Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Limit Java Heap Space for play framework globaly

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

like image 845
reen Avatar asked Jul 20 '11 14:07

reen


People also ask

How do I reduce Java heap space?

You can change size of heap space by using JVM options -Xms and -Xmx. Xms denotes starting size of Heap while -Xmx denotes maximum size of Heap in Java.

What is the max Java heap size that can be allocated?

The theoretical limit is 2^64 bytes, which is 16 exabytes (1 exabyte = 1024 petabytes, 1 petabyte = 1024 terabytes). However, most OS's can't handle that. For instance, Linux can only support 64 terabytes of data. Note: We don't recommend you exceed 2 GB of in use JVM heap.

What is the maximum heap size for 64 bit JVM?

For 64 bit platforms and Java stacks in general, the recommended Maximum Heap range for WebSphere Application Server, would be between (4096M - 8192M) or (4G - 8G).


2 Answers

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.

like image 72
Ayush Gupta Avatar answered Sep 22 '22 17:09

Ayush Gupta


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

like image 24
reen Avatar answered Sep 19 '22 17:09

reen