<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>REVERT TO CONSOLE &#187; Performance</title>
	<atom:link href="http://www.reverttoconsole.com/blog/category/performance/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.reverttoconsole.com</link>
	<description>for f in *;do echo &#124; sed &#039;i\rtc&#039; &#62;&#62; $f;done; java programming et al</description>
	<lastBuildDate>Thu, 25 Aug 2011 15:02:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>The best 59$, a java developer can ever invest</title>
		<link>http://www.reverttoconsole.com/blog/core-java/the-best-59-a-java-developer-can-ever-invest/</link>
		<comments>http://www.reverttoconsole.com/blog/core-java/the-best-59-a-java-developer-can-ever-invest/#comments</comments>
		<pubDate>Wed, 17 Jun 2009 20:03:10 +0000</pubDate>
		<dc:creator>Priyatam</dc:creator>
				<category><![CDATA[Core Java]]></category>
		<category><![CDATA[Performance]]></category>

		<guid isPermaLink="false">http://www.reverttoconsole.com/?p=388</guid>
		<description><![CDATA[If you don&#8217;t buy this now, you&#8217;re either dumb. Or just plainly stupid. For the impatient: it&#8217;s a small jar that lets you compile/run/deploy java instantly, like php. I&#8217;ts the real HOT DEPLOY that jvm lacks out of the box. No more restarting the server, ever again, even after reconfiguring Spring beans. I used this [...]]]></description>
			<content:encoded><![CDATA[<p>If you don&#8217;t buy <a href="http://www.zeroturnaround.com/javarebel/">this </a>now, you&#8217;re either dumb. Or just plainly stupid.</p>
<p>For the impatient: it&#8217;s a small jar that lets you compile/run/deploy java instantly, like php. I&#8217;ts the real HOT DEPLOY that jvm lacks out of the box.</p>
<p>No more restarting the server, ever again, even after reconfiguring Spring beans.</p>
<p>I used this for a month, and convinced my manager to buy licenses for all. It&#8217;s that good.</p>

<span class="slashdigglicious">
<a href="http://slashdot.org/bookmark.pl?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcore-java%2Fthe-best-59-a-java-developer-can-ever-invest%2F&amp;title=The+best+59%24%2C+a+java+developer+can+ever+invest" title="Slashdot It!"><img src="http://slashdot.org/favicon.ico" height="16" width="16" alt="[Slashdot]" /></a>
<a href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcore-java%2Fthe-best-59-a-java-developer-can-ever-invest%2F&amp;title=The+best+59%24%2C+a+java+developer+can+ever+invest" title="Digg This Story"><img src="http://digg.com/favicon.ico" width="16" height="16" alt="[Digg]" /></a>
<a href="http://reddit.com/submit?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcore-java%2Fthe-best-59-a-java-developer-can-ever-invest%2F&amp;title=The+best+59%24%2C+a+java+developer+can+ever+invest" title="Reddit"><img src="http://reddit.com/favicon.ico" width="16" height="16" alt="[Reddit]" /></a>
<a href="http://del.icio.us/post?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcore-java%2Fthe-best-59-a-java-developer-can-ever-invest%2F&amp;title=The+best+59%24%2C+a+java+developer+can+ever+invest" title="Save to del.icio.us" onclick="window.open('http://del.icio.us/post?v=4&amp;noui&amp;jump=close&amp;url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcore-java%2Fthe-best-59-a-java-developer-can-ever-invest%2F&amp;title=The+best+59%24%2C+a+java+developer+can+ever+invest', 'delicious', 'toolbar=no,width=700,height=400'); return false;"><img src="http://images.del.icio.us/static/img/delicious.small.gif" width="16" height="16" alt="[del.icio.us]" /></a>
<a href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcore-java%2Fthe-best-59-a-java-developer-can-ever-invest%2F" title="Share on Facebook"><img src="http://www.facebook.com/favicon.ico" width="16" height="16" alt="[Facebook]" /></a>
<a href="http://technorati.com/faves?add=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcore-java%2Fthe-best-59-a-java-developer-can-ever-invest%2F" title="Add to my Technorati Favorites"><img src="http://technorati.com/favicon.ico" width="16" height="16" alt="[Technorati]" /></a>
<a href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcore-java%2Fthe-best-59-a-java-developer-can-ever-invest%2F&amp;title=The+best+59%24%2C+a+java+developer+can+ever+invest" title="Save to Google Bookmarks"><img src="http://www.google.com/favicon.ico" width="16" height="16" alt="[Google]" /></a>
<a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcore-java%2Fthe-best-59-a-java-developer-can-ever-invest%2F&amp;title=The+best+59%24%2C+a+java+developer+can+ever+invest" title="Stumble it!"><img src="http://www.stumbleupon.com/favicon.ico" width="16" height="16" alt="[StumbleUpon]" /></a>
</span>]]></content:encoded>
			<wfw:commentRss>http://www.reverttoconsole.com/blog/core-java/the-best-59-a-java-developer-can-ever-invest/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>DBCP vs C3P0</title>
		<link>http://www.reverttoconsole.com/blog/performance/dbcp-vs-c3p0/</link>
		<comments>http://www.reverttoconsole.com/blog/performance/dbcp-vs-c3p0/#comments</comments>
		<pubDate>Fri, 25 Apr 2008 13:20:46 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[Performance]]></category>

		<guid isPermaLink="false">http://reverttoconsole.com/archives/172</guid>
		<description><![CDATA[I didn&#8217;t know there was a great debate going on between DBCP and C3P0 about 6 months ago going on. My new project is using C3P0 for connection pooling with JNDI-bindable datasources and I find it really annoying to have it configured that way in development. Anyway C3P0 is a project that&#8217;s new to me, [...]]]></description>
			<content:encoded><![CDATA[<p>I didn&#8217;t know there was a <a href="http://forum.springframework.org/showthread.php?t=45575">great debate going on between DBCP and C3P0 about 6 months ago</a> going on. My new project is using <a href="http://sourceforge.net/projects/c3p0/">C3P0 </a>for connection pooling with JNDI-bindable datasources and I find it really annoying to have it configured that way in development. Anyway C3P0 is a project that&#8217;s new to me, I&#8217;m used to using <a href="http://commons.apache.org/dbcp/">DBCP</a> with Spring. From the docs, DBCP is:</p>
<blockquote><p>The <code>commons-dbcp</code> package relies on code in the <code>commons-pool</code> package to provide the underlying object pool mechanisms that it utilizes.</p></blockquote>
<blockquote><p> Applications can use the <code>commons-dbcp</code> component directly or through the existing interface of their container / supporting framework.</p></blockquote>
<p><a href="http://sourceforge.net/projects/c3p0/">C3P0</a>, on the other hand,</p>
<blockquote><p>c3p0 is an easy-to-use library for augmenting traditional (DriverManager-based) JDBC drivers with JNDI-bindable DataSources, including DataSources that implement Connection and Statement Pooling, as described by the jdbc3 spec and jdbc2 std extension.</p></blockquote>
<p>I found an interesting article comparing DBCP and C3PO, but it was only available via google&#8217;s cache. So I&#8217;m copying it here after the jump&#8230;</p>
<p><span id="more-146"></span></p>
<p class="post-meta" id="post-17">
<h1><a href="http://javatech.org/2007/11/12/c3p0-vs-dbcp-the-straight-dope/" title="C3P0 vs DBCP - The Straight Dope">C3P0 vs <strong style="color: black; background-color: #ffff66">DBCP</strong> &#8211; The Straight Dope</a></h1>
<p class="posted-aut-cat">Posted in November 12th, 2007</p>
<p class="posted-aut-cat">by <a href="http://javatech.org/author/admin/" title="Posts by Darren Hicks">Darren Hicks</a> in <a href="http://javatech.org/category/open-source/" title="View all posts in Open Source" rel="category tag">Open Source</a>,  <a href="http://javatech.org/category/benchmarks/" title="View all posts in Benchmarks" rel="category tag">Benchmarks</a></p>
<p class="post-content"> I’ve found it very difficult to find any accurate comparisons of C3P0 and <strong style="color: black; background-color: #ffff66">DBCP</strong>.  Why should I choose C3P0 over <strong style="color: black; background-color: #ffff66">DBCP</strong>?  When might <strong style="color: black; background-color: #ffff66">DBCP</strong> be better?</p>
<p>Well, here’s a fairly in-depth overview of both with pros and cons and similarities and differences included.</p>
<p>The first thing to note is that if you’re not in a multi-threaded environment, then <strong style="color: black; background-color: #ffff66">DBCP</strong> is going to be faster than C3P0 and will also use significantly fewer connections than C3P0. For example, using the default settings for each and sizing the pool to contain 50 connections at most, will yield results like the following single-threaded test.</p>
<p><strong>Single-threaded Benchmark &#8211; 50,000 calls to getConnection()</strong></p>
<table border="1">
<tr>
<th></th>
<th>Trials</th>
<th>MaxPoolSize</th>
<th>Connections Used</th>
<th>Seconds</th>
<th>Settings</th>
</tr>
<tr>
<th><strong style="color: black; background-color: #ffff66">DBCP</strong></th>
<td>50,000</td>
<td>50</td>
<td>1</td>
<td>5.18</td>
<td>—</td>
</tr>
<tr>
<th>C3P0</th>
<td>50,000</td>
<td>50</td>
<td>50</td>
<td>6.72</td>
<td>*numHelperThreads=3</td>
</tr>
<tr>
<th>C3P0</th>
<td>50,000</td>
<td>50</td>
<td>39</td>
<td>6.6</td>
<td>numHelperThreads=4</td>
</tr>
<tr>
<th>C3P0</th>
<td>50,000</td>
<td>50</td>
<td>27</td>
<td>6.45</td>
<td>numHelperThreads=5</td>
</tr>
<tr>
<th>C3P0</th>
<td>50,000</td>
<td>50</td>
<td>30</td>
<td>6.63</td>
<td>numHelperThreads=6</td>
</tr>
</table>
<p>Suffice it to say that <strong style="color: black; background-color: #ffff66">DBCP</strong> is obviously better suited to Single-threaded applications with high load. Needing 50 connections in the pool to do the work where only 1 is needed is certainly not desired. This is the case with C3P0’s default setting of “numHelperThreads=3?. Regardless of the environment you have ( single-threaded, multi-threaded ) I would always change this setting if you forsee high load on the program. I would always use at least “numHelperThreads=5?. As a bit of background/explanation, C3P0 doesn’t actually make a connection available in the pool when it is checked-in. Instead the HelperThreads will detect these and do the work to get them back in the pool. This is great in high-load, multi-threaded environments as it avoids blocking issues. But it inherently requires a much larger number of connections to provide the same functionality ( especially if you keep “numHelperThreads=3? ). Also, notice that <strong style="color: black; background-color: #ffff66">DBCP</strong> is 20% faster regardless of how we tweak numHelperThreads.</p>
<p>Score 2 points for <strong style="color: black; background-color: #ffff66">DBCP</strong>.  2-0.</p>
<p>Next what if we run the same test with a smaller connection pool size &#8211; say of only 5 connections, and numHelperThreads=3 for C3P0?</p>
<p>The results are a bit counterintuitive ( to me at least ).  <strong style="color: black; background-color: #ffff66">DBCP</strong> does at least manage to stay the same &#8211; very fast and reasonable ( needing just 1 connection in its pool ). But C3P0, which I expected to take longer because it previously needed all 50 connections, but actually runs faster with a smaller pool : 6.25 seconds down from 6.7 seconds. The lesson here is that C3P0 is slowing itself down with the HelperThreads having to manage all the extra connections to get them back in the pool.</p>
<table border="1">
<tr>
<th></th>
<th>Trials</th>
<th>MaxPoolSize</th>
<th>Connections Used</th>
<th>Seconds</th>
<th>Settings</th>
</tr>
<tr>
<th><strong style="color: black; background-color: #ffff66">DBCP</strong></th>
<td>50,000</td>
<td>5</td>
<td>1</td>
<td>5.18</td>
<td>—</td>
</tr>
<tr>
<th>C3P0</th>
<td>50,000</td>
<td>5</td>
<td>5</td>
<td>6.18</td>
<td>*numHelperThreads=3</td>
</tr>
</table>
<p>Score 1 point each.  <strong style="color: black; background-color: #ffff66">DBCP</strong> for making sense and C3P0 for speeding up.</p>
<p>3-1, <strong style="color: black; background-color: #ffff66">DBCP</strong> in the lead.</p>
<p>Now for the good stuff &#8211; the multi-threaded tests.  I’ll be varying the number of Threads which will be running.<br />
<strong>Multi-threaded tests</strong></p>
<table border="1">
<tr>
<th></th>
<th>Threads</th>
<th>MaxPoolSize</th>
<th>Connections Used</th>
<th>Seconds</th>
<th>Settings</th>
</tr>
<tr>
<th><strong style="color: black; background-color: #ffff66">DBCP</strong></th>
<td>25</td>
<td>5</td>
<td>5</td>
<td>90</td>
<td>—</td>
</tr>
<tr>
<th><strong style="color: black; background-color: #ffff66">DBCP</strong></th>
<td>25</td>
<td>10</td>
<td>10</td>
<td>107</td>
<td>—</td>
</tr>
<tr>
<th><strong style="color: black; background-color: #ffff66">DBCP</strong></th>
<td>25</td>
<td>25</td>
<td>25</td>
<td>167</td>
<td>—</td>
</tr>
<tr>
<th><strong style="color: black; background-color: #ffff66">DBCP</strong></th>
<td>50</td>
<td>50</td>
<td>50</td>
<td>198</td>
<td>—</td>
</tr>
<tr>
<th><strong style="color: black; background-color: #ffff66">DBCP</strong></th>
<td>50</td>
<td>100</td>
<td>50</td>
<td>207</td>
<td>—</td>
</tr>
<tr>
<th>C3P0</th>
<td>25</td>
<td>5</td>
<td>5</td>
<td>156</td>
<td>*numHelperThreads=3</td>
</tr>
<tr>
<th>C3P0</th>
<td>25</td>
<td>10</td>
<td>10</td>
<td>142</td>
<td>*numHelperThreads=3</td>
</tr>
<tr>
<th>C3P0</th>
<td>25</td>
<td>25</td>
<td>25</td>
<td>137</td>
<td>*numHelperThreads=3</td>
</tr>
<tr>
<th>C3P0</th>
<td>50</td>
<td>50</td>
<td>50</td>
<td>252</td>
<td>*numHelperThreads=3</td>
</tr>
<tr>
<th>C3P0</th>
<td>50</td>
<td>100</td>
<td>100</td>
<td>252</td>
<td>*numHelperThreads=3</td>
</tr>
<tr>
<th>C3P0</th>
<td>50</td>
<td>100</td>
<td>100</td>
<td>269</td>
<td>numHelperThreads=6</td>
</tr>
</table>
<p>Score yet another to <strong style="color: black; background-color: #ffff66">DBCP</strong>. Faster across the board on all accounts. So, what is it about C3P0 that has everybody ( myself included ) using it and singing its praises? Multiple threads yield multiple points again for <strong style="color: black; background-color: #ffff66">DBCP</strong> &#8211; 2 points awarded.</p>
<p>5-1, C3P0 will need a miracle comeback at this point.</p>
<p>I know, usually Connections aren’t just checked out and run with a small SQL statement and immediately returned like the Benchmarks I’ve been running. Maybe I need to put some delay in there to more closely mimic real world performance. I’m going to throw a new setting in here which is a delay in milliseconds that each call to getConnection() will endure before finishing with the connection. I’ll give it a shot with an extra 100ms of sleep time after each SQL statement is run.</p>
<p><strong>Multi-threaded &#8211; 100ms of sleep time added</strong></p>
<table border="1">
<tr>
<th></th>
<th>Threads</th>
<th>MaxPoolSize</th>
<th>Connections Used</th>
<th>Seconds</th>
<th>Settings</th>
</tr>
<tr>
<th><strong style="color: black; background-color: #ffff66">DBCP</strong></th>
<td>50</td>
<td>25</td>
<td>25</td>
<td>9338</td>
<td>—</td>
</tr>
<tr>
<th><strong style="color: black; background-color: #ffff66">DBCP</strong></th>
<td>50</td>
<td>10</td>
<td>10</td>
<td>20918</td>
<td>—</td>
</tr>
<tr>
<th><strong style="color: black; background-color: #ffff66">DBCP</strong></th>
<td>100</td>
<td>50</td>
<td>50</td>
<td>9248</td>
<td>—</td>
</tr>
<tr>
<th><strong style="color: black; background-color: #ffff66">DBCP</strong></th>
<td>0</td>
<td>50</td>
<td>50</td>
<td>0</td>
<td>—</td>
</tr>
<tr>
<th><strong style="color: black; background-color: #ffff66">DBCP</strong></th>
<td>0</td>
<td>100</td>
<td>50</td>
<td>0</td>
<td>—</td>
</tr>
<tr>
<th>C3P0</th>
<td>50</td>
<td>25</td>
<td>25</td>
<td>9295</td>
<td>numHelperThreads=6</td>
</tr>
<tr>
<th>C3P0</th>
<td>50</td>
<td>10</td>
<td>10</td>
<td>20088</td>
<td>numHelperThreads=6</td>
</tr>
<tr>
<th>C3P0</th>
<td>100</td>
<td>50</td>
<td>50</td>
<td>9412</td>
<td>numHelperThreads=6</td>
</tr>
<tr>
<th>C3P0</th>
<td>0</td>
<td>50</td>
<td>50</td>
<td>0</td>
<td>*numHelperThreads=3</td>
</tr>
<tr>
<th>C3P0</th>
<td>0</td>
<td>100</td>
<td>100</td>
<td>0</td>
<td>*numHelperThreads=3</td>
</tr>
<tr>
<th>C3P0</th>
<td>0</td>
<td>100</td>
<td>100</td>
<td>0</td>
<td>numHelperThreads=6</td>
</tr>
</table>
<h2>4 users commented in &#8221; C3P0 vs <strong style="color: black; background-color: #ffff66">DBCP</strong> &#8211; The Straight Dope &#8220;</h2>
<p><span class="rssfeed">             Follow-up <a href="http://javatech.org/2007/11/12/c3p0-vs-dbcp-the-straight-dope/feed/">comment rss</a> or Leave a <a href="http://javatech.org/2007/11/12/c3p0-vs-dbcp-the-straight-dope/trackback/">Trackback</a>             </span><script type="text/javascript"><!-- google_ad_client = ""; google_ad_width = 468; google_ad_height = 60; google_ad_format = "468x60_as"; google_ad_type = "text"; google_ad_channel = ""; google_color_border = "ffffff"; google_color_bg = "ffffff"; google_color_link = "333333"; google_color_text = "333333"; google_color_url = "80856B"; //--> </script> <script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"> </script><iframe src="http://pagead2.googlesyndication.com/pagead/ads?client=&amp;dt=1209141053453&amp;lmt=1209141050&amp;format=468x60_as&amp;output=html&amp;correlator=1209141053453&amp;url=http%3A%2F%2F209.85.173.104%2Fsearch%3Fq%3Dcache%3A0hWLi1J_Z2QJ%3Ajavatech.org%2F%253Fp%253D17%2Bdbcp%2Bversus%2Bc3po%26hl%3Den%26ct%3Dclnk%26cd%3D6%26gl%3Dus%26client%3Dfirefox-a&amp;color_bg=ffffff&amp;color_text=333333&amp;color_link=333333&amp;color_url=80856B&amp;color_border=ffffff&amp;ad_type=text&amp;frm=0&amp;cc=28&amp;ga_vid=1037078069.1209141053&amp;ga_sid=1209141053&amp;ga_hid=293317023&amp;flash=9.0.124&amp;u_h=1050&amp;u_w=1680&amp;u_ah=1016&amp;u_aw=1680&amp;u_cd=32&amp;u_tz=-300&amp;u_his=2&amp;u_java=true&amp;u_nplug=13&amp;u_nmime=51" name="google_ads_frame" marginwidth="0" marginheight="0" vspace="0" hspace="0" allowtransparency="true" frameborder="0" height="60" scrolling="no" width="468"></iframe></p>
<p class="com-box_alt">
<p class="author_com">rpt said,</p>
<p class="author_date">             in November 23rd, 2007 at 1:14 pm</p>
<p class="author_com_text">So, what is it about C3P0 that has everybody (yourself included) using it and singing its praises?</p>
<p class="com-box">
<p class="author_com">Darren Hicks said,</p>
<p class="author_date">             in November 23rd, 2007 at 7:59 pm</p>
<p class="author_com_text">The biggest thing is the lack of blocking in multithreaded environments.  With <strong style="color: black; background-color: #ffff66">DBCP</strong>, even the act of returning a connection to the pool is a blocking operation. In production environments where there are other resources being worked with ( possibly also synchronously ), there then arises the likelihood of slowdowns and the potential for deadlocks. It only takes a few of these occurences to see the value C3P0 adds. Additionally, C3P0 ships with JMX management and can be fine tuned to a greater extent than <strong style="color: black; background-color: #ffff66">DBCP</strong>.</p>
<p>I’ve got to finish the article and come up with the test cases demonstrating the <strong style="color: black; background-color: #ffff66">DBCP</strong> slowdowns and deadlocks when using other synchronous resources <img src="http://javatech.org/wp-includes/images/smilies/icon_wink.gif" alt=";)" class="wp-smiley" /></p>
<p class="com-box_alt">
<p class="author_com">andy said,</p>
<p class="author_date">             in November 25th, 2007 at 2:15 am</p>
<p class="author_com_text">how about adding Proxool to the comparison ?</p>
<p class="com-box">
<p class="author_com">mike said,</p>
<p class="author_date">             in April 9th, 2008 at 4:21 pm</p>
<p class="author_com_text">Thanks for taking the time to benchmark and share with everyone…</p>
<p>I haven’t used Proxool at all but was recently using <strong style="color: black; background-color: #ffff66">DBCP</strong> on a busy tomcat site (15M hits/day) and was running into a wall of contention that turned out to be <strong style="color: black; background-color: #ffff66">DBCP</strong>… Switched to C3P0 and this issue was immediately resolved and actually looked like it was doing so with less connections and faster response times.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.reverttoconsole.com/blog/performance/dbcp-vs-c3p0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The size of an object instance at runtime &#8211; pre Java 1.5</title>
		<link>http://www.reverttoconsole.com/blog/core-java/the-size-of-an-object-instance-at-runtime-pre-java-15/</link>
		<comments>http://www.reverttoconsole.com/blog/core-java/the-size-of-an-object-instance-at-runtime-pre-java-15/#comments</comments>
		<pubDate>Tue, 13 Nov 2007 12:42:56 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[Core Java]]></category>
		<category><![CDATA[Performance]]></category>

		<guid isPermaLink="false">http://reverttoconsole.com/archives/147</guid>
		<description><![CDATA[In Java 1.5, Sun provides us with a miracle method that is long overdue: long java.lang.instrument.Instrumentation.getObjectSize (Object objectToSize) However, this is still limited in that it only returns the total size of the Object, not the details about the Object size in regard to its composition. Enter monq.jar from Whatizit. There&#8217;s a Sizeof class in [...]]]></description>
			<content:encoded><![CDATA[<p>In Java 1.5, Sun provides us with a miracle method that is long overdue:<br />
long java.lang.instrument.Instrumentation.getObjectSize (Object objectToSize)</p>
<p>However, this is still limited in that it only returns the total size of the Object, not the details about the Object size in regard to its composition.</p>
<p>Enter <a href="ftp://ftp.ebi.ac.uk/pub/software/textmining/monq/monq.jar">monq.jar</a> from<br />
<a href="http://www.ebi.ac.uk/Rebholz-srv/whatizit/software">Whatizit</a>.</p>
<p>There&#8217;s a <code>Sizeof</code> class in monq.jar with a static <code>sizeof</code> method that walks through an Object instance at runtime and counts up the bytes in use for all its elements and then returns a HashTable.  The results seem to be consistent with what I&#8217;ve seen by using the java.lang.Runtime class to estimate heap size.  The Sizeof class also provides a convenient <code>printTypes</code> method which can be used to dump the HashTable data to an OutputStream (such as System.out).  This allows you to easily see which nodes of a given Object tree might be prone to causing trouble.  Though it cannot be 100% accurate, it&#8217;s probably very close.</p>
<p>Here&#8217;s a simple usage example:</p>
<pre>
public void printObjectSizeTable(Object object) {
   Sizeof.printTypes(System.out, Sizeof.sizeof(object));
}
</pre>
<p>The above will print out a table consisting of four columns, which are:</p>
<ul>
<li>Count of the particular type</li>
<li>Total byte size of the type</li>
<li>
Containing type class name</li>
<li>Type class name</li>
</ul>
<p>Example output using a populated ArrayList as the parameter to the method above:</p>
<pre>
26 1516 java.lang.Object; java.util.ArrayList
25 500 java.util.ArrayList java.util.ArrayList
1 20 java.util.ArrayList monq.stuff.Sizeof$Root
52 2036 TOTAL
</pre>
<p>I might just start integrating this into some junit tests.  I certainly believe that it will be very useful in determining the cause of performance problems.</p>
<p>-&#8221;That&#8217;s all for now folks&#8221;</p>

<span class="slashdigglicious">
<a href="http://slashdot.org/bookmark.pl?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcore-java%2Fthe-size-of-an-object-instance-at-runtime-pre-java-15%2F&amp;title=The+size+of+an+object+instance+at+runtime+%26%238211%3B+pre+Java+1.5" title="Slashdot It!"><img src="http://slashdot.org/favicon.ico" height="16" width="16" alt="[Slashdot]" /></a>
<a href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcore-java%2Fthe-size-of-an-object-instance-at-runtime-pre-java-15%2F&amp;title=The+size+of+an+object+instance+at+runtime+%26%238211%3B+pre+Java+1.5" title="Digg This Story"><img src="http://digg.com/favicon.ico" width="16" height="16" alt="[Digg]" /></a>
<a href="http://reddit.com/submit?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcore-java%2Fthe-size-of-an-object-instance-at-runtime-pre-java-15%2F&amp;title=The+size+of+an+object+instance+at+runtime+%26%238211%3B+pre+Java+1.5" title="Reddit"><img src="http://reddit.com/favicon.ico" width="16" height="16" alt="[Reddit]" /></a>
<a href="http://del.icio.us/post?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcore-java%2Fthe-size-of-an-object-instance-at-runtime-pre-java-15%2F&amp;title=The+size+of+an+object+instance+at+runtime+%26%238211%3B+pre+Java+1.5" title="Save to del.icio.us" onclick="window.open('http://del.icio.us/post?v=4&amp;noui&amp;jump=close&amp;url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcore-java%2Fthe-size-of-an-object-instance-at-runtime-pre-java-15%2F&amp;title=The+size+of+an+object+instance+at+runtime+%26%238211%3B+pre+Java+1.5', 'delicious', 'toolbar=no,width=700,height=400'); return false;"><img src="http://images.del.icio.us/static/img/delicious.small.gif" width="16" height="16" alt="[del.icio.us]" /></a>
<a href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcore-java%2Fthe-size-of-an-object-instance-at-runtime-pre-java-15%2F" title="Share on Facebook"><img src="http://www.facebook.com/favicon.ico" width="16" height="16" alt="[Facebook]" /></a>
<a href="http://technorati.com/faves?add=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcore-java%2Fthe-size-of-an-object-instance-at-runtime-pre-java-15%2F" title="Add to my Technorati Favorites"><img src="http://technorati.com/favicon.ico" width="16" height="16" alt="[Technorati]" /></a>
<a href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcore-java%2Fthe-size-of-an-object-instance-at-runtime-pre-java-15%2F&amp;title=The+size+of+an+object+instance+at+runtime+%26%238211%3B+pre+Java+1.5" title="Save to Google Bookmarks"><img src="http://www.google.com/favicon.ico" width="16" height="16" alt="[Google]" /></a>
<a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.reverttoconsole.com%2Fblog%2Fcore-java%2Fthe-size-of-an-object-instance-at-runtime-pre-java-15%2F&amp;title=The+size+of+an+object+instance+at+runtime+%26%238211%3B+pre+Java+1.5" title="Stumble it!"><img src="http://www.stumbleupon.com/favicon.ico" width="16" height="16" alt="[StumbleUpon]" /></a>
</span>]]></content:encoded>
			<wfw:commentRss>http://www.reverttoconsole.com/blog/core-java/the-size-of-an-object-instance-at-runtime-pre-java-15/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

