简体   繁体   English

多 WAR tomcat 与 Docker 容器

[英]Multi-WAR tomcat vs Docker containers

I'm wondering if a Docker solution is faster and more memory efficient than my current Tomcat deployment.我想知道 Docker 解决方案是否比我目前的 Tomcat 部署更快、更高效。 I will explain both solutions.我将解释这两种解决方案。

The current: I have a Tomcat server with about 20 WAR's deployed.当前:我有一个 Tomcat 服务器,部署了大约 20 个 WAR。 The WAR's are Spring Boot applications. WAR 是 Spring 引导应用程序。 It takes up a lot of memory and boottime and money too.它占用了大量的 memory 以及启动时间和金钱。

The docker alternative: The alternative I'm thinking about is a docker host with 20 docker containers, one for each app. docker 替代方案:我正在考虑的替代方案是 docker 主机,带有 20 个 docker 容器,每个应用程序一个。 It seems Spring recommends using JAR's on JDK images.似乎 Spring 建议在 JDK 映像上使用 JAR。

Now, does Docker, or containerization in general, improve memory and speed?现在,Docker 或一般的容器化是否会提高 memory 和速度?

One improvement I am expecting is that applications can start in parallel.我期待的一项改进是应用程序可以并行启动。 This will hopefully speed up boot-time (assuming multi-core hardware).这有望加快启动时间(假设多核硬件)。 Am I right here?我在这里吗?

Secondly I'm wondering which approach will handle memory most efficient.其次,我想知道哪种方法可以最有效地处理 memory。 What happens when I have multiple WAR's, sharing the exact same dependency?当我有多个 WAR,共享完全相同的依赖项时会发生什么? Will Tomcat reuse dependency memory for that? Tomcat 会为此重用依赖 memory 吗? And will Docker? Docker 会怎样?

Memory (and thus likely CPU) efficiency can be debated and probably needs to be measured. Memory(以及可能的 CPU)效率可以讨论并且可能需要测量。 Let me give some insight.让我提供一些见解。

Let's assume you create 20 containers, one for each of the war's you want to run.假设您创建了 20 个容器,每个容器用于您要运行的每个战争。 At that time you have 20 different JVMs in memory.那时你在 memory 中有 20 个不同的 JVM。 Depending whether they come from the same container image or from different ones, the OS recognizes they are the same, and the codebase could be shared.根据它们是来自同一个容器映像还是来自不同的容器映像,操作系统会识别它们是相同的,并且可以共享代码库。 So this depends on whether you bake your wars into the container images or have one image only and mount the wars at runtime.因此,这取决于您是将战争烘焙到容器图像中还是只有一个图像并在运行时挂载战争。

What about permgen space, heap or other memory regions? permgen 空间、堆或其他 memory 区域呢? I doubt the OS can share much between the processes here.我怀疑操作系统可以在这里的进程之间共享很多东西。 And the JVMs cannot share on their level since the docker container isolation would not allow them to talk to each other.并且 JVM 无法共享它们的级别,因为 docker 容器隔离不允许它们相互通信。 So shared memory on JVM level is lost.所以 JVM 级别上的共享 memory 丢失。

With that, every JVM would start up and run the JIT for hotspot code locations, and no synergy between the applications can be used.这样,每个 JVM 都将启动并运行针对热点代码位置的 JIT,并且无法使用应用程序之间的协同作用。 With a bigger codebase in memory, also the CPU would have to jump more between processes, invalidating the cache more often.随着 memory 中更大的代码库,CPU 也必须在进程之间跳转更多,从而更频繁地使缓存无效。

All in all I believe dockerizing your setup is an improvement in application isolation.总而言之,我相信对您的设置进行 docker 化是对应用程序隔离的一种改进。 You can more easily install/uninstall your stuff, and one application running havoc cannot impact the others.您可以更轻松地安装/卸载您的东西,一个运行严重破坏的应用程序不会影响其他应用程序。 But performance-wise, you should notice lower execution times and higher memory usage.但在性能方面,您应该注意到更低的执行时间和更高的 memory 使用率。 To what extent might only be benchmarked.只能在多大程度上进行基准测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM