codecentric

Save Memory by Using String Intern in Java

During Attila Szegedis talk about “lessons learned about the JVM” at QCon London, I was surprised that he emphasized the importance of knowing the amount of data you store in memory. It is not common to be concerned about object size in enterprise Java programming, but he gave a good example of what they had to do Twitter.

Recap: Memory Footprint of Data

Question: How much memory does the String “Hello World” consume?
Answer: 62/86 Bytes (32/64 bit Java)!
This breaks down into 8/16 (Object Header for String) + 11 * 2 (characters) + [8/16 (Object Header char Array) + 4 (array length) padded to 16/24] + 4 (Offset) + 4 (Count) + 4 (HashCode) + 4/8 (Reference to char Array). [On 64Bit the size of String Object is padded to 40].

The Problem

Imagine you have a lot of Locations attached to tweets in your data store. The implementation of the location as a Java class could look like this

class Location {
	String city;
	String region;
	String countryCode;
	double long;
	double lat;
}

So if you load all the locations of tweets ever made, it is quite obvious that you load a lot of String objects, and at the scale Twitter has, there are for sure a lot of duplicate Strings. Attila said that this data did not fit into a 32 GB heap. So the question is: can we reduce memory consumption, so that all Locations fit into memory?
(read more…)

Fabian Lange

 

Analyzing Production Outage Caused by Weblogic Compiler Threads

I was at a customer recently to further improve their application monitoring for which they were using AppDynammics. When I arrived, they told me:
“Good that you came Fabian, we have something interesting to show”. Usually operations guys are very concerned about something when they say this to me, but in this case, they were happy. “We had a big outage when we took our new software live on Saturday!”. Ooops?? Nobody likes production outage on Saturdays! Why are they so happy about it? “Well it was a long Saturday, but thanks to our monitoring we knew what was going on”.

So let me walk you through what they did, and show you the problem that killed their server.

An Overview of the Situation

Here is what the situation looked like on Saturday 8 in the morning.

(read more…)

Fabian Lange

 

Find Memory Leaks at Runtime – Addendum

In Act 5 of our OutOfMemoryError series, I talked about the lack of tool support for finding memory leaks at runtime. I got some negative feedback on dzone, because the tool I discussed was commercial :-(
Shortly after I published that post, I got notified of a product called “plumbr“. Plumbr is in beta phase, which means it is free at the moment, and they even have a public pricing discussion. But still we need to accept, that there is no free solution. Its not my fault, so don’t be angry :-)
In this short update, I will show you how plumber will find the very same memory leak, which AppDynamics found in my last article.
(read more…)

Fabian Lange