Limit Java Heap Space for play framework globaly
Asked Answered
F

9

32

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

Freeholder answered 20/7, 2011 at 14:21 Comment(1)
please note that -Xmx/-Xms denote the amount of heap memory used, the total amount of memory used will be much much higher.Conation
F
19

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

Freeholder answered 21/7, 2011 at 6:52 Comment(4)
Wow, how did you find out? You saved my life :)Cradling
I'm on a VPS, but this didn't fix my problem. :(Recce
+1 I am on a citrix-something, so this is most def going to help me!Stepfather
Newer releases (1.7.0_40 on x64 in my case) don't appear to have the client JVM anymore. Stuck on server I suppose. BumerRascon
T
24

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.

Trow answered 14/11, 2011 at 7:56 Comment(5)
In Play 1.2.4, the environment variable seems to be JAVA_OPTSGlossology
@itsadok: Actually this seems to be more of a Java Runtime thing than Play specific. If you set _JAVA_OPTIONS and run "java -version", you'll see that the settings are picked up.Trow
I guess we're talking about two completely different mechanisms. I was referring to this.Glossology
how about Play 2.2.0?Flavia
Setting this gives me "No java installations was detected. Please go to java.com/getjava and download" error.Amati
F
19

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

Freeholder answered 21/7, 2011 at 6:52 Comment(4)
Wow, how did you find out? You saved my life :)Cradling
I'm on a VPS, but this didn't fix my problem. :(Recce
+1 I am on a citrix-something, so this is most def going to help me!Stepfather
Newer releases (1.7.0_40 on x64 in my case) don't appear to have the client JVM anymore. Stuck on server I suppose. BumerRascon
F
12

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.

Ferrick answered 20/7, 2011 at 14:27 Comment(2)
Post updated. I have looked at the python code, and can now see exactly your problem,Ferrick
Thanks, I hardcoded it and also created a ticket. The same problem is for evolutions :-(Freeholder
L
6

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.

Lorrimor answered 4/4, 2012 at 4:24 Comment(0)
G
3

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).

Gerda answered 20/7, 2011 at 14:52 Comment(3)
See Update 2. There is still swap space left and almost 1 GB Memory is used for caches.Freeholder
That's really odd. Try to invoke java -version -Xmx32M (with only 32MB or even less). As long as you can't start java itself, play won't work.Gerda
See my answer. The problem was, that java is running in a container.Freeholder
D
3

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
Drainage answered 24/11, 2013 at 0:51 Comment(0)
H
2

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.

Hengel answered 20/7, 2011 at 14:45 Comment(0)
H
0

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...
Hamstring answered 29/11, 2012 at 18:10 Comment(0)
C
0

Play does not recognize -XX options. Instead use -DX.

Clamorous answered 9/1, 2015 at 7:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.