7

I need to increase the default java heap size to get OpenNMS Linkd service running smoothly, and fortunately I have 4/5 of my total installed memory free at any given time even when their is maximum load on the server. still java is not performing to it's bast. hence I need to increase the default java heap size.

Can anyone tell me how to do it?

I'm using Ubuntu 12.04 lts & total memory installed is 16 GB out of which generally 2GB to 4GB is used.

I have already checked below questions and they did not help me resolve my issue.

  1. How to increase memory allocated to java? java.lang.OutOfMemoryError: Java heap space

  2. Comparing Virtual Memory Size with Resident Size

  3. How to increase memory allocated to java? java.lang.OutOfMemoryError: Java heap space

Please feel free to edit or comment for any additional details required.

15

You could use java -Xmx4096m in order to set your heap to 4 GB.

you could then add export _JAVA_OPTIONS=-Xmx4096m to your shell by their (.bashrc, .zshrc) file.

|improve this answer|||||
  • 1
    How do you check the current configuration of the heap size? – josh.thomson Apr 20 '15 at 15:18
  • 2
    if you run java -XshowSettings:vm, near the top it should say something like this "Max. Heap Size (Estimated): 2.60G" – zeitue Apr 21 '15 at 5:12
  • Would increasing the amount of RAM on the server remove the heap error? Here's my scenario: askubuntu.com/questions/611685/… – josh.thomson Apr 21 '15 at 7:41
  • depends if the heap is getting too big for the main memory, like if the heap hit 2GB and the RAM is only two GB you'd most likely get an error before that because there are other things in memory. now if the error is the program needs a bigger heap and Java has say 0.5GB as the max heap size and you need 1GB for the program, then it is more of a setting error than a hardware issue. – zeitue Apr 22 '15 at 5:13
  • Ah! here's my result: Max. Heap Size (Estimated): 494.94M ... So I guess it would be a good idea to increase the Heap Size to around 2GB. After some research I have found out there is a 3GB RAM limit on 32-bit Ubuntu 14.04 LTS systems (with a certain PAE config)... So I increased the RAM to 3GB (networking is working unaffected). I will try increasing the heap and see if that works! -Thanks for your assistance. – josh.thomson Apr 27 '15 at 9:49
0

Hmmmm....Java performance is not necessarily tied to the size of the heap size. By increasing the max size you do prevent one source of out of memory errors (there are other things that generate this java error).

The only efficiency is gained by reducing the number of calls to increase stack memory size if you set the preallocated heap to the maximum size.

Hmm...I guess it might also slow down the garbage collector a little bit since it would not have to react as quickly as a smaller heap size.

Both of the above heap size adjustments are available on the java command line.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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