设置-XX:MaxRam [英] Setting -XX:MaxRam

查看:527
本文介绍了设置-XX:MaxRam的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据此链接,可以选择手动设置MaxRamSize来限制JVM不会使用超出此范围的内存.但是我还没有看到相同的任何文档.我从来不知道.有没有类似或类似的东西? PS.我知道,我不希望设置堆/堆栈/元空间/本机内存大小.我只是想知道是否有整体内存限制选项.

According to this link, there is an option to set MaxRamSize manually to restrict the JVM to not use memory beyond this. But I have not seen any documentation of the same. I've never known this. Is there anything like this or anything similar? PS. I know and I'm not looking to set heap/stack/metaspace/native memory sizes. I just would like to know if there is an overall memory limiting option.

尝试它没有帮助,因为它出错了:

Trying it did not help as It errored out:

Improperly specified VM option 'MaxRAM=1073741824B'
Could not create the Java Virtual Machine.
A fatal exception has occurred. Program will exit.

根据此链接 a> open-jdk似乎有这些选项. 我发现另一个链接,我相信它指向设置堆大小.再次没有寻找.但这是给Oracle的.

Infact according to this link open-jdk seems to have these options. Another link that I found I believe points to set the heap size. Which again is not looking for. But this is for Oracle I guess.

为什么我要寻找这种选项来在容器内运行应用程序(如Docker),并防止应用程序被OOM Killer杀死.我相信的是,如果有这样的Java应用程序设置,将导致错误或使用java.lang.OutOfMemoryError崩溃,而不是终止容器.

Why I'm looking for this kind of an option to run the application inside a container (Like Docker) and prevent the application from being killed by the OOM Killer. What I believe is if there is a setting of such the java application would error or crash with a java.lang.OutOfMemoryError rather, than the container being terminated.

我的假设和理解可能是完全错误的. 这个问题也可能是完全错误和无关紧要的.但是,当然,问问是前进的方向:).

My assumptions and understandings may be totally wrong. This question may also be totally wrong and irrelevant. But of course, asking is the way forward :).

推荐答案

为什么我要寻找这种选项来在容器内运行应用程序(如Docker),并防止应用程序被OOM Killer杀死.

Why I'm looking for this kind of an option to run the application inside a container (Like Docker) and prevent the application from being killed by the OOM Killer.

这正是您要寻找的选项.此外,它已作为cgroups(〜docker)正确集成. . 请注意,此标志不会阻止JVM分配比其值更多的内存,而是提示我知道我的物理RAM限制为X,请在X内分配",因此JVM将在Java堆和本机内存之间共享此值.但是如果您的应用程序有本机内存泄漏或类加载器泄漏,那么无论如何都会达到此限制.

This is exactly the option you are looking for. Moreover, it was properly integrated with cgroups (~docker) as part of JDK-8170888. Note that this flag does not prevent JVM from allocating more memory than its value, but rather gives a hint "I know my physical RAM limit is X, please allocate within X", so JVM will share this value between Java heap and native memory. But if e.g. your application has native memory leak or classloader leak, then this limit will be reached anyway.

JVM在MaxRAM=1073741824B上抱怨,因为它最终不希望使用B,因此应将其声明为-XX:MaxRAM=1073741824. 参见标志的说明:Real memory size (in bytes) used to set maximum heap size.

JVM is complaining on MaxRAM=1073741824B because it doesn't expect B in the end, it should be declared as -XX:MaxRAM=1073741824. See the description of the flag: Real memory size (in bytes) used to set maximum heap size.

这篇关于设置-XX:MaxRam的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆