I have recently deployed a java application on a VPS but It keeps crashing because the JVM runs out of memory after a while. I never had this issue on other 'low memory' servers thanks to the swap but on this VPS, It's different: There is no swap and only 50% of the actual 512megs of ram "can be used" (they say 256mbs are garanteed). Is there any way I can limit the memory consumption ? I have tried to use the xms variables but It didn't help much. I have also tried to put swap into a file but It's not allowed apparently.
Thanks in advance
Yes, you could limit java memory consumption. See for example here: http://viralpatel.net/blogs/2009/01/jvm-java-increase-heap-size-setting-heap-size-jvm-heap.html
But 256M is very small amount for java world. I suggest you to get a better vps.
You can limit the memory available fto a VM in the VM starting parameters. THat said, if an app needs 1gb, it needs 1gb. Limiting the VM wont help (app may crash with out of memory exceptions).
512mb is VERY little these days. 256Mb is even lower. Depending on th app the better solution would be "get a server capable of running the app".
It looks like you are using an OpenVZ or Virtuozzo-based VPS. If so, it's probably worth to add "ulimit -s 1024" to /etc/profile and to /etc/init.d/* startup scripts. OpenVZ and Virtuozzo memory accounting counts copy-on-write memory reserved for a stack as actually used, and the default value for the reserved stack memory is pretty high (8 to 10Mb depending on your distro).