Java 似乎忽略 -Xms 和 -Xmx 选项
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6450132/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Java seems to ignore -Xms and -Xmx options
提问by Itako
I'd like to run a very simple bot written in java on my VPS. I want to limit jvm memory to let's say 10MB (I doubt it would need any more).
我想在我的 VPS 上运行一个用 java 编写的非常简单的机器人。我想将 jvm 内存限制为 10MB(我怀疑它是否需要更多)。
I'm running the bot with the following command:
我正在使用以下命令运行机器人:
java -Xms5M -Xmx10M-server -jar IrcBot.jar "/home/jbot"
java -Xms5M -Xmx10M-server -jar IrcBot.jar "/home/jbot"
But top
shows that actual memory reserved for java is 144m
(or am I interpreting things wrong here?).
但是top
表明为 java 保留的实际内存是144m
(或者我在这里解释错误?)。
13614 jbot 17 0 144m16m 6740 S 0.0 3.2 0:00.20 java
13614 jbot 17 0 144米16米6740秒0.0 3.2 0:00.20 java的
Any ideas what can be wrong here?
任何想法这里可能有什么问题?
Java version "1.6.0_20" Java(TM) SE Runtime Environment (build 1.6.0_20-b02) Java HotSpot(TM) Client VM (build 16.3-b01, mixed mode)
Java 版本“1.6.0_20”Java(TM) SE 运行时环境(构建 1.6.0_20-b02)Java HotSpot(TM) 客户端 VM(构建 16.3-b01,混合模式)
BTW. I'm running CentOS - if it matters.
顺便提一句。我正在运行 CentOS - 如果重要的话。
EDIT: Thank you for your answers.
编辑:谢谢你的回答。
I can't really accept any of them, since it turns out the problem lies within the language i choose to write the program, not the JVM itself.
我不能真正接受它们中的任何一个,因为事实证明问题出在我选择编写程序的语言中,而不是 JVM 本身。
采纳答案by Michael
-Xmx
specifies the max Java heapallocation (-Xms
specifies the min heapallocation). The Java process has its own overhead (the actual JVM etc), plus the loaded classes and the perm gen space (set via -XX:MaxPermSize=128m
) sits outside of that value too.
-Xmx
指定最大 Java堆分配(-Xms
指定最小堆分配)。Java 进程有自己的开销(实际的 JVM 等),加上加载的类和永久生成空间(通过 设置-XX:MaxPermSize=128m
)也位于该值之外。
Think of your heap allocation as simply Java's "internal working space", not the process as a whole.
将您的堆分配视为简单的 Java 的“内部工作空间”,而不是整个过程。
Try experimenting and you'll see what I mean:
尝试试验,你会明白我的意思:
java -Xms512m -Xmx1024m ...
Also, try using a tool such as JConsoleor JVisualVM(both are shipped with the Sun / Oracle JDK) and you'll be able to see graphical representations of the actual heap usage (and the settings you used to constrain the size).
此外,尝试使用诸如JConsole或JVisualVM(两者都随 Sun/Oracle JDK 一起提供)之类的工具,您将能够看到实际堆使用情况的图形表示(以及用于限制大小的设置)。
Finally, as @Peter Lawrey very rightly states, the resident memory is the crucial figure here - in your case the JVM is only using 16 MiB RSS (according to 'top'). The shared / virtual allocation won't cause any issues as long as the JVM's heap isn't pushed into swap (non-RAM). Again, as I've stated in some of the comments, there are other JVM's available - "Java" is quite capable of running on low resource or embedded platforms.
最后,正如@Peter Lawrey 非常正确地指出的那样,常驻内存是这里的关键数字 - 在您的情况下,JVM 仅使用 16 MiB RSS(根据“顶部”)。只要 JVM 的堆没有被推入交换区(非 RAM),共享/虚拟分配就不会引起任何问题。同样,正如我在一些评论中所说的,还有其他 JVM 可用——“Java”非常有能力在低资源或嵌入式平台上运行。
回答by Theo
Xmx
is the max heapsize, but besides that there's a few other things that the JVM needs to keep in memory: the stack, the classes, etc. For a brief introduction see this post about the JVM memory structure.
Xmx
是最大堆大小,但除此之外,JVM 还需要在内存中保留一些其他内容:堆栈、类等。有关简要介绍,请参阅有关 JVM 内存结构的这篇文章。
回答by Peter Lawrey
The JVM maps in shared libraries which are about 150m. The amount of virtual memory used is unlikely to be important to use if you are trying to minimise physical main memory.
JVM 映射在大约 150m 的共享库中。如果您试图最小化物理主内存,则使用的虚拟内存量不太可能重要。
The number you want to look at is the resident memory which is amount of physical main memory actually used (which is 16 MB)
您要查看的数字是驻留内存,即实际使用的物理主内存量(16 MB)