问题描述
我想在我的VPS上运行一个用java编写的非常简单的bot。
我想限制jvm内存让我们说10MB(我怀疑它还需要更多)。
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).
我用以下命令运行机器人:
I'm running the bot with the following command:
但是 top
表明为java保留的实际内存是 144m
(或者我在这里解释错误吗?)。
But top
shows that actual memory reserved for java is 144m
(or am I interpreting things wrong here?).
任何想法在这里可能出错?
Any ideas what can be wrong here?
Java版1.6.0_20Java(TM)SE运行时环境(版本1.6.0_20-b02)Java HotSpot(TM)客户端VM(版本16.3-b01,混合模式)
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)
BTW。我正在运行CentOS - 如果重要的话。
BTW. I'm running CentOS - if it matters.
编辑:
感谢您的回答。
Thank you for your answers.
我不能真正接受它们中的任何一个,因为事实证明问题在于我选择编写程序的语言,而不是JVM本身。
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.
推荐答案
-Xmx
指定最大Java 堆分配( -Xms
指定min 堆分配)。 Java进程有自己的开销(实际的JVM等),加上加载的类和perm gen空间(通过 -XX:MaxPermSize = 128m
设置)位于值得。
-Xmx
specifies the max Java heap allocation (-Xms
specifies the min heap allocation). 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.
将您的堆分配视为Java的内部工作空间,而不是整个过程。
Think of your heap allocation as simply Java's "internal working space", not the process as a whole.
尝试实验,你会明白我的意思:
Try experimenting and you'll see what I mean:
java -Xms512m -Xmx1024m ...
此外,尝试使用 JConsole 或 JVisualVM (两者都附带Sun / Oracle JDK),您将能够看到实际堆使用情况的图形表示(以及用于约束大小的设置)。
Also, try using a tool such as JConsole or 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).
最后,正如@Peter Lawrey所说的那样,常驻内存是关键数字 - 在你的情况下,JVM只使用16 MiB RSS(根据'top')。只要JVM的堆没有被推入交换(非RAM),共享/虚拟分配就不会引起任何问题。同样,正如我在一些评论中所述,还有其他JVM可用 - Java能够在低资源或嵌入式平台上运行。
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.
这篇关于Java似乎忽略了-Xms和-Xmx选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!