简体   繁体   English

如何优化 JVM 的 memory 使用?

[英]How can I optimize the memory usage of JVM?

I would like to ask if anyone here knows a way how to optimize the memory usage of the JVM?我想问这里是否有人知道如何优化 JVM 的 memory 使用的方法? We are using a java service wrapper (YAJSW) that invokes the JVM and the physical memory usage is around 40MB.我们正在使用调用 JVM 的 java 服务包装器 (YAJSW),物理 memory 使用量约为 40MB。 I want to lessen this to let's say 5-10MB.我想减少这个,比如说 5-10MB。 How do I achieve this?我如何实现这一目标?

So far, I only have the following configuration:到目前为止,我只有以下配置:

java =-Xmx1024m

I have also tried this:我也试过这个:

java =-Xms1024m -Xmx1024m -XX:NewSize=512m -XX:MaxNewSize=512m -XX:SurvivorRatio=2 -XX:PermSize=256m -XX:MaxPermSize=256m

But these configuration settings made no difference at all.但是这些配置设置根本没有任何区别。 What would be the correct configuration settings for this?什么是正确的配置设置? or, what else do i have to do to optimize this?或者,我还需要做什么来优化它?

Thank in advance for your answers.提前感谢您的回答。

Are you talking about resident memory or virtual?你说的是常驻 memory 还是虚拟的? On my machine, a simple while(true);在我的机器上,一个简单的while(true); in main without anything else already gets me 10 MB of resident memory, mostly because of memory mapped r/o libraries (libc, libm, librt, libpthread...) and jars.在没有其他任何东西的情况下,我已经获得了 10 MB 的常驻 memory, main是因为 memory 映射的 r/o 库(libc、libm、librt、libpthread ...)和 ZBE1587EA25D1C05C81D3BDEB94 Reducing, if possible at all, the memory footprint any further, or to 10 MB in any non-trivial application, would only mean more paging, thus reducing speed.如果可能的话,进一步减少 memory 占用空间,或在任何重要的应用程序中减少到 10 MB,只会意味着更多的分页,从而降低速度。

Virtual memory, on the other hand, is 1.1 GB on my machine, which could be reduced if necessary, but why do so?另一方面,虚拟 memory 在我的机器上是 1.1 GB,如果需要可以减少,但为什么要这样做? Unused virtual memory doesn't really cost anything.未使用的虚拟 memory 并没有真正花费任何成本。

Edit: Apart from that, you may want to have a look at the other HotSpot VM Options , especially MaxHeapFreeRatio.编辑:除此之外,您可能还想看看其他HotSpot VM Options ,尤其是 MaxHeapFreeRatio。

The documentation for YAJSW states:YAJSW 的文档指出:

Wrapper memory requirements包装器 memory 要求
The flexibility of YAJSW comes at a price. YAJSW 的灵活性是有代价的。 Using java for the wrapper process has many advantages.使用 java 进行包装工艺有很多优点。 However we pay the java price of higher memory footprint.但是,我们支付更高 memory 占用空间的 java 价格。 Whereas the JSW wrapper requires only a few k of memory, the minimal virtual memory requirement of YAJSW is 90 MB and 40 MB physical memory.虽然 JSW 包装器只需要几 k 的 memory,但 YAJSW 的最小虚拟 memory 要求是 90 MB 和 40 MB 物理 ZCD69B4957F06CD818D7BF3D61980E29 The value varies depending on the OS and the functions.该值因操作系统和功能而异。

If your application can run within 32bit memory restrictions you can use the community edition of Tanuki as it has a lower footprint.如果您的应用程序可以在 32 位 memory 限制下运行,您可以使用 Tanuki 的社区版,因为它占用空间较小。

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

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