可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
I have a very old linux system and installed java and play framework. When I run java I get:
java -version
Error occurred during initialization of VM
Could not reserve enough space for object heap
Could not create the Java virtual machine.
So I limited the java heap space in application.conf:
jvm.memory=-Xmx256M -Xms256M
With that setting I can run play test, play run etc....
But I cannot run:
play dependencies
~ _ _
~ _ __ | | __ _ _ _| |
~ | '_ \| |/ _' | || |_|
~ | __/|_|\____|\__ (_)
~ |_| |__/
~
~ play! 1.2.1, http://www.playframework.org
~
Error occurred during initialization of VM
Could not reserve enough space for object heap
Could not create the Java virtual machine.
Is there a global configuration file or environment variable where I can limit java heap space globaly for play framework?
Update:
Also the following is not working:
play dependencies -Xmx256M -Xms256M
~ _ _
~ _ __ | | __ _ _ _| |
~ | '_ \| |/ _' | || |_|
~ | __/|_|\____|\__ (_)
~ |_| |__/
~
~ play! 1.2.1, http://www.playframework.org
~
Error occurred during initialization of VM
Could not reserve enough space for object heap
Could not create the Java virtual machine.
Update 2:
Memory:
ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
file size (blocks, -f) unlimited
pending signals (-i) 1024
max locked memory (kbytes, -l) 32
max memory size (kbytes, -m) unlimited
open files (-n) 1024
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
stack size (kbytes, -s) 10240
cpu time (seconds, -t) unlimited
max user processes (-u) 38912
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
Limits:
cat /proc/meminfo
MemTotal: 4139312 kB
MemFree: 332988 kB
Buffers: 105252 kB
Cached: 1705644 kB
SwapCached: 4 kB
Active: 2566216 kB
Inactive: 625032 kB
HighTotal: 786432 kB
HighFree: 1728 kB
LowTotal: 3352880 kB
LowFree: 331260 kB
SwapTotal: 4192956 kB
SwapFree: 4168224 kB
Dirty: 368 kB
Writeback: 0 kB
Mapped: 1672180 kB
Slab: 570864 kB
CommitLimit: 6262612 kB
Committed_AS: 4075144 kB
PageTables: 19884 kB
VmallocTotal: 303096 kB
VmallocUsed: 10400 kB
VmallocChunk: 292648 kB
BR,
Rene
回答1:
Play does not appear to pick up the jvm.memory settings for dependencies or even test command. One way to force it to use specific JVM settings would be to use _JAVA_OPTIONS.
For example:
export _JAVA_OPTIONS="-Xms800m -Xmx1500m -XX:PermSize=64m -XX:MaxPermSize=256m"
play test
or
play deps
and you should see
~ _ _
~ _ __ | | __ _ _ _| |
~ | '_ \| |/ _' | || |_|
~ | __/|_|\____|\__ (_)
~ |_| |__/
~
~ play! 1.2.3, http://www.playframework.org
~ framework ID is test
~
~ Running in test mode
~ Ctrl+C to stop
~
Picked up _JAVA_OPTIONS: -Xms800m -Xmx1500m -XX:PermSize=64m -XX:MaxPermSize=256m
Listening for transport dt_socket at address: 8000
Note that this would apply those settings to all java programs run on that terminal where _JAVA_OPTIONS is set.
回答2:
After googling more around I found this discussion. The problem is, that my Linux System is running in an openvz container:
The reason why Java complains is because on start up, it sees that the machine has more than 2 GB of RAM, so it starts up in server mode, which tries to allocate all the memory, which then fails because it is inside a VPS.
I could fix the java startup problem by changing /usr/java/jdk1.6.0_26/jre/lib/i386/jvm.cfg from:
-client IF_SERVER_CLASS -server
-server KNOWN
-hotspot ALIASED_TO -client
-classic WARN
-native ERROR
-green ERROR
to:
#-client IF_SERVER_CLASS -server
-client KNOWN
-server KNOWN
-hotspot ALIASED_TO -client
-classic WARN
-native ERROR
-green ERROR
Now I can run any play command. Maybe this helps other people having similar problems related to container based virtualization.
BR, Rene
回答3:
Normally, you can specify Java command line arguments when you call play using the following pattern.
play run <appname> -Xmx256M -Xms256M
However, looking at the python code for the play run
command and the play dependencies
command, they invoke Java in different ways.
The play dependencies command invokes Java without passing through -X commands (for some reason, it passes through -D commands, but not -X). Therefore, there is nothing you can do, apart from editing the deps.py
file in framework/pym/play/commands and hard coding the -Xmx and -Xms settings into this file.
This not a long term solution, and I would suggest you raise a ticket on Play to allow these settings to be read from command line, or from the application.conf, but for now, I see this approach as your only option.
回答4:
Just ran into this on my laptop running Fedora and using Play 2.0 when simply starting the interactive shell. I found that the build script is setting the memory values by default to pretty high values.
To fix this I had to edit the $play_dir/framework/build
script and change the values manually, at the end of the script it does the following to launch:
java ${DEBUG_PARAM} -Xms512M -Xmx1536M -Xss1M -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=384M ...
Just change the -Xmx/-Xms values (and possibly the permgen) accordingly.
回答5:
You computer doesn't have enough RAM to run Java. Java needs at least 64MB RAM.
Note that you can't add free memory to your computer by specifying -Xms
to Java: Java can't add memory modules to your mainboard. -Xms
just tells Java how much of the available RAM to take. If that fails (= the OS returns an error when Java tries to allocate it), you get the error above.
My guess is that there is no swap space. Look at the output of cat /proc/meminfo
. Or you have a ulimit
set which limits how much memory each process can allocate (try ulimit -a
to check).
回答6:
In Play 2.2 and Java 7, this is what I used.
$ target/universal/stage/bin/foo -mem 256 -J-server
For the detail of -mem, please see:
$ target/universal/stage/bin/foo -h
回答7:
It appears that the play
command you run is actually a Python script which invokes other Play Framework python modules, which eventually invoke the java
command as subprocess.
Looking at the source code for the code that runs for the dependencies
command, there doesn't appear to be any logic to load an environment variable or anything else to specify the max heap size as the -Xmx
argument. In other words, the Python code from Play which invokes the JVM in this script has no way to specify the max heap size from the default.
回答8:
I faced the same issue. Try increasing --XX:MaxHeapSize to a higher allocation. Here is my configuration in path/to/framework/build
java -Xms512M -Xmx1300M -Xss1M -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=384M -XX:MaxHeapSize=512m...
回答9:
Play does not recognize -XX options. Instead use -DX.