We use Netbeans for web development.
Last half of the year it began to behave pretty slow on the bigger project.
Most of machines have HDD with the speed 5400 rpm, i5 Core, Ubuntu 14.04.3 LTS and in average 8 GB RAM.
Cleaning the cache, changing OpenJDK to Oracle Java, updating version of Java to the last 8th version, reinstalling Netbeans, removing plugins – nothing gave a reasonable increase in the speed.
I was going to give up and to choose the last resort – to buy SSD disk only to make Netbeans work a bit faster. Many articles states it should help.
Before going to the shop I decided to play with Java configs and it helped!
Now it works seamlessly.
Config of Netbeans before tuning: netbeans.config_old
Netbeans’s config after tuning: netbeans_tuned_up.conf
Pay attention specifically to this line:
netbeans_default_options=”-J-client -J-Xss2m -J-Xms32m -J-XX:PermSize=32m -J-Dapple.laf.useScreenMenuBar=true -J-Dapple.awt.graphics.UseQuartz=true -J-Dsun.java2d.noddraw=true -J-Dsun.java2d.dpiaware=true -J-Dsun.zip.disableMemoryMapping=true”
The core options are:
Xss2m – meants size of the stack is 2 megabytes, Xms32m – minimal heap size, etc.
Other available options are:
- -Xmx : max heap size (ex: -Xmx1024)
- -Xms : min heap size. Having -Xms = 1.8GB (32bit) can be bad, because you don’t let memory for anything else.
- -Xmn : the size of the heap for the young generation
Young generation represents all the objects which have a short life of time. Young generation objects are in a specific location into the heap, where the garbage collector will pass often. All new objects are created into the young generation region (called “eden”). When an object survive is still “alive” after more than 2-3 gc cleaning, then it will be swap has an “old generation” : they are “survivor” .
Good size is 33%
- -XX:NewRatio : the same as Wmn, but using a % (dynamic fs static -Xmn option). -XX:NewRatio=3 means that the ratio between the old and young generation is 1:3
- -XX:NewSize – Size of the young generation at JVM init. Calculated automatically if you specify -XX:NewRatio
- -XX:MaxNewSize – The largest size the young generation can grow to (unlimited if this value is not specified at command line)
- -XX:SurvivorRatio : “old generation” called tenured generation, ratio, in %. For example, -XX:SurvivorRatio=6 sets the ratio between each survivor space and eden to be 1:6 (eden is where new objects are created)
- -XX:MinHeapFreeRatio: default is 40%. JVM will allocate memory to always have as minimum 40% of free memory. When -Xmx = -Xms, it’s useless.
- -XX:MaxHeapFreeRatio: default is 70%. The same as Min, to avoid unecessary memory allocation.
I used this website and comments left by people there for getting various info while playing with configs.
Please make sure before applying any changes that you made copy of initial Netbeans config file. Otherwise you may get into troubles.