简体   繁体   English

不提供 Xms JVM 参数有什么缺点?

[英]What are the downsides of not providing the Xms JVM parameter?

I am looking for a strategy to tweak the JVM parameters for an app I am running.我正在寻找一种策略来调整我正在运行的应用程序的 JVM 参数。

The app itself is a webapp that most of the time doesn't do much and does not require much memory.该应用程序本身是一个 web 应用程序,大部分时间不会做太多,也不需要太多 memory。 Let's say 300MB.假设 300MB。 Every now and then something external triggers a lot of heavy processing, occasionally requiring more memory.时不时地有一些外部触发大量繁重的处理,偶尔需要更多的 memory。 Let's say 1400 MB.假设 1400 MB。

I am running on JDK 15 without any other JVM parameters on a pod in a kubernetes cluster.我在 JDK 15 上运行,在 kubernetes 集群中的 pod 上没有任何其他 JVM 参数。

I want to:我想要:

  • Make sure my app keeps running确保我的应用程序继续运行
  • Make sure my app does not take up much more memory from the underlying system than is actually needed to keep it running.确保我的应用程序从底层系统中占用的 memory 不会比保持其运行实际需要的多。

When looking around for answers, a recommendation that often pops up is to set the Xmx parameter.在四处寻找答案时,经常弹出的建议是设置Xmx参数。 I understand why and this makes sense to me.我明白为什么,这对我来说很有意义。

But then there is another common recommendation that puzzles me.但是还有另一个让我困惑的常见建议。 It is to set the Xms parameter as well, and set it equal to the Xmx parameter.也就是设置Xms参数,设置为equal to the Xmx参数。

The last few weeks I have set both parameters and configured them equally, both to 1400M.在过去的几周里,我设置了这两个参数并同样配置了它们,都是 1400M。

两个参数设置

  • The blue line at the top is how much memory in total is reserved on the underlying system (heap + others)顶部的蓝线是在底层系统(堆+其他)上总共保留了多少 memory
  • The yellow straight line beneath it is how much memory the JVM actually reserves/commits for the heap.它下面的黄色直线是 memory 和 JVM 实际为堆保留/提交的数量。
  • The purple line at the bottom is how much heap memory is actually in use at the moment.底部的紫色线是 memory 目前实际使用了多少堆。

I concluded that everything runs smoothly and looks predictable.我得出的结论是,一切运行顺利,看起来可以预测。 What I don't like is that the JVM reserves 1400MB memory at all times (which is exactly what the Xms parameter does I assume), permanently occupying 2.2 GB of the underlying system.我不喜欢的是 JVM 始终保留 1400MB memory (这正是我假设的 Xms 参数),永久占用 2.2 GB 的底层系统。

Let's see what happens when I remove the Xms parameter and only set Xmx to 1400:让我们看看当我删除 Xms 参数并将 Xmx 设置为 1400 时会发生什么:

只有 Xmx

Here you can see the typical behavior of the app more clearly.在这里,您可以更清楚地看到应用程序的典型行为。 How much memory the JVM reserves / commits for the heap is dependent on how much is actually used. memory 和 JVM 为堆保留/提交多少取决于实际使用了多少。 It is low most of the time and climbs and falls during the moments of heavy processing.它大部分时间都很低,在繁重的处理过程中会上升和下降。

My question is: Why would I want to set the Xms parameter?我的问题是:为什么要设置 Xms 参数? The behavior without it looks much more efficient.没有它的行为看起来效率更高。 Are there any downsides I am missing?我有什么缺点吗?

If some other application reserves to much memory, your application won't have enough during the next peak.如果其他一些应用程序保留太多 memory,那么您的应用程序在下一个高峰期将不够用。

The admin can better estimate the memory usage, if the reserved size doesn't change.如果保留大小没有变化,管理员可以更好地估计 memory 的使用情况。

The memory reserved at once will be most probably less fragmented.一次保留的 memory 很可能碎片较少。

But there is a downside of setting the Xmas (besides the obvious one): the garbage collector waits longer until it starts collecting.但是设置圣诞节有一个缺点(除了明显的那个):垃圾收集器在开始收集之前等待更长的时间。 The garbage collection overhead is more seldom, but heavier.垃圾收集开销很少,但更重。 The CPU performance is less stable in this case.在这种情况下,CPU 性能不太稳定。 In some cases it can cause stop-the-world pauses (for example if you have lot of RAM but weak CPU)在某些情况下,它可能会导致停顿(例如,如果您有大量 RAM 但 CPU 较弱)

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

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