Thursday, November 27, 2008

eclipse on mac

I run eclipse against an oracle instance with htmlUnit tests banging away on tomcat. Running the complete suite of unit tests on my dev box can eat processor and memory big time. Its like watching a kid coming home from college for the first time in months and invading the fridge. On a pc there was no processing time left for me. When I set up my env on the mac, and ran with the base settings, it died by running out of heap space.

So I try to allocate enough memory and set the parameters on the various running jvms (ant, tomcat and eclipse) in the hope that they wont die after running for 50 minutes with a heap space space issue. My box has 4G of memory, and I have oracle running in a separate vmware fusion vm on Ubuntu. I am using eclipse Ganymede with java 5 (1.5.0.13) , Tomcat 5.5 and and use ANT4.7.

On Mac, the eclipse.ini file is under your eclipse installation at /Eclipse.app/Contents/MacOS/eclipse.ini . You will need a terminal window to get there as the directory doesn't show up in Finder. You could perform the following to find it:

sudo find / -name "eclipse.ini"

When I opened this for the first time I found that the parameters were triplicated - so I cleaned this up. I jack up the max memory, specify to use parallel GC, and keep the eden space low. I specify the following arguments:

-Xmx1024m (the max heap size)
-Xms128m (Startup heap size)
-Xmn64m (the eden space or young generation garbage collectible space)
-XX:+UseParallelGC (Run Parallel GC)


In java there are two GC threads running. One is a very lightweight thread which does incremental collections primarily on the Eden (a.k.a. Young) generation of the heap. The other is the Full GC thread which traverses the entire heap when there is not enough memory left to allocate space for objects which get promoted from the Eden to the older generation(s). If there is a memory leak or inadequate heap allocated, eventually the older generation will start to run out of room causing the Full GC thread to run continuously. This GC thread eats the processor and eventually eclipse has no pie - it won't be able to respond to requests and they'll start to back up.


The amount allocated for the Eden generation is the value specified with -Xmn. The amount allocated for the older generation is the value of -Xmx minus the -Xmn. Generally, you don't want the Eden to be too big or it will take too long for the GC to look through it for space that can be reclaimed. If you watch the memory monitor closely, you can see the garbage collector releasing memory periodically. Keeping the amount allocated to the eden space low affects the periodicity of this cleanup. Developers can see this on their machines when running the complete stack of tests.

These parameters seemed to work for me- my memory consumption remained nearly constant across the task. Before, the memory usage would creep up and reach a terminal point - on my old pc at about 2.4GB. At this point the tests just stopped running. Viewing the memory usage after applying the new args, you could see where GC ran periodically and brought the usage back to a baseline. The tests ran faster. But there was still an occasional lockup.

Another consideration is whether to run ANT, Tomcat and Eclipse in the same jvm. I tried experimenting with combinations of virtual machine with these processes. I also experimented with the memory allocations for each. What I found was that if you run them all in the same jvm, then the memory allocation on your machine remains high even after the tasks complete. When you run these in separate jvms, the memory allocation is returned to the system as each process completes. I found that the machine performed best when running separate jvms.


Caveat Emptor: Please be aware that not all jvms support the run parallel GC option.

To specify the jvm parameters for ANT, go to the ANT view, right click on the build file or a task, click 'Run As' and then 'external tools configuration'. In the dialog that appears, choose the JRE tab and specify the vmargs and the jvm to use for the file/task.

To Specify the jvm parameters for Tomcat, double click on the tomcat instance in the servers view. Update the vmargs by clicking the Launch Configuration link.

No comments: