使用 Fat Jars 相对于容器的优势:

huangapple go评论80阅读模式
英文:

Advantages of using Fat Jars over Containers

问题

我想了解这两者之间的区别,以及根据行业标准目前更常用的是哪一个。我尝试在网上寻找资源,但关于 Fat Jars 的内容非常少,而且几乎没有在任何地方对比这两者。

英文:

I wanna know the difference between the two and also which one is currently used more according to industry standards. I tried finding resources online but the content about Fat Jars is very less and also almost no contrast is shown between the two anywhere.

答案1

得分: 0

根据您的需求,您可以使用独立的独立的 fat jars,也可以使用容器内的 fat jars。我要强调的关键点是这两者之间并没有对立,实际上它们是互补的。

Fat jar 是一种主要的方式,用于封装 Java 应用程序,以便轻松地放入容器中。

当然,您也可以以独立的方式使用 fat jars。

容器化的优点:

  1. 您可以利用容器的统一工具。即,您设置了 Docker,就可以运行任何容器 - 无论是包含 fat jar 的 Java、node.js 还是其他任何内容。
  2. 您可以利用各种容器编排系统(Docker Compose、Docker Swarm、Kubernetes 等),这意味着您可以使用统一的工具来进行健康检查、监控、滚动更新等。
  3. 您不需要担心系统上的 JRE / JDK 版本问题。

什么情况下仍然希望使用独立方式:

  • 当您具有以 Java 为中心的架构,并且围绕此架构建立了流程,从而更改为现代容器编排将会很昂贵时。
  • 当您将 Java 用作实例上的主要脚本(或应用程序)平台,并且根本不希望有任何容器的开销时。
英文:

Depending on your needs, you can use either standalone fat jars or fat jars inside containers. Key point I'm making is there is no standoff between the two, in fact they are complimentary.

Fat jar is a primary way to wrap java application so it could be easily containerized.

Of course, you could use fat jars in standalone ways too.

Pros of containerization:

  1. You can take advantage of unified tooling for containers. I.e., you set up docker and you can run any container - be it java with fat jar or node.js or anything else.
  2. You can take advantage of various container orchestration systems (docker compose, docker swarm, kubernetes, etc) - meaning you use unified tooling for healthchecks, monitoring, rolling updates, etc.
  3. You don't need to worry about things like JRE / JDK versions on your system.

When you may still want to use standalone:

  • When you have java-centric architecture and established processes around that and it would be costly to change from that to modern container orchestration.
  • When you are using java as primary scripting (or application) platform on your instance and simply don't want any overhead of containers.

答案2

得分: 0

这乍一看似乎不是什么大问题。原因是Java打包系统非常成熟,在多年的发展中变得强大。许多其他生态系统无法从中受益,但可以从打包到容器镜像中获得巨大好处。但容器不仅仅关乎打包。打包几乎可以被视为它的一个副作用。

除此之外,使用容器而不是简单的Fat JAR带来了一些好处:

简化基础设施

对于围绕微服务构建的大型(或中型)企业,很有可能它们并不都在使用相同的语言和工具。容器提供了一种在相同方式下部署所有这些不同组件的可预测方式,因此极大地简化了基础设施,从而大大降低了公司的成本。当部署到云中时,特别是在多云提供商的情况下,容器编排(例如Kubernetes等软件)在不需要太多努力的情况下非常有帮助。

一致性

容器相对于常规的JAR文件的另一个好处是在不同环境中的一致性。想象一下,你将JAR部署到开发环境(运行Java 8),然后部署到生产环境(运行Java 10)。由于默认的垃圾回收器或其他原因,JVM可能会以不同的方式运行,导致程序在两个环境中表现不同。当通过容器镜像部署时,相同的镜像将在不同的环境中使用,因此始终使用相同的Java版本,降低了出错的可能性。

资源隔离

另一个好处是资源隔离。容器可以确保你的应用程序仅“看到”预定数量的内存和CPU。实际上,Java 10在这方面进行了一些改进,你可以在这里阅读更多信息:链接

希望这能更好地为你提供有关这个问题的观点。

英文:

It seems not a big deal at a first glance. The reason for that is that the Java packaging system is really mature and grew strong over many years. Many other ecosystems do not benefit from this and can benefit greatly from being packaged into a container image. But containers are not only about packaging. Packaging could almost be considered a side-effect of it.

Amongst others, some benefits of using containers over simple Fat JARS are:

Simplified infrastructure

For a big (or mid-sized) enterprise built around microservices, chances are that not all of them are using the same languages and tools. A container provides a predictable way of deploying all those different things in the same manner, so it greatly simplifies the infrastructure, thus dramatically reducing company costs with it. This becomes even more important when deploying into the cloud, especially in multi-cloud-provider scenarios, and in that case, container orchestration provided by software like Kubernetes help a great deal without much effort.

Consistency

Another benefit of containers over regular JARs is consistency across environments. Imagine for instance that you deploy your JAR into DEV (running Java 8) and then into PROD (running Java 10). For some reason the JVM behaves differently, either because of default Garbage Collector or something else, making your program behave differently in both environments. When you deploy through a container image, the same image will be used across different environments, and thus the same Java version will be always used, making it less error-prone.

Resource isolation

Yet another benefit is resource isolation. Containers can make sure that your application "see" only a predetermined amount of memory and CPUs. Actually, there were some improvements in Java 10 regarding this matter, you can read more about it here.

Hope this provides with a better point of view regarding this matter.

huangapple
  • 本文由 发表于 2020年5月29日 21:32:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/62087186.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定