Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

share|improve this question

3 Answers 3

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.

share|improve this answer
    
If I set -Xss128m my app will never use more than 128meg? –  mnml Feb 2 '11 at 12:37
    
No, tu's more complex. You need to set a) max heap size (-Xmx=100M) b) permgen size (-XX:MaxPermSize=100M) c) stack size (-Xss128k) d) may be something else Then you app will use 100M heap + 100M permgen + 128k*number_of_threads for stack + java itself –  rvs Feb 2 '11 at 13:39

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

share|improve this answer
    
Well the problem is not the little size of the memory available: it's the fact that java is able to see 512mb, when only 256mb can be used. –  mnml Feb 2 '11 at 12:25
    
AH, that is then a VPS specific thing. Dynamic memory.... which then is not available. Too little guaranteed ram. Hardcode the VM to be smaller. –  TomTom Feb 2 '11 at 12:51
    
those vps are so worthless I should post on clientfromhell ;< –  mnml Feb 2 '11 at 13:17

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.