<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Enjoying Rails &#187; jruby glassfish rails benchmarks</title>
	<atom:link href="http://blog.erichsen.net/tag/jruby-glassfish-rails-benchmarks/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.erichsen.net</link>
	<description>I really do...</description>
	<lastBuildDate>Tue, 01 Sep 2009 07:53:42 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='blog.erichsen.net' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/341b476daf96d74224be7d0677b91401?s=96&#038;d=http://s2.wp.com/i/buttonw-com.png</url>
		<title>Enjoying Rails &#187; jruby glassfish rails benchmarks</title>
		<link>http://blog.erichsen.net</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://blog.erichsen.net/osd.xml" title="Enjoying Rails" />
	<atom:link rel='hub' href='http://blog.erichsen.net/?pushpress=hub'/>
		<item>
		<title>Benchmarking fun with JRuby 1.1 RC2, glassfish, and Rails 2.0.2</title>
		<link>http://blog.erichsen.net/2008/02/17/benchmarking-fun-with-jruby-11-rc2-glassfish-and-rails-202/</link>
		<comments>http://blog.erichsen.net/2008/02/17/benchmarking-fun-with-jruby-11-rc2-glassfish-and-rails-202/#comments</comments>
		<pubDate>Sun, 17 Feb 2008 14:19:35 +0000</pubDate>
		<dc:creator>enjoyingrails</dc:creator>
				<category><![CDATA[rails]]></category>
		<category><![CDATA[jruby glassfish rails benchmarks]]></category>

		<guid isPermaLink="false">http://blog.erichsen.net/2008/02/17/benchmarking-fun-with-jruby-11-rc2-glassfish-and-rails-202/</guid>
		<description><![CDATA[Yesterday JRuby 1.1 RC2 was released and two days ago the glassfish gem v 0.1.1 was released. Lots of interesting stuff happening in JRuby land!
I decided to take JRuby and the glassfish gem for a spin with a simple Rails application.
Installing JRuby
First step was to download and install JRuby. This is pretty straightforward:
cd /tmp
wget http://dist.codehaus.org/jruby/jruby-src-1.1RC2.tar.gz
tar [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.erichsen.net&blog=1936559&post=8&subd=enjoyingrails&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>Yesterday <a href="http://www.bloglines.com/blog/ThomasEEnebo?id=42">JRuby 1.1 RC2</a> was released and two days ago the <a href="http://weblogs.java.net/blog/arungupta/archive/2008/02/glassfish_v3_ge_1.html">glassfish gem v 0.1.1</a> was released. Lots of interesting stuff happening in JRuby land!</p>
<p>I decided to take JRuby and the glassfish gem for a spin with a simple Rails application.<br />
<b>Installing JRuby</b></p>
<p>First step was to download and install JRuby. This is pretty straightforward:<br />
<code>cd /tmp<br />
wget http://dist.codehaus.org/jruby/jruby-src-1.1RC2.tar.gz<br />
tar xvzf jruby-src-1.1RC2.tar.gz<br />
cd jruby-1.1RC2/<br />
ant<br />
export JRUBY_HOME=`pwd`<br />
export PATH=$JRUBY_HOME/bin:$PATH<br />
jruby --version<br />
ruby 1.8.6 (2008-02-17 rev 5944) [i386-jruby1.1RC2]</code><br />
Yep, seems to work.</p>
<p><b>Installing gems</b></p>
<p>Next step was to install the Rails and glassfish gems:<br />
<code>unset GEM_HOME<br />
unset GEM_PATH<br />
gem install rails<br />
gem install glassfish</code></p>
<p><b>Creating a Rails application</b></p>
<p>On to the Rails application&#8230; I used scaffold to have a simple application up and running quickly:<br />
<code>cd ..<br />
rails glassfishtest --database=mysql<br />
cd glassfishtest/<br />
export RAILS_ENV=production<br />
rake db:sessions:create<br />
script/generate scaffold Book title:string<br />
rake db:create<br />
rake db:migrate<br />
script/runner "Book.create(:title =&gt; 'JRuby Rocks')"</code></p>
<p>I use the database session store, so I added this line to the <code>config/environment.rb</code> file<br />
<code>config.action_controller.session_store = :active_record_store</code></p>
<p><b>Firing up glassfish</b></p>
<p>Let&#8217;s fire up the glassfish server:<br />
<code>cd ..<br />
glassfish_rails glassfishtest -n 2</code><br />
The <code>-n 2</code> option will make glassfish start 2 Rails instances.</p>
<p><b>Benchmark fun!</b></p>
<p><i><b></b>Glassfish</i><br />
I used the <code>ab</code> command to perform some simple benchmarks.<br />
Each <code>ab</code> command was run twice with a freshly started glassfish server. The first run warms up the JIT in the JVM. The results listed below are for the second run (and the fifth run for some). All benchmarks were performed on my 2.33GHz MacBook Pro running Leopard 10.5.2 with Java version 1.5.0_13-b05-237.</p>
<p>The performance with respect to static files is impressive:<br />
<code>ab -n 5000 -c 10 http://localhost:3000/<br />
Requests per second:    2705.63 [#/sec] (mean)</code></p>
<p>Now onto a page created by Rails:<br />
<code>ab -n 1000 -c 8 http://localhost:3000/books/1<br />
Requests per second:    54.10 [#/sec] (mean)</code></p>
<p>JRuby can be tweaked a little bit with the <code>-server</code> parameter:<br />
<code>JAVA_OPTS="-server" glassfish_rails glassfishtest -n 2<br />
ab -n 1000 -c 8 http://localhost:3000/books/1<br />
Requests per second:    53.82 [#/sec] (mean) 2nd run<br />
Requests per second:    63.06 [#/sec] (mean) 5th run<br />
</code><br />
After a little warmup the performance is approximately 20% better than without the <code>-server</code> option.</p>
<p>Let&#8217;s try adding more Rails instances:<br />
<code>JAVA_OPTS="-server" glassfish_rails glassfishtest -n 4<br />
Requests per second:    50.71 [#/sec] (mean) 2nd run<br />
Requests per second:    60.69 [#/sec] (mean) 5th run</code><br />
On my dual core machine this actually degrades performance a little bit. I guess it is a good idea to have the number of Rails instances match the number of cores in your server.</p>
<p>But what about one Rails instance:<br />
<code>JAVA_OPTS="-server" glassfish_rails glassfishtest -n 1<br />
Requests per second:    31.56 [#/sec] (mean) 2nd run<br />
Requests per second:    34.48 [#/sec] (mean) 5th run</code><br />
That hurts!</p>
<p><i>Mongrel</i></p>
<p>How does mongrel compare to glassfish?<br />
Single Mongrel &#8211; JRuby<br />
<code>JAVA_OPTS='-server' jruby script/server -e production<br />
Requests per second:    54.99 [#/sec] (mean) 2nd run<br />
Requests per second:    63.20 [#/sec] (mean) 5th run</code></p>
<p>Two Mongrels behind pen &#8211; JRuby<br />
<code>Requests per second:    58.39 [#/sec] 2nd run(mean)<br />
Requests per second:    69.16 [#/sec] (mean) 10th run</code></p>
<p>Static files:<br />
<code>Requests per second:    313.57 [#/sec] (mean)</code></p>
<p>Mongrel and the glassfish server have comparable performance with respect to Rails generated pages.<br />
With respect to serving static files, glassfish outperforms Mongrel significantly. That said, you shouldn&#8217;t really let Mongrel serve static content &#8211; it is better to leave that to nginx or Apache.</p>
<p><i>Mongrel &#8211; MRI</i></p>
<p>What is the performance when using MRI?<br />
Single Mongrel &#8211; MRI<br />
<code>Requests per second:    120.79 [#/sec] (mean)</code></p>
<p>Two Mongrels behind pen &#8211; MRI<br />
<code>Requests per second:    123.42 [#/sec] (mean)</code></p>
<p>The MRI Mongrel seems to have a lot better performance for this (admittedly simple) benchmark.</p>
<p><b>Conclusion</b></p>
<p>With respect to ease of running a server the JRuby/glassfish combo is very appealing:</p>
<ul>
<li>static files are served very fast</li>
<li>no need for a separate load balancer</li>
<li>the whole thing is started with just one command</li>
</ul>
<p>For this particular Rails application benchmark, the performance of the JRuby stack is only half of the performance of MRI, which is kind of sad. I am pretty sure that this is not the case for all Rails applications. In fact, evidence from Mingle seems to indicate that JRuby is faster than MRI. So I guess the best thing is to try it out on your own Rails app &#8211; and please blog about your findings. If you decide to benchmark your own Rails app I highly recommend <a href="http://peepcode.com/products/benchmarking-with-httperf">this peepcode screencast</a> about benchmarking.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/enjoyingrails.wordpress.com/8/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/enjoyingrails.wordpress.com/8/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/enjoyingrails.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/enjoyingrails.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/enjoyingrails.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/enjoyingrails.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/enjoyingrails.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/enjoyingrails.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/enjoyingrails.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/enjoyingrails.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/enjoyingrails.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/enjoyingrails.wordpress.com/8/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.erichsen.net&blog=1936559&post=8&subd=enjoyingrails&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://blog.erichsen.net/2008/02/17/benchmarking-fun-with-jruby-11-rc2-glassfish-and-rails-202/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2047f0076ea63c7d1a35373bac6f9841?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">enjoyingrails</media:title>
		</media:content>
	</item>
	</channel>
</rss>