Friday, September 10, 2010

Git Completion, Git Branch in Shell Prompt


  1. which git --> /usr/local/git/bin/git, so /usr/local/git is {GIT_HOME}

  2. cp {GIT_HOME}/contrib/completion/git-completion.bash ~/.git-completion.sh

  3. vi ~/.profile (or .bashrc if on Linux)

  4. insert into end of .profile:

    source ~/.git-completion.sh
    PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '

Open a new terminal window and enjoy.

Friday, August 7, 2009

Turn on DisableExplicitGC NOW!

Well, after two weeks of slogging through myriad combination of GC settings, GC logs, application logs, multiple JConsole windows, and cursing the various spreadsheet programs' pathetic ability to deal with data set that is of any significant size, I finally hit a jackpot of sort. Looking back though I practically would have to slap myself for not seeing this from the very beginning, it was right there, so apparent, so obvious.

Long story short. We have a service application that is used by various groups within the company. Lately we had been struggling a little bit to maintain our SLAs under much high load then we used to have. So we started digging into logs, and pretty soon started to focus on GC tuning. This application runs on Java 5, so we started with replacing the default serial collector with concurrent mark sweep collectors. There were some improvements, but not enough. The application still have way too many full GC events, and way too many full GCs that were caused by concurrent mode failures. However, there were not many regular CMS collection at all.

Looking through JConsole, full GCs started pretty much right after application start up and just keep going and going, and would later on be joined by concurrent mode failures when load starts to go up. So we increased total heap, and propotionally added more space to both young generation and old generation, hoping this would give objects in the young generation more time to die, and give old generation enough space to avoid concurrent mode failure. Well, that did not quit work out as we had hoped. YoungGen collections still happen at about the same frequency, and average YoungGen collection time really took a dive, using 5x more time. Worse, the full GCs and concurrent mode failures are still there, only this time there were less concurrent mode failures. Presumably the increased OldGen size helped out a little in terms of avoiding concurrent mode failures. The worst part of all this though is the large heap actually increased GC pause times and caused even more outliers that fall out of our SLA.

Now comes the jackpot part. I was staring at the GC logs which I imported into Excel, and at JConsole windows, watching the count of full CMS gcs going up steadily. Then it hit me, the pattern that is so obvious now: the full GCs were coming in once a minute, almost like clock work, right from application start up, when there were barely anything in OldGen. There is no way these were triggered by OldGen being used up, something must be calling System.gc() somewhere. A quick googling indicate this is probably the case. And the fix is straight forward, disable explicit GC calls by using the flag -XX:+DisableExplicitGC. Presto, no more this one full GC per minute nonsense.

An added bonus, with explicit GC disabled, now we see the expected regular CMS collections. And more importantly, we found out our PermGen was getting full. Our load test still led to two concurrent mode failures. From what we can see with JConsole, these two failures happens right after PermGen got full, the full GC cleaned up about half of the PermGen space. So we will up our PermGen as well. Our application instantiate a whole bunch of objects every few minutes and caches them, so we know we are thrashing PermGen space. The once per minute full GCs were masking the fact that our PermGen was too small.

One day I might spend some time to find out which library we use is calling System.gc(). I am pretty sure I will go anywhere near it, not after these last couple weeks in GC tuning paradise :-)

Thursday, August 6, 2009

Graphing GC Events

Having been knee deep in tuning GC, trying to reduce GC pause time. Unfortunately Microsoft Excel, Apple Numbers, and OpenOffice Spreadsheet are all quite weak when dealing with the amount of GC and non-GC events we are trying to analyze, especially when it comes time trying to graph these events. Open Office on Ubuntu actually performed better, was able to deal with number of events that chokes both Excel and Numbers. However working with OpenOffice Spreadsheet is not the smoothed experience, as there are quite some rough edges here and there.

We've been using JConsole to watch live GC events, which is nice. If you can, always use JDK 6 JConsole instead of that from JDK 5. The former keeps history when JVM terminates, which is very nice.

Next we probably will investigate VisualGC (http://java.sun.com/performance/jvmstat/visualgc.html), VisualVM (https://visualvm.dev.java.net/), gchisto (https://gchisto.dev.java.net/). Hopefully one of them will turn out to be a better tool then pure spreadsheets.

Or, there is always JFreeChart or GnuPlot :-) One of our guys already used JFreeChat to plot some data, which actually looked quite nice.

Update on 08/07/2009:
Checked out VisualVM today along with its VisualGC plugin. The application itself looked pretty nice. However I was getting some kind of NullPointerException with the monitoring view, so there is no graph of heap usage etc. I am using Java 6 on Ubutnu, and I was having trouble get the VisualGC plugin to work with both of my remote JVMs. Of the the JVM is Java 5 32bit on Ubuntu, the other is Java 6 64 bit on Ubuntu. In both cases VisualGC was complaining it cannot work with the JVM version. Anyhow, from what I saw, I don't think VisualVM/VisualGC will give me the kind of graph that I was trying to do with spreadsheets, as I was plotting very detailed GC times for CMS initial mark, remark time, full GC, full GC from concurrent mode failure, and ParNew collections. Given that, I am still quite impressed with what I saw from VisualVM, and I am surely will visit it again the next time I need to dig into some other tough performance tuning problems.

Friday, November 21, 2008

Debugging Mule Application in Eclipse

Two ways to debug a Mule application:

First, Mule user guide has this page, Remote Debugging a Mule Server. Free registration is required to access this page. The page lists all the default steps, but that's all unnecessary as you only need to follow instructions at the top of the page, i.e., launch Mule with a -debug switch. Default debug port is 5005. Just go ahead and attach to the Mule instance using Eclipse's Remote Java Application configuration. What's good with this approach is remote Mule instances can be attached to and debugged.

Alternatively you can choose to launch Mule from inside Eclipse. Follow the section "Create a Run Configuration and Run the Application" in this page Setting Up Eclipse - Mule 2.x Getting Started Guide, basically set up a Java Application run configuration using org.mule.MuleServer, specify -config argument, then simply launch it in debug mode.


Monday, November 17, 2008

JAX-WS 2.1.3 runtime with Jetty

So I had the need to make a web service call out from a web application using JAX-WS 2.1.3 runtime. To do this in WebLogic 10.0.1, one has to resort to WebLogic-specific classpath manipulations, i.e., putting the runtime jars inside APP-INF/lib folder of the EAR that contains the .war file. One would also need to put the following in application-weblogic.xml:


<prefer-application-packages>
<package-name>javax.activation.*</package-name>
<package-name>javax.annotation.*</package-name>
<package-name>javax.jws.*</package-name>
<package-name>javax.xml.bind.*</package-name>
<package-name>javax.xml.soap.*</package-name>
<package-name>javax.xml.stream.*</package-name>
<package-name>javax.xml.ws.*</package-name>

<package-name>com.sun.activation.registries.*</package-name>
<package-name>com.sun.activation.viewers.*</package-name>
<package-name>com.sun.istack.*</package-name>
<package-name>com.sun.org.apache.xml.internal.resolver.*</package-name>
<package-name>com.sun.xml.bind.*</package-name>
<package-name>com.sun.xml.messaging.*</package-name>
<package-name>com.sun.xml.stream.*</package-name>
<package-name>com.sun.xml.txw2.*</package-name>
<package-name>com.sun.xml.ws.*</package-name>

<package-name>org.jvnet.mimepull.*</package-name>
<package-name>org.jvnet.staxex.*</package-name>

<package-name>weblogic.xml.saaj.*</package-name>
</prefer-application-packages>


So, not the easiest way around.

Well, turns out it's much easier to do this in Jetty, all one has to do is to package the following jars from JAX-WS 2.1.3 distribution into WEB-INF/lib and everything is golden:

activation-1.1.jar
jaxb-api-2.1.jar
jaxb-impl-2.1.6.jar
jaxws-api-2.1.jar
jaxws-rt-2.1.3.jar
jsr181-api-1.0.jar
jsr250-api-1.0.jar
mimepull-1.1.jar
resolver-20050927.jar
saaj-api-1.3.jar
saaj-impl-1.3.jar
sjsxp-1.0.jar
stax-api-1.0-2.jar
stax-ex-1.2.jar
streambuffer-0.7.jar

If you are using maven 2, the following dependencies should do the trick:

<dependency>
<groupId>javax.xml.ws</groupId>
<artifactId>jaxws-api</artifactId>
<version>2.1</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-rt</artifactId>
<version>2.1.3</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>javax.jws</groupId>
<artifactId>jsr181-api</artifactId>
<version>1.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.1</version>
<scope>compile</scope>
</dependency>