java 多个 JVM 与单个应用服务器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26145408/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Multiple JVMs vs single app server
提问by Noky
I'm dealing with a system that runs a Java application per customer in its own JVM. We've got about a half dozen dedicated servers that are running close to 100 JVMs total now and sets of custom scripts for managing these JVMs. This setup is really showing its age at this point: managing that many JVMs is becoming a monitoring/management nightmare and we are constantly dealing with heap sizing issues. We'd like to move to a more modern approach and just run a bunch of applications in a single app server per physical machine. However, keeping the applications separate does have distinct advantages in terms of isolation (e.g. out of memory errors only affect one customer). Each customer's software stack has memory requirements that vary widely.
我正在处理一个系统,该系统在自己的 JVM 中为每个客户运行一个 Java 应用程序。我们现在有大约 6 个专用服务器,它们总共运行着接近 100 个 JVM,以及用于管理这些 JVM 的自定义脚本集。在这一点上,这种设置确实显示了它的年龄:管理这么多 JVM 正成为监控/管理的噩梦,我们一直在处理堆大小问题。我们希望采用更现代的方法,只需在每台物理机的单个应用程序服务器中运行一堆应用程序。但是,将应用程序分开在隔离方面确实具有明显的优势(例如,内存不足错误仅影响一位客户)。每个客户的软件堆栈的内存要求差异很大。
My question: is there a way to have the best of both worlds here and run multiple applications in one JVM (app server) and still maintain some level of isolation? Or is it just a modern fact of life that you need to manage memory requirements of a set of applications these days? Are there other solutions here besides an app server or Java EE container (e.g. Wildfly or Spring) that I'm missing here? It seems like this system is a holdout from another era!
我的问题:有没有一种方法可以两全其美,并在一个 JVM(应用程序服务器)中运行多个应用程序,并且仍然保持一定程度的隔离?或者,您现在需要管理一组应用程序的内存需求只是现代生活的事实吗?除了我在这里缺少的应用程序服务器或 Java EE 容器(例如 Wildfly 或 Spring)之外,这里还有其他解决方案吗?这个系统似乎是另一个时代的坚持!
采纳答案by GreyFairer
Checkout 'multi-tenant' JVM's.
签出“多租户”JVM。
IBM's JRE has it already: http://www.ibm.com/developerworks/library/j-multitenant-java/
IBM 的 JRE 已经有了:http: //www.ibm.com/developerworks/library/j-multitenant-java/
Waratek has implemented it on top of the Oracle JRE, and they created ElastiCat, a Tomcat fork that isolates different applications in the same container: http://www.elasticat.com/faq/
Waratek 已经在 Oracle JRE 之上实现了它,他们创建了 ElastiCat,这是一个 Tomcat 分支,可以隔离同一容器中的不同应用程序:http://www.elasticat.com/faq/
Multi-tenancy is rumoured to appear in the official Oracle Java 9 JVM, too.
有传言称,官方 Oracle Java 9 JVM 中也会出现多租户。
=======================================================
================================================== ======
Update: Java 9 is out, but no word from Oracle about multi-tenancy. It seems they prefer having multiple JVM's these days, even multiple Containers (e.g. docker).
更新:Java 9 已经发布,但 Oracle 没有关于多租户的消息。似乎他们现在更喜欢拥有多个 JVM,甚至是多个容器(例如 docker)。
回答by Michael
There's pros and cons of either approach:
两种方法各有利弊:
Shared JVM
共享JVM
- Lower overhead - JVM memory footprint (core libraries etc.) only needs to be loaded once.
- Better memory usage. Java processes will consume OS memory for heap space that may not currently be in use.
- 更低的开销 - JVM 内存占用(核心库等)只需要加载一次。
- 更好的内存使用。Java 进程将消耗操作系统内存用于当前可能未使用的堆空间。
Separate JVM
独立的JVM
- Insulation from 'greedy' or 'leaky' applications.
- Better security from malicious code.
- Easier updates, updating one app without bringing down the other.
- 与“贪婪”或“泄漏”应用程序绝缘。
- 从恶意代码中获得更好的安全性。
- 更轻松的更新,更新一个应用程序而不会降低另一个应用程序。
Overall, I wouldn't set a blanket policy. Look for small / micro-services or other low-usage apps that may be good candidates to share first and expand from there.
总的来说,我不会制定一揽子政策。寻找小型/微服务或其他低使用率的应用程序,这些应用程序可能是首先共享并从那里扩展的良好候选者。
回答by SteveD
Have a look Spring Bootor Fabric8for a modern take on running Java in a manageable way
看看Spring Boot或Fabric8以现代方式以可管理的方式运行 Java
回答by A User
Another important reason to have multiple JVM instead of one is when facing numa groups. You cannot distribute your threads within one JVM appropriate over numa groups as you can with multiple jvm processes. At least i never found a way to do so.
使用多个 JVM 而不是一个的另一个重要原因是在面对 numa 组时。您不能像使用多个 jvm 进程那样将线程分布在一个适合于 numa 组的 JVM 中。至少我从来没有找到这样做的方法。
We have here machines with two cpu's, each having 18 cores, This gives two numa groups and we cannot enforce 34 Threads to be spread upon both cpu if only one JVM is used. This is obviously because it assumes that all threads of the same JVM process need to have fast access to the same memory which is not the case.
我们这里有两个 cpu 的机器,每个都有 18 个内核,这提供了两个 numa 组,如果只使用一个 JVM,我们不能强制将 34 个线程分布在两个 cpu 上。这显然是因为它假设同一个 JVM 进程的所有线程都需要快速访问同一个内存,但事实并非如此。
Having 34 Processes the system assumes they have no need for shared memory and thus spread them over both cpus.
有 34 个进程,系统假设它们不需要共享内存,因此将它们分布在两个 CPU 上。
If someone knows a better way of doing this i would be very glad to hear it.
如果有人知道这样做的更好方法,我会很高兴听到它。