<?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>Mike Perham &#187; Ruby</title>
	<atom:link href="http://www.mikeperham.com/category/ruby/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mikeperham.com</link>
	<description>On Ruby, software and the Internet</description>
	<lastBuildDate>Sat, 31 Dec 2011 04:32:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Optimizing Heroku</title>
		<link>http://www.mikeperham.com/2011/06/01/optimizing-heroku/</link>
		<comments>http://www.mikeperham.com/2011/06/01/optimizing-heroku/#comments</comments>
		<pubDate>Wed, 01 Jun 2011 23:02:11 +0000</pubDate>
		<dc:creator>Mike Perham</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.mikeperham.com/?p=745</guid>
		<description><![CDATA[I spent some time recently playing with a trivial Rails 3 app using girl_friday and learned a few interesting things: Michael&#8217;s post on using Unicorn with Heroku is a fantastic idea and great way to improve the efficiency of your Heroku application&#8217;s web dynos. Heroku imposes a limit of 15 threads per Ruby process (there [...]]]></description>
			<content:encoded><![CDATA[<p>I spent some time recently playing with a trivial Rails 3 app using <a href="http://mperham.github.com/girl_friday">girl_friday</a> and learned a few interesting things:</p>
<ul>
<li>Michael&#8217;s post on <a href="http://michaelvanrooijen.com/articles/2011/06/01-more-concurrency-on-a-single-heroku-dyno-with-the-new-celadon-cedar-stack/">using Unicorn with Heroku</a> is a fantastic idea and great way to improve the efficiency of your Heroku application&#8217;s web dynos.</li>
<li>Heroku imposes a limit of 15 threads per Ruby process (there is an open question about this, it might just be a bug in the Heroku Cedar stack, which is still beta).  If you are using thin, you get 1 process and 15 threads per dyno.  If you are using Unicorn, you get 3 processes<sup>*</sup> and 45 threads.</li>
<li>girl_friday defaults to 5 threads per queue.  With the thread limit on Heroku, you&#8217;ll want to carefully ration the size of each queue.  girl_friday&#8217;s Rack status app can tell you at runtime which queues are busy and which are quiet for tuning purposes.</li>
<li>girl_friday can, in many cases, replace or dramatically reduce your need for separate worker dynos, saving you money.</li>
</ul>
<p>* Where 3 is based on the memory consumption of your application.  YMMV.</p>
<p>Unicorn appears to work great with girl_friday and Heroku&#8217;s free service level actually becomes useful for non-trivial applications with these optimizations.  Know any other tips?  Let me know!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mikeperham.com/2011/06/01/optimizing-heroku/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Threads Fibers Events and Actors</title>
		<link>http://www.mikeperham.com/2011/05/19/threads-fibers-events-and-actors/</link>
		<comments>http://www.mikeperham.com/2011/05/19/threads-fibers-events-and-actors/#comments</comments>
		<pubDate>Fri, 20 May 2011 02:37:43 +0000</pubDate>
		<dc:creator>Mike Perham</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.mikeperham.com/?p=738</guid>
		<description><![CDATA[I presented (from 3000 miles away!) today at EMRubyConf. My talk, &#8220;Threads Fibers Events and Actors&#8220;, is a short 13min chat on current trends in Ruby scalability and concurrency. To summarize: Ruby&#8217;s threading has historically been terrible. So we turned to event-based systems like EventMachine but the reactor pattern brings its own set of drawbacks. [...]]]></description>
			<content:encoded><![CDATA[<p>I presented (from 3000 miles away!) today at <a href="//emrubyconf.com">EMRubyConf</a>.  My talk, &#8220;<a href="http://vimeo.com/23933313">Threads Fibers Events and Actors</a>&#8220;, is a short 13min chat on current trends in Ruby scalability and concurrency.  To summarize:</p>
<p>Ruby&#8217;s threading has historically been terrible.  So we turned to event-based systems like EventMachine but the reactor pattern brings its own set of drawbacks.  So we turned to Fibers to solve some of those problems but they bring along another set of drawbacks.  In the end though, all of this is a workaround for Ruby&#8217;s historically terrible threading implementation.  But what if Ruby&#8217;s threading didn&#8217;t suck?</p>
<p>JRuby has great threads.  Rubinius will soon have great threads.  Both have really matured into excellent, stable runtimes over the last year.  Make no mistake threads have issues too; locks and race conditions are notoriously hard to write well and Ruby code can&#8217;t be autoloaded safely in a multithreaded system.  The former is what Actors attempt to solve: making concurrency simpler and safer by passing messages rather than sharing mutable state and requiring locks.</p>
<p>I think the Ruby community needs to give threads another chance: ensure their gems are thread-safe and use Actors when needing to write safe multithreaded code.  <a href="https://github.com/tarcieri/celluloid">Celluloid</a> and the <a href="http://rubini.us/doc/en/systems/concurrency/">Rubinius Actor API</a> are two APIs which provide Actors to Ruby. My new gem <a href="http://mperham.github.com/girl_friday">girl_friday</a> leverages actors for safe concurrency.  The autoloading problem is the only hard problem remaining; I hope some time and effort can determine ways around this issue.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mikeperham.com/2011/05/19/threads-fibers-events-and-actors/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Actors and Ruby</title>
		<link>http://www.mikeperham.com/2011/04/23/actors-and-ruby/</link>
		<comments>http://www.mikeperham.com/2011/04/23/actors-and-ruby/#comments</comments>
		<pubDate>Sat, 23 Apr 2011 22:58:04 +0000</pubDate>
		<dc:creator>Mike Perham</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.mikeperham.com/?p=721</guid>
		<description><![CDATA[I&#8217;ve spent the last month learning Rubinius&#8217;s Actor API for safer concurrency with threads. My entire career really has been focused on learning and building scalable and high performance infrastructure. My explorations with Fibers over the last year lead me to believe that they are essentially a workable hack to get around Ruby&#8217;s current issues [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve spent the last month learning Rubinius&#8217;s Actor API for safer concurrency with threads.  My entire career really has been focused on learning and building scalable and high performance infrastructure.  My explorations with Fibers over the last year lead me to believe that they are essentially a workable hack to get around Ruby&#8217;s current issues but not really something that developers should use widely.  Debugging is difficult and testing very difficult with any reactor-based system.</p>
<p>On the other hand, I do think Actors are a good step forward for concurrency by making Threads safer to utilize.  By the end of this year, we&#8217;ll have several Ruby VMs (JRuby, MacRuby, Rubinius) that can execute threads in parallel, allowing a single Ruby process to peg a multi-core machine; Actors will be helpful in building applications that can take advantage of this.</p>
<p>I&#8217;ve written two posts on the <a href="http://blog.carbonfive.com">Carbon Five</a> blog, the first covering <a href="http://blog.carbonfive.com/2011/04/19/concurrency-with-actors/">Actors in general</a> and the second covering my new, simple but full-featured <a href="http://blog.carbonfive.com/2011/04/20/asynchronous-processing-with-girl_friday/">asynchronous processing library, girl_friday</a>, which leverages Actors.  Take a look and let me know what you think!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mikeperham.com/2011/04/23/actors-and-ruby/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Filling out PDF forms with JRuby</title>
		<link>http://www.mikeperham.com/2011/02/15/filling-out-pdf-forms-with-jruby/</link>
		<comments>http://www.mikeperham.com/2011/02/15/filling-out-pdf-forms-with-jruby/#comments</comments>
		<pubDate>Tue, 15 Feb 2011 21:10:25 +0000</pubDate>
		<dc:creator>Mike Perham</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.mikeperham.com/?p=699</guid>
		<description><![CDATA[I recently had to figure out how to programmatically fill out a PDF based on the form input from a Rails application. It looks like there&#8217;s nothing native to Ruby but there is a comprehensive PDF library called iText which will handle form duties. Using JRuby, we can access their Java API to fill out [...]]]></description>
			<content:encoded><![CDATA[<p>I recently had to figure out how to programmatically fill out a PDF based on the form input from a Rails application.  It looks like there&#8217;s nothing native to Ruby but there is a comprehensive PDF library called <a href="http://api.itextpdf.com/">iText</a> which will handle <a href="http://itextpdf.com/themes/keyword.php?id=247">form</a> duties.  Using JRuby, we can access their Java API to fill out the form pretty easily:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'java'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'iText-5.0.6.jar'</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">module</span> Pdf
  include_package <span style="color:#996600;">&quot;com.itextpdf.text.pdf&quot;</span>
  include_package <span style="color:#996600;">&quot;java.io&quot;</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">write</span>
    reader = PdfReader.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'application.pdf'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;
    stamper = PdfStamper.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>reader, FileOutputStream.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'completed.pdf'</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    form = stamper.<span style="color:#9900CC;">acro_fields</span>
    <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Form has these fields: #{form.fields.key_set.to_a}&quot;</span>
    form.<span style="color:#9900CC;">set_field</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;some_zipcode_field&quot;</span>, <span style="color:#996600;">&quot;94115&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    stamper.<span style="color:#9900CC;">close</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
Pdf.<span style="color:#9900CC;">write</span></pre></div></div>

<p>Obviously sample code, not production quality, etc.  Really the only hard/tedious part is mapping field names to Ruby object attribute values.  If you have a complex form, you may have tens or even hundreds of <code>set_field</code> calls.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mikeperham.com/2011/02/15/filling-out-pdf-forms-with-jruby/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Using RDoc</title>
		<link>http://www.mikeperham.com/2010/12/16/using-rdoc/</link>
		<comments>http://www.mikeperham.com/2010/12/16/using-rdoc/#comments</comments>
		<pubDate>Thu, 16 Dec 2010 15:55:29 +0000</pubDate>
		<dc:creator>Mike Perham</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.mikeperham.com/?p=673</guid>
		<description><![CDATA[One longstanding weakness with the Ruby community is subpar documentation. I think many Rubyists tend to look down on actual API documentation, preferring instead to just read source code directly. I&#8217;ve been guilty of this too and I think some of this is due simply to unfamiliarity with RDoc. Let&#8217;s change that now. Creating RDoc [...]]]></description>
			<content:encoded><![CDATA[<p>One longstanding weakness with the Ruby community is subpar documentation.  I think many Rubyists tend to look down on actual API documentation, preferring instead to just read source code directly.  I&#8217;ve been guilty of this too and I think some of this is due simply to unfamiliarity with RDoc.  Let&#8217;s change that now.</p>
<p><strong>Creating RDoc</strong></p>
<p>I&#8217;ve never found an easily accessible RDoc markup reference.  The only one I know of is unlinkable, buried at the bottom of the RDoc readme instead of front and center as it should be.  So I extracted the <a href='http://www.mikeperham.com/wp-content/uploads/2010/12/rdoc.html'>RDoc markup reference</a> for your reading pleasure.  Jan Varwig created a great <a href="http://jan.varwig.org/wp-content/uploads/2006/09/Rdoc%20Cheat%20Sheet.pdf">RDoc cheatsheet PDF</a> for local or offline access.</p>
<p>Next time you&#8217;re working on a gem, take 10 minutes to read the reference and document the main class for the gem.  It&#8217;ll make you a better Rubyist, I guarantee it.</p>
<p><strong>Generating RDoc</strong></p>
<p>Ok, so you&#8217;ve learned RDoc markup and your code is documented like a champ.  What do you do now?  You&#8217;ve got several choices:</p>
<ul>
<li>Generate rdoc by hand &#8211; the <code>rdoc</code> command ships with Ruby and by default generates all .rb files in or below the current directory.  You probably want something like <code>rdoc lib</code> to just include your project&#8217;s main Ruby code.</li>
<li>Integrate RDoc into Rake &#8211; Rake has an <a href="http://rake.rubyforge.org/classes/Rake/RDocTask.html">RDocTask</a> which can be configured for your project, so you can just run <code>rake rdoc</code>.</li>
</ul>
<p>Once generated, you can view the generated output at <code>doc/index.html</code>.</p>
<p><strong>Viewing RDoc</strong></p>
<p>Rubygems has built-in support for generating and viewing the RDoc for installed gems.  rdoc is generated when the gem is installed (using <code>gem install --no-rdoc [name]</code> skips the local rdoc generation).  You can then use <code>gem server</code> to view your local gem rdoc at <a href="http://localhost:8808">http://localhost:8808</a>.</p>
<p><strong>Check out YARD</strong></p>
<p><a href="http://yardoc.org">YARD</a> is an interesting project by Loren Segal to create a next generation Ruby documentation system.  <a href="http://rubydoc.info/docs/yard/file/docs/GettingStarted.md">Getting started with YARD</a> is well documented; try it out if you want an alternative to RDoc.  YARD&#8217;s syntax is a superset of RDoc&#8217;s so backwards compatibility should not be an issue.  The <a href="http://rubydoc.info/github/mperham/dalli/master/frames">generated documentation</a> looks pretty awesome (note the support for Markdown-formatted README files, which RDoc does not have).</p>
<p>The YARD team also created <a href="http://rubydoc.info/">RubyDoc.info</a>, which hosts documentation for popular gems and is a great resource for finding linkable documentation.</p>
<p>I hope this helps de-mystify rdoc for people.  Any other rdoc tips, please leave a comment.  Happy documenting!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mikeperham.com/2010/12/16/using-rdoc/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Contributing to Ruby</title>
		<link>http://www.mikeperham.com/2010/12/08/contributing-to-ruby/</link>
		<comments>http://www.mikeperham.com/2010/12/08/contributing-to-ruby/#comments</comments>
		<pubDate>Wed, 08 Dec 2010 17:22:21 +0000</pubDate>
		<dc:creator>Mike Perham</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.mikeperham.com/?p=670</guid>
		<description><![CDATA[I had a very pleasant experience recently in contributing some net/http documentation improvements to Ruby. Ruby Core has made contributing very easy these days, it&#8217;s really as simple as: Fork http://github.com/ruby/ruby Make and commit your changes in your repo Send a pull request In other words, contributing to Ruby is now just as easy to [...]]]></description>
			<content:encoded><![CDATA[<p>I had a very pleasant experience recently in contributing <a href="https://github.com/ruby/ruby/commit/baf7a09d3509f7d858fc7a705e14feaaf5ad56b6">some net/http documentation</a> improvements to Ruby.  Ruby Core has made contributing very easy these days, it&#8217;s really as simple as:</p>
<ul>
<li>Fork http://github.com/ruby/ruby</li>
<li>Make and commit your changes in your repo</li>
<li>Send a pull request</li>
</ul>
<p>In other words, contributing to Ruby is now just as easy to contribute to as any other Github project!  This is a huge deal.  Obviously there are caveats: if you are making significant changes to runtime code, you should probably enter an issue in <a href="http://redmine.ruby-lang.org/">Redmine</a> and/or send an email to the ruby-dev mailing list.  But for small cleanups and RDoc improvements that have been sorely missing for years, there&#8217;s no longer any excuse!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mikeperham.com/2010/12/08/contributing-to-ruby/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Ruby Stdlib is a Ghetto, Pt. 2</title>
		<link>http://www.mikeperham.com/2010/11/25/ruby-stdlib-is-a-ghetto-pt-2/</link>
		<comments>http://www.mikeperham.com/2010/11/25/ruby-stdlib-is-a-ghetto-pt-2/#comments</comments>
		<pubDate>Thu, 25 Nov 2010 16:42:24 +0000</pubDate>
		<dc:creator>Mike Perham</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.mikeperham.com/?p=660</guid>
		<description><![CDATA[Eric Hodel disagreed with my recent point. I didn&#8217;t present much of an argument because I didn&#8217;t think there was much disagreement with my point. Let me elaborate. 1) It&#8217;s full of unnecessary libraries that should be separately distributed The Ruby community, at least in the US, has proven to be very open to change, [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.segment7.net">Eric Hodel</a> disagreed with my recent point.  I didn&#8217;t present much of an argument because I didn&#8217;t think there was much disagreement with my point.  Let me elaborate.</p>
<p><strong>1) It&#8217;s full of unnecessary libraries that should be separately distributed</strong></p>
<p>The Ruby community, at least in the US, has proven to be very open to change, see Rails 1, 2 and 3 for example.  Sometimes you have to break compatibility to advance the state of the art.  Continuing to bundle inferior implementations means that we have this compatibility albatross around our neck while stronger third-party libraries don&#8217;t pop to the top of the ecosystem.  <a href="http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/32078">Some random dude</a> said it better than me.  <a href="http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/32012">Some other dude agreed</a>, REXML in this case should be unbundled.</p>
<p>I was proposing unbundling DRb and Tk not because their codebase sucks but simply because they aren&#8217;t used by the vast majority of the Ruby community.  treetop and shoes are very useful libraries also but they don&#8217;t belong in stdlib either.</p>
<p>I&#8217;m not proposing we do this in the next 1.9.2 patch, but for 2.0, sure.  Now that rubygems is in core (thanks Eric!), I think we should be aggressive in unbundling everything that can be unbundled.</p>
<p><strong>2) It&#8217;s (still) too hard to contribute</strong></p>
<p>The Net::HTTP docs haven&#8217;t been touched AFAICT in 5 years.  They&#8217;re full of broken English and rudimentary examples.  I hear people complain about it all the time, why hasn&#8217;t anyone fixed it?  Maybe everyone is lazy or maybe the contribution process remains too steep for most.</p>
<p>Net::HTTP had performance issues in the 1.8.6 era, sounds they have been fixed.  The API is still poor and poorly documented IMO.  Just about every HTTP library has a better API IMO, e.g. Typhoeus, httparty and rest-client.  As someone else pointed out, Ruby really does need an http API in core though, if not just for Rubygems to use.</p>
<p>I would love to see ruby-core treat git as a first class citizen and allow pull requests and git email patches against <a href="http://github.com/ruby/ruby">http://github.com/ruby/ruby</a>.  If this is the case today, please let me know.  I will be the first to submit a pull request for better net/http docs.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mikeperham.com/2010/11/25/ruby-stdlib-is-a-ghetto-pt-2/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>The Ruby Stdlib is a Ghetto</title>
		<link>http://www.mikeperham.com/2010/11/22/the-ruby-stdlib-is-a-ghetto/</link>
		<comments>http://www.mikeperham.com/2010/11/22/the-ruby-stdlib-is-a-ghetto/#comments</comments>
		<pubDate>Mon, 22 Nov 2010 16:48:14 +0000</pubDate>
		<dc:creator>Mike Perham</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.mikeperham.com/?p=648</guid>
		<description><![CDATA[Much of Ruby&#8217;s standard library (the set of classes shipped with the Ruby VM itself) is old and crufty. For laughs, go look at the code for some of the classes that you&#8217;ve never used. Chances are it&#8217;s from 2000-2003 and doesn&#8217;t even look like idiomatic Ruby. I&#8217;m wondering what classes should be removed from [...]]]></description>
			<content:encoded><![CDATA[<p>Much of Ruby&#8217;s standard library (the set of classes shipped with the Ruby VM itself) is old and crufty.  For laughs, go look at the code for some of the classes that you&#8217;ve never used.  Chances are it&#8217;s from 2000-2003 and doesn&#8217;t even look like idiomatic Ruby.  I&#8217;m wondering what classes should be removed from the standard library or deprecated so that higher quality replacements can take their place.</p>
<p>The canonical example is Ruby&#8217;s net/http library.  Its performance and API are just terrible.  (Side note: how do you know if an API is terrible?  If you have to consult the docs even after having used the API for the past 5 years.)  But because it&#8217;s in the standard library, most people use it as the base for higher-level API abstractions (e.g. httparty, rest-client).</p>
<p>So looking at <a href="http://ruby-doc.org/ruby-1.9/index.html">Ruby&#8217;s core RDoc</a>, my suggested list for removal (where removal means move to a rubygem):</p>
<ul>
<li>Net::*</li>
<li>DRb</li>
<li>REXML</li>
<li>RSS</li>
<li>Rinda</li>
<li>WEBrick</li>
<li>XML</li>
</ul>
<p>Any others I missed?  Will Ruby 1.9.3 or 2.0 get a good spring cleaning or will we have to live with these classes forever?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mikeperham.com/2010/11/22/the-ruby-stdlib-is-a-ghetto/feed/</wfw:commentRss>
		<slash:comments>33</slash:comments>
		</item>
		<item>
		<title>Dalli Performance and Garbage Collection</title>
		<link>http://www.mikeperham.com/2010/09/19/dalli-performance-and-garbage-collection/</link>
		<comments>http://www.mikeperham.com/2010/09/19/dalli-performance-and-garbage-collection/#comments</comments>
		<pubDate>Sun, 19 Sep 2010 17:53:21 +0000</pubDate>
		<dc:creator>Mike Perham</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.mikeperham.com/?p=624</guid>
		<description><![CDATA[I did an interesting experiment to compare memcache-client and Dalli performance this morning. I wanted to understand which library allocated more objects in order to know which library would have more GC overhead. Ruby 1.9 has a new module GC::Profiler which will generate a report with stats about each GC run. Since both gems have [...]]]></description>
			<content:encoded><![CDATA[<p>I did an interesting experiment to compare memcache-client and <a href="http://github.com/mperham/dalli">Dalli</a> performance this morning.  I wanted to understand which library allocated more objects in order to know which library would have more GC overhead.  Ruby 1.9 has a new module <a href="http://rdoc.info/docs/ruby-core/1.9.2/GC/Profiler">GC::Profiler</a> which will generate a report with stats about each GC run.  Since both gems have an identical benchmark suite, I ran the GC Profiler on the benchmark suite for each:</p>
<table cellpadding="5" cellspacing="10">
<tr>
<th>&nbsp;</th>
<th>Runs</th>
<th>GC Time</th>
<th>Total Time</th>
</tr>
<tr>
<th>memcache-client</th>
<td>596</td>
<td>3.40</td>
<td>18.35</td>
</tr>
<tr>
<th>dalli</th>
<td>153</td>
<td>1.73</td>
<td>15.29</td>
</tr>
</table>
<p>memcache-client runs the GC 4x as much as Dalli and roughly half of Dalli&#8217;s speed improvement over memcache-client is due to more efficient object allocation requiring less garbage collection.  Note that Dalli&#8217;s GC runs seem to take twice as long as the memcache-client runs.  Anyone know Ruby 1.9&#8242;s GC implementation and have an idea why this might be?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mikeperham.com/2010/09/19/dalli-performance-and-garbage-collection/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Dalli &#8211; memcached for Ruby</title>
		<link>http://www.mikeperham.com/2010/08/30/dalli-memcached-for-ruby/</link>
		<comments>http://www.mikeperham.com/2010/08/30/dalli-memcached-for-ruby/#comments</comments>
		<pubDate>Mon, 30 Aug 2010 15:32:13 +0000</pubDate>
		<dc:creator>Mike Perham</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[memcached]]></category>

		<guid isPermaLink="false">http://www.mikeperham.com/?p=616</guid>
		<description><![CDATA[Dalli is my brand new memcached client for Ruby. I&#8217;ve maintained Ruby&#8217;s memcache-client for two years now and been dissatisfied with the codebase for a while. Coincidentally, NorthScale approached me recently about building a pure Ruby memcached client which used the new binary protocol defined in memcached 1.4. We worked out an arrangement to sponsor [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.mikeperham.com/wp-content/uploads/2010/08/memcache_logo.png" alt="" title="memcache_logo" width="76" height="75" class="alignleft size-full wp-image-619" /><a href="http://github.com/mperham/dalli">Dalli</a> is my brand new memcached client for Ruby.  I&#8217;ve maintained Ruby&#8217;s memcache-client for two years now and been dissatisfied with the codebase for a while.<br />
<img src="http://www.mikeperham.com/wp-content/uploads/2010/08/NorthScale-Labs.gif" alt="" title="NorthScale Labs" width="171" height="62" class="alignright size-full wp-image-617" /><br />
Coincidentally, <a href="http://www.northscale.com">NorthScale</a> approached me recently about building a pure Ruby memcached client which used the new <a href="http://code.google.com/p/memcached/wiki/MemcacheBinaryProtocol">binary protocol</a> defined in memcached 1.4.  We worked out an arrangement to sponsor the OSS project which became Dalli.</p>
<p>My goals for Dalli were threefold:</p>
<ol>
<li>Clean sheet codebase using the binary protocol</li>
<li>Drop-in replacement for memcache-client in Rails for a very simple upgrade path for Rails developers</li>
<li>Equivalent or faster performance than memcache-client</li>
</ol>
<p>I&#8217;m happy to say that Dalli meets all those goals.  For one, the Dalli core is almost half the size of the memcache-client core, 700 vs 1250 LOC!  But wait, there&#8217;s more!  Using Rails 3?  Dalli drops right in!  Using Heroku?  Dalli works without any additional configuration!  <a href="http://github.com/mperham/dalli">Take a look at the README</a> for more details.</p>
<p>Please <a href="http://github.com/mperham/dalli/issues">file an issue</a> if you find a bug or have a feature you&#8217;d like to see.  In the meantime, happy caching!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mikeperham.com/2010/08/30/dalli-memcached-for-ruby/feed/</wfw:commentRss>
		<slash:comments>24</slash:comments>
		</item>
	</channel>
</rss>

