<?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>Xavier Llorà &#187; java</title>
	<atom:link href="http://www.xavierllora.net/tag/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.xavierllora.net</link>
	<description>A notebook on data-intensive computing, genetics-based machine learning &#38; more.</description>
	<lastBuildDate>Sun, 08 Jan 2012 19:39:15 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Temporary storage for Meandre&#8217;s distributed flow execution</title>
		<link>http://www.xavierllora.net/2009/09/29/temporary-storage-for-meandres-distribute-flow-execution/</link>
		<comments>http://www.xavierllora.net/2009/09/29/temporary-storage-for-meandres-distribute-flow-execution/#comments</comments>
		<pubDate>Tue, 29 Sep 2009 15:14:28 +0000</pubDate>
		<dc:creator>Xavier</dc:creator>
				<category><![CDATA[Notes]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Data-Intensive Computing]]></category>
		<category><![CDATA[data-intensive flows]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[meandre]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[storage]]></category>
		<category><![CDATA[tokyo cabinet]]></category>

		<guid isPermaLink="false">http://www.xavierllora.net/?p=615</guid>
		<description><![CDATA[Designing the distributed execution of a generic Meandre flow involves several moving pieces. One of those is the temporary storage required by the computing nodes (think of it as one node as one isolated component of a flow) to keep up with the data generated by a component, and also be able to replicate such [...]
Related posts:<ol>
<li><a href='http://www.xavierllora.net/2009/08/13/easy-reliable-and-flexible-storage-for-python/' rel='bookmark' title='Easy, reliable, and flexible storage for Python'>Easy, reliable, and flexible storage for Python</a></li>
<li><a href='http://www.xavierllora.net/2008/07/01/efficient-storage-for-python/' rel='bookmark' title='Efficient storage for Python'>Efficient storage for Python</a></li>
<li><a href='http://www.xavierllora.net/2008/06/05/the-next-generation-of-data-bases/' rel='bookmark' title='The next generation of data bases'>The next generation of data bases</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Designing the distributed execution of a generic Meandre flow involves several moving pieces. One of those is the temporary storage required by the computing nodes (think of it as one node as one isolated component of a flow) to keep up with the data generated by a component, and also be able to replicate such storage to the node containing the consumer to be fed. Such storage, local to each node, must guarantee at least three basic properties.</p>
<ul>
<li>Transaction ready</li>
<li>Light weight implementation</li>
<li>Efficient write and read to minimize the contention on ports</li>
</ul>
<p>Also, it is important to keep in mind that in a distributed execution scenario, each node requires to have its one separated and standalone storage system. Thus, it is also important to minimize the overhead of installation and maintenance of such storage subsystem. There are several alternatives available ranging from traditional relational data base systems to home-brewed solutions. Relational data base systems provide a distributed, reliable, stable, and well tested environment, but they may tend to require a quite involved installation and maintenance. Also, tuning those systems to optimize performance may required quite an involved monitoring and tweaking. On the other hand, home-brewed solutions can be optimized for performance by dropping non required functionality and focussing on writing and reading performance. However, such solutions tend to be bug prone and tend to become time consuming, not to mention that proving transaction correctness can be quite involved.</p>
<p>Fortunately there is a middle ground where efficient and stable transaction aware solutions are available. They may not provide SQL interfaces, but they still provide transaction boundaries. Also, since they are oriented to maximize performance, they can provide better throughput and operation latency than having to traverse the SQL stack. Examples of such storage systems can be found under the areas of key-value stores and column stores. Several options were considered while writing these line, but key-value stores were the ones that better matches the three requirements described above. Several options were informally tested, including solutions like HDF and Berkely DB, however the best performing by far under similar stress test conditions as the sketched temporary storage subsystem was <a href="http://1978th.net/tokyocabinet/">Tokyo Cabinet</a>. I already <a href="/2008/06/05/the-next-generation-of-data-bases/">introduced and <a href="/2009/08/13/easy-reliable-and-flexible-storage-for-python/">tested</a> <a href="http://1978th.net/tokyocabinet/">Tokyo Cabinet</a> more than a year ago, but this time I was going to give it a stress test to basically convince myself that that was what I wanted to use for as temporary storage of the distributed flow execution.</p>
<h2>The experiment</h2>
<p>Tokyo cabinet is a collection of storage utilities including, among other facilities, key-value stores implemented as hash files or B-trees and flexible column stores. To illustrate the performance and throughput you can achieve. To implement multiple queues on a single casket (<a href="http://1978th.net/tokyocabinet/">Tokyo Cabinet</a> file containing the data store) B-trees with duplicated keys can help achieving such goal. The duplicated keys are the queue names, and the values are the <a href="http://en.wikipedia.org/wiki/Universally_Unique_Identifier">UUID</a>s of the objects being store. Objects are also stored in the same B-tree by using the <a href="http://en.wikipedia.org/wiki/Universally_Unique_Identifier">UIUD</a> as a key and the value become the payload to store (usually an array of bytes). </p>
<p>Previously, I have been heavily using Python bindings to test <a href="http://1978th.net/tokyocabinet/">Tokyo Cabinet</a>, but this time I went down the Java route (since the Meandre infrastructure is written on Java). The Java bindings are basically build around JNI and statically link to the C version of <a href="http://1978th.net/tokyocabinet/">Tokyo Cabinet</a> library, giving away the best of both world. To measure how fast can I write data out of a port into the local storage in a transactional mode, I used the following piece of code.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main <span style="color: #009900;">&#40;</span> <span style="color: #003399;">String</span> args <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">int</span> MAX <span style="color: #339933;">=</span> <span style="color: #cc66cc;">10000000</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">int</span> inc <span style="color: #339933;">=</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">int</span> cnt <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">float</span> fa <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #000066; font-weight: bold;">float</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">8</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">int</span> reps <span style="color: #339933;">=</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span> <span style="color: #000066; font-weight: bold;">int</span> i<span style="color: #339933;">=</span><span style="color: #cc66cc;">1</span> <span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;=</span>MAX <span style="color: #339933;">;</span> i<span style="color: #339933;">*=</span>inc  <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #666666; font-style: italic;">//System.out.println(&quot;Size: &quot;+i);</span>
			<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span> <span style="color: #000066; font-weight: bold;">int</span> j<span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span> <span style="color: #339933;">;</span> j<span style="color: #339933;">&lt;</span>reps <span style="color: #339933;">;</span> j<span style="color: #339933;">++</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>	
				<span style="color: #666666; font-style: italic;">//System.out.println(&quot;\tRepetition: &quot;+j);</span>
&nbsp;
				<span style="color: #666666; font-style: italic;">// open the database</span>
				BDB bdb <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> BDB<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
				<span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>bdb.<span style="color: #006633;">open</span><span style="color: #009900;">&#40;</span>TEST_CASKET_TCB, BDB.<span style="color: #006633;">OWRITER</span> <span style="color: #339933;">|</span> BDB.<span style="color: #006633;">OCREAT</span> <span style="color: #339933;">|</span> BDB.<span style="color: #006633;">OTSYNC</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
					<span style="color: #000066; font-weight: bold;">int</span> ecode <span style="color: #339933;">=</span> bdb.<span style="color: #006633;">ecode</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					fail<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;open error: &quot;</span> <span style="color: #339933;">+</span> bdb.<span style="color: #006633;">errmsg</span><span style="color: #009900;">&#40;</span>ecode<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
&nbsp;
				<span style="color: #666666; font-style: italic;">// Add a bunch of duplicates</span>
				<span style="color: #000066; font-weight: bold;">long</span> start <span style="color: #339933;">=</span> <span style="color: #003399;">System</span>.<span style="color: #006633;">currentTimeMillis</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				bdb.<span style="color: #006633;">tranbegin</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span> <span style="color: #000066; font-weight: bold;">int</span> k<span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> k<span style="color: #339933;">&lt;</span>i<span style="color: #339933;">;</span> k<span style="color: #339933;">++</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					<span style="color: #003399;">String</span> uuid <span style="color: #339933;">=</span> UUID.<span style="color: #006633;">randomUUID</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					bdb.<span style="color: #006633;">putdup</span><span style="color: #009900;">&#40;</span>QUEUE_KEY, uuid<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					bdb.<span style="color: #006633;">putdup</span><span style="color: #009900;">&#40;</span>uuid.<span style="color: #006633;">getBytes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, uuid.<span style="color: #006633;">getBytes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
				<span style="color: #009900;">&#125;</span>
				bdb.<span style="color: #006633;">trancommit</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				fa<span style="color: #009900;">&#91;</span>cnt<span style="color: #009900;">&#93;</span> <span style="color: #339933;">+=</span> <span style="color: #003399;">System</span>.<span style="color: #006633;">currentTimeMillis</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span>start<span style="color: #339933;">;</span>
&nbsp;
				<span style="color: #666666; font-style: italic;">// Clean up</span>
				bdb.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">File</span><span style="color: #009900;">&#40;</span>TEST_CASKET_TCB<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">delete</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			fa<span style="color: #009900;">&#91;</span>cnt<span style="color: #009900;">&#93;</span> <span style="color: #339933;">/=</span> reps<span style="color: #339933;">;</span>
			<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">+</span>i<span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>&quot;</span><span style="color: #339933;">+</span>fa<span style="color: #009900;">&#91;</span>cnt<span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>&quot;</span><span style="color: #339933;">+</span><span style="color: #009900;">&#40;</span>fa<span style="color: #009900;">&#91;</span>cnt<span style="color: #009900;">&#93;</span><span style="color: #339933;">/</span>i<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			cnt<span style="color: #339933;">++;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The idea is very simple. Just go and star storing 1, 10, 100, 1000, 10000, 1000000, and 10000000 pieces of data at once in a transaction. Measure the time. For each data number repeat the operation 10 times and average the time trying to palliate the fact that the experiment was run on a laptop running all sorts of other concurrent applications. Plot the results to illustrate:</p>
<ol>
<li>time required to insert one piece of data as a function of the number of data involve in the transaction</li>
<li>number of pieces of data wrote per second as a function of the number of data involve in the transaction</li>
</ol>
<p>The idea is to expose the behavior of <a href="http://1978th.net/tokyocabinet/">Tokyo Cabinet</a> as more data is involved in a transaction to check if degradation happens as the volume increase. This is an important issue, since data intensive flows can generate large volumes of data per firing event. </p>
<h2>The results</h2>
<p>Results are displayed on the figures below.</p>
<p><a href="http://www.xavierllora.net/wp-content/uploads/2009/09/tc_time.png"><img src="http://www.xavierllora.net/wp-content/uploads/2009/09/tc_time-400x400.png" alt="Time per data unit as a function of number of data involve in a transaction" title="Time per data unit as a function of number of data involve in a transaction" width="300" height="300" /></a><a href="http://www.xavierllora.net/wp-content/uploads/2009/09/tc_throughput.png"><img src="http://www.xavierllora.net/wp-content/uploads/2009/09/tc_throughput-400x400.png" alt="Throughput as a function of number of data in a transaction" title="Throughput as a function of number of data in a transaction" width="300" height="300" /></a></p>
<p>The first important element to highlight is that the time to insert one data element does not degrade as the volume increase. Actually, it is quite interesting that <a href="http://1978th.net/tokyocabinet/">Tokyo Cabinet</a> feels more comfortable as the volume per transaction grows. The throughput results are also interesting, since it shows that it is able to sustain transfers of around 40K data units per second, and that the only bottleneck is the disk cache management and bandwidth to the disk itself&#8212;which gets saturated after pushing more than 10K pieces of data.</p>
<h2>The lessons learned</h2>
<p><a href="http://1978th.net/tokyocabinet/">Tokyo Cabinet</a> is a excellent candidate to support the temporary transactional storage required in a distributed execution of a Meandre flow. Other alternatives like <a href="http://www.mysql.com/">MySQL</a>, embedded <a href="http://db.apache.org/derby/">Apache Derby</a>, the <a href="http://www.oracle.com/database/berkeley-db/je/index.html">Java edition of Berkeley DB</a>, <a href="http://www.zentus.com/sqlitejdbc/">SQLite JDBC</a> could not get even get close to such performance falling at least one order of magnitude behind.</p>
<p>Related posts:<ol>
<li><a href='http://www.xavierllora.net/2009/08/13/easy-reliable-and-flexible-storage-for-python/' rel='bookmark' title='Easy, reliable, and flexible storage for Python'>Easy, reliable, and flexible storage for Python</a></li>
<li><a href='http://www.xavierllora.net/2008/07/01/efficient-storage-for-python/' rel='bookmark' title='Efficient storage for Python'>Efficient storage for Python</a></li>
<li><a href='http://www.xavierllora.net/2008/06/05/the-next-generation-of-data-bases/' rel='bookmark' title='The next generation of data bases'>The next generation of data bases</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.xavierllora.net/2009/09/29/temporary-storage-for-meandres-distribute-flow-execution/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Efficient serialization for Java (and beyond)</title>
		<link>http://www.xavierllora.net/2009/02/04/efficient-serialization-for-java-and-beyond/</link>
		<comments>http://www.xavierllora.net/2009/02/04/efficient-serialization-for-java-and-beyond/#comments</comments>
		<pubDate>Wed, 04 Feb 2009 15:10:38 +0000</pubDate>
		<dc:creator>Xavier</dc:creator>
				<category><![CDATA[Data-Intensive Computing]]></category>
		<category><![CDATA[Research]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[data-intensive flows]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[meandre]]></category>
		<category><![CDATA[protocol buffers]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[serialization]]></category>
		<category><![CDATA[xstream]]></category>

		<guid isPermaLink="false">http://www.xavierllora.net/?p=431</guid>
		<description><![CDATA[I am currently working on the distributed execution of flows as part of the Meandre infrastructure&#8212;as a part of the SEASR project. One of the pieces to explore is how to push data between machines. No, I am not going to talk about network protocols and the like here, but how you can pass the [...]
Related posts:<ol>
<li><a href='http://www.xavierllora.net/2008/05/20/svnkit-or-analyzing-svn-content-in-java/' rel='bookmark' title='SVNKit or analyzing SVN content in Java'>SVNKit or analyzing SVN content in Java</a></li>
<li><a href='http://www.xavierllora.net/2009/09/29/temporary-storage-for-meandres-distribute-flow-execution/' rel='bookmark' title='Temporary storage for Meandre&#8217;s distributed flow execution'>Temporary storage for Meandre&#8217;s distributed flow execution</a></li>
<li><a href='http://www.xavierllora.net/2006/10/19/r-and-java/' rel='bookmark' title='R and Java'>R and Java</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>I am currently working on the distributed execution of flows as part of the <a href="http://seasr.org/meandre/">Meandre infrastructure</a>&#8212;as a part of the <a href="http://seasr.org">SEASR project</a>. One of the pieces to explore is how to push data between machines. No, I am not going to talk about network protocols and the like here, but how you can pass the data around. If you have ever programmed <a href="http://www-unix.mcs.anl.gov/mpi/">MPI</a> using C/C++ you remember the tedious efforts that requires passing complex data structures around between processes. Serialization is a way to take those complex structures into a form that can be easily stored/transmitted, and then retrieved/received and regenerate the original complex data structure. Some languages/platforms support this functionality (e.g. Java, Python), allowing to easily use the serialized representation for persistency or transmission purposes.</p>
<p>Last Thursday I was talking to <a href="http://vermaabhishekp.googlepages.com/">Abhishek Verma</a>, and he pointed out <a title="Protocol buffers" href="http://code.google.com/p/protobuf/">Google&#8217;s Protol Buffer</a> project&#8212;Google&#8217;s take data interchange formats. Not a new idea&#8212;for instance <a href="http://en.wikipedia.org/wiki/Interface_definition_language">Corba&#8217;s IDL</a> has been around for a long time&#8212;but what caught my eye was their claims about: (1) efficiency, and (2) multiple language bindings. I was contemplating using <a href="http://xstream.codehaus.org/">XStream</a> for Meandre distributed flow execution needs, but the XML heavy weight made me quite reluctant to walk down that path.  The Java native serialization is not a bad choice in terms of efficiency, but does not provide friendly mechanics for modifying data formats without rendering already serialized objects useless, neither a transparent mechanism to allow bindings for other languages/platforms. So the <a title="Protocol buffers" href="http://code.google.com/p/protobuf/">Google&#8217;s Protol Buffer</a> seemed an option worth trying. So there I went, and I prepare a simple comparison between the tree: (1) Java serialization, (2) <a title="Protocol buffers" href="http://code.google.com/p/protobuf/">Google&#8217;s Protol Buffer</a>, and (3) <a href="http://xstream.codehaus.org/">XStream</a>. Yes, you may guess the outcome, but I was more interested on getting my hands dirty, see how <a title="Protocol buffers" href="http://code.google.com/p/protobuf/">Google&#8217;s Protol Buffer</a> perform, and how much overhead for the developer it required.</p>
<h2>The experiment</h2>
<p>Before getting into the description, this experiment does not try to be an exhaustive performance evaluation, just an afternoon diversion. Having said so, the experiment measured the serialization/deserialization time and space used for a simple data structure containing just one array of integers and one array of strings. All the integers were initialized to zero, and the strings to <em>&#8220;Dummy text&#8221;</em>. To allow measuring the time required to serialize this simple object, the number of integers and strings were increased incrementally. The code below illustrates the implementation of the Java native serialization measures.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">org.meandre.tools.serialization.xstream</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> TargetObject <span style="color: #009900;">&#123;</span>
&nbsp;
       <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> sa<span style="color: #339933;">;</span>
       <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> ia<span style="color: #339933;">;</span>
&nbsp;
       <span style="color: #000000; font-weight: bold;">public</span> TargetObject <span style="color: #009900;">&#40;</span> <span style="color: #000066; font-weight: bold;">int</span> iStringElements, <span style="color: #000066; font-weight: bold;">int</span> iIntegerElements <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
             sa <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span>iStringElements<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
             <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span> <span style="color: #000066; font-weight: bold;">int</span> i<span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span> <span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span>iStringElements <span style="color: #339933;">;</span> i<span style="color: #339933;">++</span> <span style="color: #009900;">&#41;</span>
                  sa<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Dummy text&quot;</span><span style="color: #339933;">;</span>
             ia <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#91;</span>iIntegerElements<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
       <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The experiment consisted on generating objects like the above containing from 100 to 10,000 elements by increments of 100. Each object was serialized 50 times, measuring the average serialization time and the space required (in bytes) per object generated. Below you may have the sample code I used to measure native java serialization/deserialization times.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">org.meandre.tools.serialization.java</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.ByteArrayInputStream</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.ByteArrayOutputStream</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.IOException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.ObjectInputStream</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.ObjectOutputStream</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.junit.Test</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> JavaSerializationTest <span style="color: #009900;">&#123;</span>
&nbsp;
       @Test
       <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> testJavaSerialization <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> 
       <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span>
             <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">int</span> MAX_SIZE <span style="color: #339933;">=</span> <span style="color: #cc66cc;">10000</span><span style="color: #339933;">;</span>
             <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">int</span> REP <span style="color: #339933;">=</span> <span style="color: #cc66cc;">50</span><span style="color: #339933;">;</span>
             <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">int</span> INC <span style="color: #339933;">=</span> <span style="color: #cc66cc;">100</span><span style="color: #339933;">;</span>
&nbsp;
             <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Java serialization times&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
             <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span> <span style="color: #000066; font-weight: bold;">int</span> i<span style="color: #339933;">=</span>INC <span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;=</span>MAX_SIZE <span style="color: #339933;">;</span> i<span style="color: #339933;">+=</span>INC <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                  TargetObjectSerializable tos <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> TargetObjectSerializable<span style="color: #009900;">&#40;</span>i,i<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                  <span style="color: #000066; font-weight: bold;">long</span> lAccTime <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
                  <span style="color: #000066; font-weight: bold;">long</span> lSize <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
                  <span style="color: #000066; font-weight: bold;">long</span> lTmp<span style="color: #339933;">;</span>
                  <span style="color: #003399;">ByteArrayOutputStream</span> baos<span style="color: #339933;">;</span>
                  <span style="color: #003399;">ObjectOutputStream</span> out<span style="color: #339933;">;</span>
                  <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span> <span style="color: #000066; font-weight: bold;">int</span> j<span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span> <span style="color: #339933;">;</span> j<span style="color: #339933;">&lt;</span>REP <span style="color: #339933;">;</span> j<span style="color: #339933;">++</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                      baos <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">ByteArrayOutputStream</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                      out <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">ObjectOutputStream</span><span style="color: #009900;">&#40;</span>baos<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                      lTmp <span style="color: #339933;">=</span> <span style="color: #003399;">System</span>.<span style="color: #006633;">currentTimeMillis</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                      out.<span style="color: #006633;">writeObject</span><span style="color: #009900;">&#40;</span>tos<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                      lTmp <span style="color: #339933;">-=</span> <span style="color: #003399;">System</span>.<span style="color: #006633;">currentTimeMillis</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                      out.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                      lAccTime <span style="color: #339933;">-=</span> lTmp<span style="color: #339933;">;</span>
                      lSize <span style="color: #339933;">=</span> baos.<span style="color: #006633;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
                  <span style="color: #009900;">&#125;</span>
                  <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">+</span>i<span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>&quot;</span><span style="color: #339933;">+</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">double</span><span style="color: #009900;">&#41;</span>lAccTime<span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span>REP<span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>&quot;</span><span style="color: #339933;">+</span>lSize<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
             <span style="color: #009900;">&#125;</span>
       <span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
       @Test
       <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> testJavaDeserialization <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> 
       <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span>, <span style="color: #003399;">ClassNotFoundException</span> <span style="color: #009900;">&#123;</span>
             <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">int</span> MAX_SIZE <span style="color: #339933;">=</span> <span style="color: #cc66cc;">10000</span><span style="color: #339933;">;</span>
             <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">int</span> REP <span style="color: #339933;">=</span> <span style="color: #cc66cc;">50</span><span style="color: #339933;">;</span>
             <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">int</span> INC <span style="color: #339933;">=</span> <span style="color: #cc66cc;">100</span><span style="color: #339933;">;</span>
&nbsp;
             <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Java deserialization times&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
             <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span> <span style="color: #000066; font-weight: bold;">int</span> i<span style="color: #339933;">=</span>INC <span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;=</span>MAX_SIZE <span style="color: #339933;">;</span> i<span style="color: #339933;">+=</span>INC <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                  TargetObjectSerializable tos <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> TargetObjectSerializable<span style="color: #009900;">&#40;</span>i,i<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                  <span style="color: #003399;">ByteArrayOutputStream</span> baos <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">ByteArrayOutputStream</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                  <span style="color: #003399;">ObjectOutputStream</span> out <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">ObjectOutputStream</span><span style="color: #009900;">&#40;</span>baos<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                  out.<span style="color: #006633;">writeObject</span><span style="color: #009900;">&#40;</span>tos<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                  out.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                  <span style="color: #003399;">ByteArrayInputStream</span> bais<span style="color: #339933;">;</span>
                  <span style="color: #003399;">ObjectInputStream</span> ois<span style="color: #339933;">;</span>
                  <span style="color: #000066; font-weight: bold;">long</span> lAccTime <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
                  <span style="color: #000066; font-weight: bold;">long</span> lTmp<span style="color: #339933;">;</span>
                  <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span> <span style="color: #000066; font-weight: bold;">int</span> j<span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span> <span style="color: #339933;">;</span> j<span style="color: #339933;">&lt;</span>REP <span style="color: #339933;">;</span> j<span style="color: #339933;">++</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                      bais <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">ByteArrayInputStream</span><span style="color: #009900;">&#40;</span>baos.<span style="color: #006633;">toByteArray</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                      ois <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">ObjectInputStream</span><span style="color: #009900;">&#40;</span>bais<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                      lTmp <span style="color: #339933;">=</span> <span style="color: #003399;">System</span>.<span style="color: #006633;">currentTimeMillis</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                      ois.<span style="color: #006633;">readObject</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                      lTmp <span style="color: #339933;">-=</span> <span style="color: #003399;">System</span>.<span style="color: #006633;">currentTimeMillis</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                      lAccTime <span style="color: #339933;">-=</span> lTmp<span style="color: #339933;">;</span>
                  <span style="color: #009900;">&#125;</span>
                  <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">+</span>i<span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>&quot;</span><span style="color: #339933;">+</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">double</span><span style="color: #009900;">&#41;</span>lAccTime<span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span>REP<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
             <span style="color: #009900;">&#125;</span>
       <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Equivalent versions of the code shown above were used to measure <a title="Protocol buffers" href="http://code.google.com/p/protobuf/">Google&#8217;s Protol Buffer</a> and <a href="http://xstream.codehaus.org/">XStream</a>. If you are interested on seeing the <a href="http://www.xavierllora.net/wp-content/uploads/2009/02/src-test-serialization.zip">full code you can download it as it is</a>&#8212;no guarantees provided. Also, for completion of the experiment code, you can find below the <code>proto</code> file use for testing the Java implementation of <a title="Protocol buffers" href="http://code.google.com/p/protobuf/">Google&#8217;s Protol Buffer</a>.</p>

<div class="wp_syntax"><div class="code"><pre class="proto" style="font-family:monospace;">package test;
&nbsp;
option java_package = &quot;org.meandre.tools.serialization.proto&quot;;
option java_outer_classname = &quot;TargetObjectProtoOuter&quot;;
&nbsp;
message TargetObjectProto { 
  repeated int32 ia = 1; 
  repeated string sa = 2;
}</pre></div></div>

<p>In order to run the experiment, besides <a title="Protocol buffers" href="http://code.google.com/p/protobuf/">Google&#8217;s Protol Buffer</a> and  <a href="http://xstream.codehaus.org/">XStream</a> libraries, you will also need <a href="http://www.junit.org/" title="JUnit">JUnit</a>.</p>
<h2>The results</h2>
<p>The experiments were run on an first generation MacBook Pro using Apple&#8217;s Java 1.5 virtual machine with 2Gb of RAM. The figure below illustrated the different memory requirements for each of the the three serialization methods compared. Figures and data processing was done using <a href="http://www.r-project.org/" title="R">R</a>.</p>
<p><a href="http://www.xavierllora.net/wp-content/uploads/2009/02/data-size.png"><img src="http://www.xavierllora.net/wp-content/uploads/2009/02/data-size.png" alt="Data size of the serialized object" title="Data size of the serialized object" width="220" height="220" class="aligncenter size-full wp-image-425" /></a><a href="http://www.xavierllora.net/wp-content/uploads/2009/02/data-size-ratio.png"><img src="http://www.xavierllora.net/wp-content/uploads/2009/02/data-size-ratio.png" alt="Serialized/original data size ratio" title="Serialized/original data size ratio" width="220" height="220" class="aligncenter size-full wp-image-424" /></a></p>
<p>Figures show the already intuited bloated size of XML-based XStream serialization, up to 6 time larger than the original data being serialized. On the other hand, the Java native serialization provides a minimal increase on the serialized equivalent. Google&#8217;s Protocol Buffer presents a slightly larger requirement than the native Java serialization, but never doubled the original size. Moreover, it does not exhibit the constant initial payload overhead displayed by both XStream and the Java native serialization. The next question was how costly was the serialization process. Figures below show the amount of time required to serialize an object.</p>
<p><a href="http://www.xavierllora.net/wp-content/uploads/2009/02/serialization-time.png"><img src="http://www.xavierllora.net/wp-content/uploads/2009/02/serialization-time.png" alt="Serialization time" title="Serialization time" width="220" height="220" class="aligncenter size-full wp-image-430" /></a><a href="http://www.xavierllora.net/wp-content/uploads/2009/02/serialization-time-ratio.png"><img src="http://www.xavierllora.net/wp-content/uploads/2009/02/serialization-time-ratio.png" alt="Serialization time ratio" title="Serialization time ratio" width="220" height="220" class="aligncenter size-full wp-image-429" /></a></p>
<p>The Java native serialization was, as expected the fastest, however Google&#8217;s Protocol Buffer took only, on average, four times the more time than the Java native version. However, that is peanuts when compared to the fifty times slower XStream version. Deserialization times of the encoded object presents the same trends as the serialization, as the figures below show.</p>
<p><a href="http://www.xavierllora.net/wp-content/uploads/2009/02/deserialization-time.png"><img src="http://www.xavierllora.net/wp-content/uploads/2009/02/deserialization-time.png" alt="Deserialization time" title="Deserialization time" width="220" height="220" class="aligncenter size-full wp-image-427" /></a><a href="http://www.xavierllora.net/wp-content/uploads/2009/02/deserialization-time-ratio.png"><img src="http://www.xavierllora.net/wp-content/uploads/2009/02/deserialization-time-ratio.png" alt="Deserialization time ratio" title="Deserialization time ratio" width="220" height="220" class="aligncenter size-full wp-image-426" /></a></p>
<p>It is also interesting to note that serialization&#8212;as the figures below show&#8212;is faster than deserialization (as common sense would have suggested). However, it is interesting to note that Google&#8217;s Protocol Buffer is the method where these difference is more pronounced.</p>
<p><a href="http://www.xavierllora.net/wp-content/uploads/2009/02/serialization-deserialization-ratio.png"><img src="http://www.xavierllora.net/wp-content/uploads/2009/02/serialization-deserialization-ratio.png" alt="Serialization/deserialization ratio" title="Serialization/deserialization ratio" width="220" height="220" class="aligncenter size-full wp-image-428" /></a></p>
<h2>The lessons learned</h2>
<p>As I said, this is far from being an exhaustive or even representative example, but just one afternoon exploration. However, the results show interesting trends. Yes, XStream could also be tweaked to make the searialized XML leaner, and even would&#8212;with the proper tinkering&#8212;make possible deserialize the object on a different platform/language, but at an enormous cost&#8212;both in size and time. The Java native serialization is by far the fastest and the most size efficient, but is made from and for Java. Also, changes on the serialized classes&#8212;imagine wanting to add or remove a field&#8212;may render the serialize objects unreadable. Google Protocol Buffers on the other hand delivers the best of both scenarios: (1) the ability to serialize/deserialize objects in a compact and relatively fast manner, and (2) allows the serialization/deserialization to happen between different languages and platforms. For these reasons, it seems to be a very interesting option to keep exploring, if you need both.</p>
<p>Related posts:<ol>
<li><a href='http://www.xavierllora.net/2008/05/20/svnkit-or-analyzing-svn-content-in-java/' rel='bookmark' title='SVNKit or analyzing SVN content in Java'>SVNKit or analyzing SVN content in Java</a></li>
<li><a href='http://www.xavierllora.net/2009/09/29/temporary-storage-for-meandres-distribute-flow-execution/' rel='bookmark' title='Temporary storage for Meandre&#8217;s distributed flow execution'>Temporary storage for Meandre&#8217;s distributed flow execution</a></li>
<li><a href='http://www.xavierllora.net/2006/10/19/r-and-java/' rel='bookmark' title='R and Java'>R and Java</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.xavierllora.net/2009/02/04/efficient-serialization-for-java-and-beyond/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>SVNKit or analyzing SVN content in Java</title>
		<link>http://www.xavierllora.net/2008/05/20/svnkit-or-analyzing-svn-content-in-java/</link>
		<comments>http://www.xavierllora.net/2008/05/20/svnkit-or-analyzing-svn-content-in-java/#comments</comments>
		<pubDate>Tue, 20 May 2008 14:47:52 +0000</pubDate>
		<dc:creator>Xavier</dc:creator>
				<category><![CDATA[Notes]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[data processing]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[svn]]></category>

		<guid isPermaLink="false">http://www.xavierllora.net/?p=220</guid>
		<description><![CDATA[The other day I was looking for a piece of software that could help me pull data out of SVN repository so I can do a little analysis on it. Browsing over the net, I run into several tools, but the one that finally caught my eye was SNVKit. The package does a lot of [...]
Related posts:<ol>
<li><a href='http://www.xavierllora.net/2009/02/04/efficient-serialization-for-java-and-beyond/' rel='bookmark' title='Efficient serialization for Java (and beyond)'>Efficient serialization for Java (and beyond)</a></li>
<li><a href='http://www.xavierllora.net/2007/04/14/visualizing-content-from-metadata-stores/' rel='bookmark' title='Visualizing content from metadata stores'>Visualizing content from metadata stores</a></li>
<li><a href='http://www.xavierllora.net/2006/07/07/analyzing-active-interactive-genetic-algorithms-using-visual-analytics/' rel='bookmark' title='Analyzing active interactive genetic algorithms using visual analytics'>Analyzing active interactive genetic algorithms using visual analytics</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>The other day I was looking for a piece of software that could help me pull data out of SVN repository so I can do a little analysis on it. Browsing over the net, I run into several tools, but the one that finally caught my eye was <a title="SVNKit" href="http://svnkit.com/">SNVKit</a>. The package does a lot of stuff, but for instance, if you are only interested on pulling information out, it makes your like quite easy. The code below is just a simple example of how you can use it to pull information out of a SVN repository.</p>
<pre class="brush: java">
import java.util.LinkedList;

import org.tmatesoft.svn.core.ISVNDirEntryHandler;
import org.tmatesoft.svn.core.SVNDirEntry;
import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.SVNURL;
import org.tmatesoft.svn.core.internal.io.svn.SVNRepositoryFactoryImpl;
import org.tmatesoft.svn.core.internal.wc.admin.SVNEntry;
import org.tmatesoft.svn.core.wc.SVNClientManager;
import org.tmatesoft.svn.core.wc.SVNLogClient;
import org.tmatesoft.svn.core.wc.SVNRevision;
import org.tmatesoft.svn.core.SVNNodeKind;

public class SVNReader {

    public static void main ( String [] sArgs ) throws SVNException {
          final LinkedList&lt;SVNDirEntry&gt; lstFiles = new LinkedList&lt;SVNDirEntry&gt;();

          SVNRepositoryFactoryImpl.setup();

          SVNClientManager clientManager = SVNClientManager.newInstance();

          SVNLogClient lc = clientManager.getLogClient();
          SVNURL svnUrl = SVNURL.parseURIDecoded(
                    &quot;svn://some.server.com:3690/path/to/trunk&quot;
                    );
          lc.doList(svnUrl, SVNRevision.HEAD,  SVNRevision.HEAD, false, true, new ISVNDirEntryHandler() {
                    public void handleDirEntry(SVNDirEntry svnEntry) throws SVNException {
                              if ( svnEntry.getKind()==SVNNodeKind.FILE) {
                                        lstFiles.add(svnEntry);
                              }
                    }
          });

          for ( SVNDirEntry svnEntry:lstFiles ) {
                    System.out.println(svnEntry);
          }
      }
}
</pre>
<p> </p>
<p>Related posts:<ol>
<li><a href='http://www.xavierllora.net/2009/02/04/efficient-serialization-for-java-and-beyond/' rel='bookmark' title='Efficient serialization for Java (and beyond)'>Efficient serialization for Java (and beyond)</a></li>
<li><a href='http://www.xavierllora.net/2007/04/14/visualizing-content-from-metadata-stores/' rel='bookmark' title='Visualizing content from metadata stores'>Visualizing content from metadata stores</a></li>
<li><a href='http://www.xavierllora.net/2006/07/07/analyzing-active-interactive-genetic-algorithms-using-visual-analytics/' rel='bookmark' title='Analyzing active interactive genetic algorithms using visual analytics'>Analyzing active interactive genetic algorithms using visual analytics</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.xavierllora.net/2008/05/20/svnkit-or-analyzing-svn-content-in-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

