<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-112442907292338613</id><updated>2011-09-08T06:32:43.725-07:00</updated><title type='text'>kasou.sk</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://blog.kasou.sk/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/112442907292338613/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://blog.kasou.sk/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>kasou</name><uri>http://www.blogger.com/profile/05928340319416629796</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://kasou.sk/xichtik-mini.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>1</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-112442907292338613.post-8461448927623869581</id><published>2007-01-19T08:52:00.000-08:00</published><updated>2007-01-22T14:04:14.298-08:00</updated><title type='text'>JRuby JDBC performance</title><content type='html'>I'm writing server-side application (webchat) which communicates with DB.&lt;br/&gt; I wanted to use JRuby as the main implementation language, just rewrite som parts in pure java.&lt;br/&gt;So I intended to use with ActiveRecord-JDBC. I used H2 database in embedded mode.&lt;br/&gt;&lt;br/&gt;My test simulates retrieving of last 10 rows in small table 1000 times in sequence.&lt;br/&gt;Every row is converted to set of custom classes which implent interfaces of business objects: ChatMessage containing MessageID, Sender, Recipient, MessageText,Timestamp, etc... &lt;br/&gt;There is previous java implementation of these interfaces, previous to decision of choosing JRuby.&lt;br/&gt;&lt;br/&gt; As I sad first prototype used ActiveRecord. Every record was converted to set of java data classes. I used JRuby 0.9.2 and  it took 3o seconds to run the test.&lt;br/&gt;After upgrade to trunk version from 2007-01-07 test sped up to 23 seconds.&lt;br/&gt;Great improvement, but still  it wasn't fast enough.&lt;br/&gt;And after evaluation of pure Java performance it was really incredibly slow. Pure looping through JDBC ResultSet in Java took less than a second.&lt;br/&gt;On the other side, when I increased number of iterations 10x, AR took &lt;strong&gt;~700 seconds&lt;/strong&gt;. You see,  it's not linear. Java didn't have this problem: 5.5 seconds.&lt;br/&gt;I have switched to trunk version with first JIT compiler on Friday, and it really helps - just 210 seconds instead of 700. Still it consumes too much memory, but finally with usual linear behaviour (21 seconds for 1000 iterations).&lt;br/&gt;&lt;br/&gt;So I decided to try some hybrid implementations. These were performed with 2 weeks old trunk version as this is the fastest for me ATM. &lt;br/&gt;&lt;ul&gt;&lt;li&gt;Ruby code calling raw JDBC interface with existing Java data classes: 114 seconds.&lt;br/&gt;&lt;/li&gt;&lt;li&gt; The same ruby code but with new Ruby data classes (fresh implementations of same Java interfaces): 62 seconds.&lt;/li&gt;&lt;li&gt;Pure ruby code without any Java objects, assigning just to flat Hash: 40 seconds.&lt;br/&gt;&lt;/li&gt;&lt;li&gt;Experimental replacement of direct JDBC calls with Java class wrapping DB row in Object[], multiple assigment to local variables: 40 seconds.&lt;/li&gt;&lt;li&gt;Same replacement returning HashMap instead of Object[]: 80 seconds.&lt;/li&gt;&lt;/ul&gt;Quite various results, aren't they? I'm not sure, what is the brake here.&lt;br/&gt;I thought it could be because of converting from Ruby to Java and back, but I'm not sure yet. I tried keeping instances of Java objects in Hash not to construct them everytime, but it doesn't help a lot, just few seconds.&lt;br/&gt;&lt;br/&gt;What to do next? I will try some metaprogramming hacks and mix ruby code generation with more universal Java wrappers to achieve good performance and configurability at the same time.&lt;br/&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/112442907292338613-8461448927623869581?l=blog.kasou.sk' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blog.kasou.sk/feeds/8461448927623869581/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=112442907292338613&amp;postID=8461448927623869581' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/112442907292338613/posts/default/8461448927623869581'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/112442907292338613/posts/default/8461448927623869581'/><link rel='alternate' type='text/html' href='http://blog.kasou.sk/2007/01/jruby-jdbc-performance.html' title='JRuby JDBC performance'/><author><name>kasou</name><uri>http://www.blogger.com/profile/05928340319416629796</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://kasou.sk/xichtik-mini.jpg'/></author><thr:total>2</thr:total></entry></feed>
