<?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>Letsgetdugg&#187; benchmark</title>
	<atom:link href="http://letsgetdugg.com/category/benchmark/feed/" rel="self" type="application/rss+xml" />
	<link>http://letsgetdugg.com</link>
	<description>Random tech jargon</description>
	<lastBuildDate>Fri, 21 Jan 2011 19:31:31 +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>Nginx Passenger vs JRuby on Jetty</title>
		<link>http://letsgetdugg.com/2009/08/31/nginx-passenger-vs-jruby-on-jetty/</link>
		<comments>http://letsgetdugg.com/2009/08/31/nginx-passenger-vs-jruby-on-jetty/#comments</comments>
		<pubDate>Mon, 31 Aug 2009 21:16:39 +0000</pubDate>
		<dc:creator>victori</dc:creator>
				<category><![CDATA[administration]]></category>
		<category><![CDATA[benchmark]]></category>
		<category><![CDATA[jruby]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://letsgetdugg.com/?p=322</guid>
		<description><![CDATA[I am in the process of evaluating which option to choose for a new production deployment of a Sinatra application. Pros and Cons of the implementations: JRuby Stack: Pros: • Fast for serial execution once warmed up. • Multi-threaded, easy to scale with spiked traffic / shared resources. Cons: • Slow warm up time, app [...]]]></description>
			<content:encoded><![CDATA[<p>I am in the process of evaluating which option to choose for a new production deployment of a <a href="http://www.sinatrarb.com/">Sinatra</a> application. </p>
<div style="text-align:center;">
<img src="http://letsgetdugg.com/wp-content/uploads/2010/07/jrubyvsruby.jpg" alt="jruby vs ruby" />
</div>
<p><strong>Pros and Cons of the implementations:</strong></p>
<p><strong>JRuby Stack:</strong></p>
<p><strong>Pros:</strong></p>
<div class="codesnip-container" >• Fast for serial execution once warmed up.<br />
• Multi-threaded, easy to scale with spiked traffic / shared resources.</div>
<p><strong>Cons:</strong></p>
<div class="codesnip-container" >• Slow warm up time, app restarts can really hurt.<br />
• Single process is a single point of failure.</div>
<p><strong>MRI Ruby Stack:</strong></p>
<p><strong>Pros:</strong></p>
<div class="codesnip-container" >• Starts off fast, with no warmup time.<br />
• Scaled via processes, no single point of failure.</div>
<p><strong>Cons:</strong></p>
<div class="codesnip-container" >• Slower than JRuby in serial execution.<br />
• Single Process, no shared resources (Possibly using more memory over time).</div>
<hr/>
 </p>
<p>These tests are run against a real-world application that is soon to be released, not some dummy &#8220;hello world&#8221; application. </p>
<p><strong>Application Background:</strong></p>
<p>Sinatra / HAML templates (not compiled, rendered per request) / CouchDB / R18N Translation</p>
<p><strong>Server Specifications:</strong></p>
<div class="codesnip-container" >OS: OpenSolaris &#8211; SNV98<br />
Hardware: 8Gig / Quad Core Xeon x5355 </p>
<p>MRI Stack:<br />
Ruby 1.8.7 (2008-08-11 patchlevel 72)<br />
Nginx Passenger 2.2.4<br />
Passenger Config: passenger_max_pool_size 8, passenger_use_global_queue on</p>
<p>Java Stack:<br />
JRuby 1.3.1 (ruby 1.8.6p287) (2009-06-15 6586)<br />
Jetty-6.1.15<br />
JDK Flags: -server -Xverify:none -XX:MaxPermSize=96m -XX:+AggressiveOpts -Xss128k -Xms256m -Xmx384m -XX:+UseParallelGC -XX:+UseParallelOldGC<br />
JDK 1.7.0 b67</p></div>
<p>Here are the results. I have taken the best time out of 10 runs, giving enough time for the JDK to warmup and passenger to load all the children. The results are clipped for brevity. </p>
<p><strong>Benchmark command:</strong></p>
<div class="codesnip-container" >ab -n1000 -c10 http://service/</div>
<p><strong>JRuby Results:</strong></p>
<div class="codesnip-container" >Requests per second:    85.97 [#/sec] (mean)<br />
Time per request:       116.316 [ms] (mean)<br />
Time taken for tests:   11.632 seconds<br />
Memory Use After Test:  437M (RSS)</div>
<p><strong>MRI Results:</strong></p>
<div class="codesnip-container" >Requests per second:    118.85 [#/sec] (mean)<br />
Time per request:       84.142 [ms] (mean)<br />
Time taken for tests:   8.414 seconds<br />
Memory Use After Test:  264M (RSS)</div>
<p><strong>Conclusions and final thoughts:</strong> </p>
<p>Seems like MRI Ruby has a <strong>39%</strong> performance advantage on JRuby executing my application. I am still a bit skeptical if MRI Ruby would still win out in production when it turns into a long running process marathon with varied traffic patterns. At the end of the day the JVM currently has the edge in garbage collection on MRI Ruby, so in &#8220;theory&#8221; JRuby should be the better choice. This is all a hypothetical <em>guesstimate[sic]</em> on my behalf. I will most likely end up trying both variants in production and see which works best. </p>
]]></content:encoded>
			<wfw:commentRss>http://letsgetdugg.com/2009/08/31/nginx-passenger-vs-jruby-on-jetty/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Catalyst vs Rails Round Two</title>
		<link>http://letsgetdugg.com/2009/04/30/catalyst-vs-rails-round-two/</link>
		<comments>http://letsgetdugg.com/2009/04/30/catalyst-vs-rails-round-two/#comments</comments>
		<pubDate>Thu, 30 Apr 2009 20:23:34 +0000</pubDate>
		<dc:creator>victori</dc:creator>
				<category><![CDATA[administration]]></category>
		<category><![CDATA[benchmark]]></category>
		<category><![CDATA[catalyst]]></category>
		<category><![CDATA[jruby]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://letsgetdugg.com/?p=156</guid>
		<description><![CDATA[There seems to be some interest Catalyst vs Rails vs Django benchmark. The older benchmark is quite old, it was done in 2007. A lot has changed since then. I am re-running the numbers once again to see what has changed. This time around the hardware is faster and the benchmark is slightly more simple. [...]]]></description>
			<content:encoded><![CDATA[<p>There seems to be <a href="http://letsgetdugg.com/2009/04/19/catalyst-vs-rails-vs-django-cook-off/">some interest Catalyst vs Rails vs Django  benchmark</a>. The older benchmark is quite old, it was done in 2007. A lot has changed since then. I am re-running the numbers once again to see what has changed. This time around the hardware is faster and the benchmark is slightly more simple. I am just stress testing the controller response performance of the two frameworks. </p>
<p><b>Benchmark System:</b><br />
Quad Core Xeon x5355 @ 2.66GHz,8 Gigs Ram,OpenSolaris SNV98</p>
<p><b>Quick Summary:</b><br />
Catalyst 5.8/Perl 5.10: 611.78req/sec (Single Process,bsdmalloc)<br />
Catalyst 5.8/Perl 5.10: 1485.53req/sec (Multi Process,bsdmalloc)<br />
Rails 2.3.2/MRI Ruby 1.8.7: 259.93req/sec (Single Process,bsdmalloc)<br />
Rails 2.3.2/JRuby 1.3-dev: 311.71req/sec  (Single-Threaded,bsdmalloc)<br />
Rails 2.3.2/JRuby 1.3-dev: 992.32req/sec (Multi-Threaded,libumem)<br />
Rails 2.3.2/MRI Ruby 1.9.1: 603.92req/sec (Single Process,bsdmalloc)</p>
<p><a href="#conclusion">Jump to conclusion&#8230;.</a></p>
<p>Catalyst 5.8 / Perl 5.10<br />
Compiled: SUNCC -xO5 -xipo -fast -xtarget=native</p>
<pre>
<div class="codesnip-container" ># ab -n1000 -c100 http://somedomain:3000/
This is ApacheBench, Version 2.0.40-dev <$Revision: 1.146 $> apache-2.0
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Copyright 2006 The Apache Software Foundation, http://www.apache.org/

Benchmarking localhost (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Finished 1000 requests

Server Software:
Server Hostname:        somedomain
Server Port:            3000

Document Path:          /
Document Length:        11 bytes

Concurrency Level:      100
Time taken for tests:   0.673159 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Total transferred:      159000 bytes
HTML transferred:       11000 bytes
Requests per second:    1485.53 [#/sec] (mean)
Time per request:       67.316 [ms] (mean)
Time per request:       0.673 [ms] (mean, across all concurrent requests)
Transfer rate:          230.26 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   2.3      0      35
Processing:    15   62  10.8     62     103
Waiting:       15   59  11.6     61      98
Total:         15   62  10.6     63     103

Percentage of the requests served within a certain time (ms)
  50%     63
  66%     66
  75%     69
  80%     71
  90%     74
  95%     76
  98%     86
  99%     91
 100%    103 (longest request)</div>
</pre>
<p>Rails 2.3.2 / Ruby 1.8.7<br />
Compiled: SUNCC -xO5 -xipo -fast -xtarget=native</p>
<pre>
<div class="codesnip-container" ># ab -n1000 -c100 http://somedomain:3000/main/index
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking somedomain (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests

Server Software:        Mongrel
Server Hostname:        somedomain
Server Port:            3000

Document Path:          /main/index
Document Length:        11 bytes

Concurrency Level:      100
Time taken for tests:   3.847 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Total transferred:      290003 bytes
HTML transferred:       11000 bytes
Requests per second:    259.93 [#/sec] (mean)
Time per request:       384.718 [ms] (mean)
Time per request:       3.847 [ms] (mean, across all concurrent requests)
Transfer rate:          73.61 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   1.1      0      16
Processing:    10  369  65.2    389     428
Waiting:        9  368  65.3    388     427
Total:         10  369  65.2    390     428

Percentage of the requests served within a certain time (ms)
  50%    390
  66%    396
  75%    398
  80%    400
  90%    404
  95%    407
  98%    413
  99%    417
 100%    428 (longest request)</div>
</pre>
<p>Rails 2.3.2 / JRuby 1.3-dev build 6586 (Multi-Threaded), libumem<br />
Platform:  JDK7 B56</p>
<div class="codesnip-container" >
<pre>
# ab -n1000 -c100 http://somedomain.com:3000/main/index
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking somedomain.com (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests

Server Software:
Server Hostname:        somedomain.com
Server Port:            3000

Document Path:          /main/index
Document Length:        11 bytes

Concurrency Level:      100
Time taken for tests:   1.008 seconds
Complete requests:      1000
Failed requests:        1
   (Connect: 0, Receive: 0, Length: 1, Exceptions: 0)
Write errors:           0
Non-2xx responses:      1
Total transferred:      253875 bytes
HTML transferred:       11936 bytes
Requests per second:    992.32 [#/sec] (mean)
Time per request:       100.773 [ms] (mean)
Time per request:       1.008 [ms] (mean, across all concurrent requests)
Transfer rate:          246.02 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   1.7      0      13
Processing:    10   79  18.8     80     122
Waiting:        9   79  18.8     79     122
Total:         10   80  18.9     80     122

Percentage of the requests served within a certain time (ms)
  50%     80
  66%     88
  75%     94
  80%     98
  90%    102
  95%    108
  98%    113
  99%    114
 100%    122 (longest request)</div>
</pre>
<p>Rails 2.3.2 / JRuby 1.3-dev build 6586 (Single-Threaded)<br />
Platform:  JDK7 B56</p>
<pre>
<div class="codesnip-container" ># ab -n1000 -c100 http://somedomain:3000/main/index
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking somedomain (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests

Server Software:
Server Hostname:        somedomain
Server Port:            3000

Document Path:          /main/index
Document Length:        11 bytes

Concurrency Level:      100
Time taken for tests:   3.208 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Total transferred:      253000 bytes
HTML transferred:       11000 bytes
Requests per second:    311.71 [#/sec] (mean)
Time per request:       320.810 [ms] (mean)
Time per request:       3.208 [ms] (mean, across all concurrent requests)
Transfer rate:          77.01 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   2.5      0      31
Processing:    37  304  56.4    318     350
Waiting:       36  304  56.5    318     349
Total:         37  305  56.5    318     352

Percentage of the requests served within a certain time (ms)
  50%    318
  66%    326
  75%    330
  80%    332
  90%    336
  95%    341
  98%    345
  99%    348
 100%    352 (longest request)</div>
</pre>
<p>Rails 2.3.2 / Ruby 1.9.1<br />
Compiled:  GCC -O3 -fomit-frame-pointer (SunCC failed to compile)</p>
<pre>
<div class="codesnip-container" ># ab -n1000 -c100 http://somedomain:3000/main/index
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking somedomain (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests

Server Software:        thin
Server Hostname:        somedomain
Server Port:            3000

Document Path:          /main/index
Document Length:        11 bytes

Concurrency Level:      100
Time taken for tests:   1.656 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Total transferred:      267001 bytes
HTML transferred:       11000 bytes
Requests per second:    603.92 [#/sec] (mean)
Time per request:       165.585 [ms] (mean)
Time per request:       1.656 [ms] (mean, across all concurrent requests)
Transfer rate:          157.47 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.6      0       8
Processing:    28  160  39.0    187     222
Waiting:       13  145  38.5    143     209
Total:         28  160  39.0    187     222

Percentage of the requests served within a certain time (ms)
  50%    187
  66%    190
  75%    191
  80%    191
  90%    196
  95%    201
  98%    221
  99%    221
 100%    222 (longest request)</div>
</pre>
<h3>Conclusion</h3>
<div id="conclusion"></div>
<p>Seems like Catalyst has the edge in controller performance compared to Rails on MRI Ruby 1.8.7. Catalyst&#8217;s controller processing is <b>135% faster</b> than Rails in single process performance and <b>471% faster</b> as a forking multi process.  It is nice to see that the Catalyst team addressed the controller performance short comings of the earlier versions of Catalyst. Like any benchmark take it with a grain of salt. In a real application your data access layer will most likely be the bottle neck.</p>
<p>Rails 2.3.2 under JRuby with threading enabled ran <b>283% faster</b> than with MRI Ruby 1.8.7. I am anxiously waiting on JDK7 B57 with invoke dynamic support, this should help push JRuby&#8217;s performance even further. I guess I know what deployment option I will choose when deploying Rails.</p>
<p>Pick your poison, both frameworks provide excellent controller response performance. Keep in mind <a href="http://letsgetdugg.com/2009/04/26/fabulously40-architecture/">scaling is all about architecture</a> and not how fast your controller&#8217;s responses are. That said, having an efficient framework does help <img src='http://letsgetdugg.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://letsgetdugg.com/2009/04/30/catalyst-vs-rails-round-two/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Not all malloc implementations are created equal</title>
		<link>http://letsgetdugg.com/2009/04/30/not-all-malloc-implementations-are-created-equal/</link>
		<comments>http://letsgetdugg.com/2009/04/30/not-all-malloc-implementations-are-created-equal/#comments</comments>
		<pubDate>Thu, 30 Apr 2009 07:25:54 +0000</pubDate>
		<dc:creator>victori</dc:creator>
				<category><![CDATA[administration]]></category>
		<category><![CDATA[benchmark]]></category>
		<category><![CDATA[main]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[solaris]]></category>

		<guid isPermaLink="false">http://letsgetdugg.com/?p=112</guid>
		<description><![CDATA[I have recently blogged about swapping malloc implementations for the JVM to help boost multi-threaded performance. Well there is yet another malloc implementation that solaris comes with that is optimized for single threaded performance; bsdmalloc. I just recently switched our perl interpreter to use bsdmalloc and got 33% faster performance with our perlbal proxy. You [...]]]></description>
			<content:encoded><![CDATA[<p>I have recently<a href="http://letsgetdugg.com/2009/04/21/improve-java-performance-on-solaris/"> blogged about swapping malloc implementations</a> for the JVM to help boost multi-threaded performance. Well there is yet another malloc implementation that solaris comes with that is optimized for single threaded performance; <strong>bsdmalloc</strong>. I just recently switched our perl interpreter to use bsdmalloc and got <em>33% faster performance</em> with our perlbal proxy. </p>
<p>You can try out multiple malloc implementations by setting LD_PRELOAD environment variable. </p>
<pre>
LD_PRELOAD="/usr/lib/libbsdmalloc.so" perl somecode.pl
</pre>
<p>So here is the rule of thumb for which malloc implementation to use for your application. </p>
<p><strong>libumem</strong> = For multithreaded applications. umem avoids thread heap contention and is highly optimized for multi-threaded applications.</p>
<p><strong>bsdmalloc</strong> = For single threaded applications. PHP/Perl/Python and Ruby will fall into this category. </p>
<p>Applying the right malloc implementation to your resource intensive application can see a nice performance benefit. </p>
]]></content:encoded>
			<wfw:commentRss>http://letsgetdugg.com/2009/04/30/not-all-malloc-implementations-are-created-equal/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ruby scaling up to multiple CPUs</title>
		<link>http://letsgetdugg.com/2009/04/28/ruby-scaling-up-to-multiple-cpus/</link>
		<comments>http://letsgetdugg.com/2009/04/28/ruby-scaling-up-to-multiple-cpus/#comments</comments>
		<pubDate>Tue, 28 Apr 2009 20:13:51 +0000</pubDate>
		<dc:creator>victori</dc:creator>
				<category><![CDATA[benchmark]]></category>
		<category><![CDATA[main]]></category>

		<guid isPermaLink="false">http://letsgetdugg.com/?p=106</guid>
		<description><![CDATA[I wrote a quick micro benchmark to test out ruby threads. Apparently ruby can&#8217;t make use of multiple CPUs with it&#8217;s threading implementation. I guess you have to resort to forking to scale up to multiple cpu cores while using mri ruby. However, there is an alternative solution, just use JRuby. JRuby utilizes all cores [...]]]></description>
			<content:encoded><![CDATA[<p>I wrote a quick micro benchmark to test out ruby threads. Apparently ruby can&#8217;t make use of multiple CPUs with it&#8217;s threading implementation. I guess you have to resort to <i>forking</i> to scale up to multiple cpu cores while using mri ruby. However, there is an alternative solution, just use JRuby. JRuby utilizes all cores when running the benchmark. </p>
<pre>
<div class="codesnip-container" >Ruby 1.8.7 - Compiled with SunCC SSX0903 (-xO5 -fast -xipo)
Total number of insane floating point divisions in 10 seconds is 5969107</div>
</pre>
<pre>
<div class="codesnip-container" >Ruby 1.9.1 / Compiled with GCC 4.3.2 (-O3 -fomit-frame-pointer)
Total number of insane floating point divisions in 10 seconds is 8596894</div>
</pre>
<p>Ran as: jruby &#8211;fast cpuMax.rb<br />
<strong>177% increase in performance</strong></p>
<pre>
<div class="codesnip-container" >JRuby 1.3-dev / JDK7 b56
Total number of insane floating point divisions in 10 seconds is 15915896</div>
</pre>
<p>Ran as: jruby &#8211;fast -J-Djruby.compile.mode=JIT -J-Djruby.jit.threshold=0 -J-server cpuMax.rb<br />
<strong>374% increase in performance</strong></p>
<pre>
<div class="codesnip-container" >JRuby 1.3-dev / JDK7 b56
Total number of insane floating point divisions in 10 seconds is 28334441</div>
</pre>
<p>Looking at mpstat, I can see the MRI ruby implementation is not utilizing all 4 cores.</p>
<pre>
Ruby 1.8.7 MRI

CPU minf mjf xcal  intr ithr  csw icsw migr smtx  srw syscl  usr sys  wt idl
  0  828   0   13   428  204  487   26   93   16    0  1903    4   5   0  91
  1 2682   0    3    39    2  280   32   81   12    2  1189   13   2   0  85
  2 1902   0    0    34   11  259   16   57   13    0  1094   11   3   0  86
  3 1017   0    3   192  150  111   34   38    8    0   676   92   2   0   6
CPU minf mjf xcal  intr ithr  csw icsw migr smtx  srw syscl  usr sys  wt idl
  0    2   0    5   422  205  388   11   75    5    0   627    4   1   0  95
  1  161   0   13    20    2  196   11   61    8    0  1405    2   2   0  96
  2  292   0    6    32   15  272   10   57    7    0   700    2   1   0  97
  3    0   0    0   108   65   74   35   28    3    0   346   99   0   0   1
</pre>
<p>Now here is the JRuby implementation.</p>
<pre>
CPU minf mjf xcal  intr ithr  csw icsw migr smtx  srw syscl  usr sys  wt idl
  0  229   0  202   755  193 1977  365  329   94    1  2869   90   2   0   8
  1  328   0   86   371    1 1817  226  303  125    0  2809   86   2   0  12
  2  294   0  128   326    0 1771  248  287  109    0  2290   88   2   0  10
  3  320   0  172   402   62 1848  246  241  116    0  2238   86   3   0  11
CPU minf mjf xcal  intr ithr  csw icsw migr smtx  srw syscl  usr sys  wt idl
  0  317   0  297   700  192 2047  323  341  136    1  2819   89   2   0   9
  1  320   0   61   279    2 1611  134  195  130    0  1960   85   2   0  13
  2  288   0  235   379    0 1941  291  299  115    0  2462   87   2   0  11
  3  308   0   78   316   43 1688  142  159  104    0  1706   85   2   0  13
</pre>
<p>I think I will stick to JRuby for production use.</p>
<div class="codesnip-container" >
<div class="ruby codesnip" style="font-family:monospace;"><span class="co1">#!/usr/bin/ruby</span></p>
<p><span class="kw3">require</span> <span class="st0">&#8216;thread&#8217;</span><br />
threads = <span class="br0">&#91;</span><span class="br0">&#93;</span><br />
counter = 0<br />
mutex = <span class="kw4">Mutex</span>.<span class="me1">new</span></p>
<p>4.<span class="me1">times</span> <span class="kw1">do</span><br />
&nbsp; &nbsp; &nbsp;threads <span class="sy0">&lt;&lt;</span> <span class="kw4">Thread</span>.<span class="me1">new</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; x=0<br />
&nbsp; &nbsp; &nbsp; &nbsp; y=0<br />
&nbsp; &nbsp; &nbsp; &nbsp; time=<span class="kw4">Time</span>.<span class="me1">new</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">while</span> 1 <span class="kw1">do</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="kw4">Time</span>.<span class="me1">new</span> <span class="sy0">-</span> time <span class="sy0">&gt;</span>= 10 <span class="kw1">then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">break</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; x=1.00<span class="sy0">/</span>24000000000.001<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; y<span class="sy0">+</span>=1<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">end</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">end</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; mutex.<span class="me1">synchronize</span> <span class="br0">&#123;</span> counter<span class="sy0">+</span>=y.<span class="me1">to_i</span> <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="kw1">end</span><br />
threads.<span class="me1">each</span> <span class="br0">&#123;</span> <span class="sy0">|</span>t<span class="sy0">|</span> t.<span class="me1">join</span> <span class="br0">&#125;</span></p>
<p><span class="kw3">puts</span> <span class="st0">&quot;Total number of insane floating point divisions in 10 seconds is &quot;</span><span class="sy0">+</span>counter.<span class="me1">to_s</span></div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://letsgetdugg.com/2009/04/28/ruby-scaling-up-to-multiple-cpus/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
	</channel>
</rss>

