<?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>snax</title>
	<atom:link href="http://blog.evanweaver.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.evanweaver.com</link>
	<description>on software</description>
	<lastBuildDate>Sat, 10 Mar 2012 21:30:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='blog.evanweaver.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>snax</title>
		<link>http://blog.evanweaver.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://blog.evanweaver.com/osd.xml" title="snax" />
	<atom:link rel='hub' href='http://blog.evanweaver.com/?pushpress=hub'/>
		<item>
		<title>hello heroku world</title>
		<link>http://blog.evanweaver.com/2012/02/29/hello-heroku-world/</link>
		<comments>http://blog.evanweaver.com/2012/02/29/hello-heroku-world/#comments</comments>
		<pubDate>Thu, 01 Mar 2012 01:43:54 +0000</pubDate>
		<dc:creator>evan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.evanweaver.com/?p=2137</guid>
		<description><![CDATA[I&#8217;ve been investigating various platform-as-a-service providers, and did some basic benchmarking on Heroku. I deployed a number of HTTP hello-world apps on the Cedar stack and hammered them via autobench. The results may be interesting to you if you are trying to maximize your hello-world dollar. setup Each Heroku dyno is an lxc container with 512MB of ram [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.evanweaver.com&amp;blog=18067431&amp;post=2137&amp;subd=evanweaver&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been investigating various platform-as-a-service providers, and did some basic benchmarking on Heroku.</p>
<p>I deployed a number of HTTP hello-world apps on the Cedar stack and hammered them via <code>autobench</code>. The results may be interesting to you if you are trying to maximize your hello-world dollar.</p>
<h2>setup</h2>
<p>Each Heroku dyno is an <a href="http://lxc.sourceforge.net/">lxc</a> container with 512MB of ram and an unclear amount of CPU. The JVM parameters were <code>-Xmx384m -Xss512k -XX:+UseCompressedOops -server -d64</code>.</p>
<p>The driver machine was an EC2 <code>m1.large</code> in <code>us-east-1a</code>, running the default 64-bit Amazon Linux AMI. A single <code>httperf</code> process could successfully generate up to 25,000 rps with the given configuration. Timeouts were set high enough to allow any intermediate queues to stay flooded.</p>
<h2>throughput results</h2>
<p>In the below graphs, the response rate is the solid line <strong><code>━━</code></strong> and the left <code>y</code> axis; connection errors as a percentage are the dashed line <strong><code>----</code></strong> and the right <code>y</code> axis. The graphs are heavily splined, as suits a meaningless micro-benchmark.</p>
<p>Note that as the response rates fall away from the gray, dashed <code>x=y</code> line, the server is responding increasingly late and thus would shed sustained load, regardless of the measured connection error rate.</p>
<p><a href="https://github.com/evan/heroku-hello-world-tests/raw/master/results_1-throughput.png"><img title="throughput-results_1" src="https://github.com/evan/heroku-hello-world-tests/raw/master/results_1-throughput.png?w=540" alt="" width="540" height="405" /></a><a href="https://github.com/evan/heroku-hello-world-tests/raw/master/results_4-throughput.png"><img title="throughput-results_4" src="https://github.com/evan/heroku-hello-world-tests/raw/master/results_4-throughput.png?w=540" alt="" width="540" height="405" /></a><a href="https://github.com/evan/heroku-hello-world-tests/raw/master/results_7-throughput.png"><img src="https://github.com/evan/heroku-hello-world-tests/raw/master/results_7-throughput.png?w=540" alt="" width="540" height="405" /></a></p>
<p>Finagle and Node made good throughput showings—Node had the most consistent performance profile, but Finagle&#8217;s best case was better. Sinatra (hosted by Thin) and Tomcat did OK. Jetty collapsed when pushed past its limit, and Bottle (hosted by wsgiref) was effectively non-functional. Finally, the naive C/Accept &#8220;stack&#8221; demonstrated an amusing combination of poor performance and good scalability.</p>
<p>As the number of dynos increases, the best per-dyno response rate declines from 2500 to below 1000, and the implementations become less and less differentiated. This suggests that there is a non-linear bottleneck in the routing layer. There also appears to be a per-app routing limit around 12,000 rps that no number of dynos can overcome (data not shown). For point of reference,  12,000 rps is the same velocity as the entire <a href="http://techblog.netflix.com/2012/02/fault-tolerance-in-high-volume.html">Netflix API</a>.</p>
<p>The outcome demonstrates the complicated interaction between implementation scalability, per-dyno scalability, and per-app scalability, none of which are linear constraints.</p>
<h2>latency results</h2>
<p><a href="https://github.com/evan/heroku-hello-world-tests/raw/master/results_1-latency.png"><img title="latency-results_11" src="https://github.com/evan/heroku-hello-world-tests/raw/master/results_1-latency.png?w=540" alt="" width="540" height="405" /></a><a href="https://github.com/evan/heroku-hello-world-tests/raw/master/results_4-latency.png"><img title="latency-results_4" src="https://github.com/evan/heroku-hello-world-tests/raw/master/results_4-latency.png?w=540" alt="" width="540" height="405" /></a><a href="https://github.com/evan/heroku-hello-world-tests/raw/master/results_7-latency.png"><img src="https://github.com/evan/heroku-hello-world-tests/raw/master/results_7-latency.png?w=540" alt="" width="540" height="405" /></a></p>
<p>Latency was essentially equivalent across all the stacks—C/Accept and Bottle excepted. Again, we see a non-linear performance falloff as dynos increases.</p>
<p>The latency ceiling at 100ms in the first two graphs is caused by Heroku&#8217;s load-shedding 500s; ideally <code>httperf</code> would exclude those from the report.</p>
<h2>using autobench</h2>
<p><a href="http://www.xenoclast.org/autobench/">Autobench</a> is a tool that automates running <code>httperf</code> at increasing rates. I like it a lot, despite (or because) of its ancient Perl-ness. A few modifications were necessary to make it more useful.</p>
<ul>
<li>Adding a retry loop around the system call to <code>httperf</code>, because sometimes it would wedge, get killed by my supervisor script, and then <code>autobench</code> would return empty data.</li>
<li>The addition of <code>--hog</code> to the <code>httperf</code> arguments.</li>
<li>Fixing the error percentage to divide by connections only, instead of by HTTP responses, which makes no sense when issuing multiple requests per connection.</li>
<li>Only counting HTTP status code 200 as a successful reply.</li>
</ul>
<p>I am not sure what happens that wedges <code>httperf</code>. Bottle was particularly nasty about this. At this point I should probably rewrite <code>autobench</code> in Ruby and merge it with my supervisor script, and also have it drive <a href="https://github.com/mariusaeriksen/hummingbird">hummingbird</a> which appears to be more modern and controllable than <code>httperf</code>.</p>
<h2>using httperf</h2>
<p><a href="http://code.google.com/p/httperf/">Httperf</a> is also old and crufty, but in C. In order to avoid lots of <code>fd-unavail</code> errors, you have to make sure that your Linux headers <a href="http://gom-jabbar.org/articles/2009/02/04/httperf-and-file-descriptors">set FD_SETSIZE large enough</a>. For the Amazon AMI:</p>
<pre>/usr/include/bits/typesizes.h:#define __FD_SETSIZE 65535
/usr/include/linux/posix_types.h:#define __FD_SETSIZE 65535</pre>
<p>Fix the <code>--hog</code> bug in <a href="http://code.google.com/p/httperf/issues/attachmentText?id=15&amp;aid=150000000&amp;name=httperf-0.9.0-hogfix.patch&amp;token=6d1c86ff869b68ec6b06b51adee5f853">httperf itself</a>, and also drop the sample rate to 0.5:</p>
<pre>src/httperf.c:#define RATE_INTERVAL 0.5</pre>
<p>You can grab the pre-compiled tools below if you don&#8217;t want to bother with updating the headers or source manually.</p>
<p>Finally, you need to make sure that your <code>ulimits</code> are ok:</p>
<pre>/etc/security/limits.conf:* hard nofile 65535</pre>
<h2>sources</h2>
<p>My <a href="https://github.com/evan/heroku-hello-world-tests/blob/master/benchmark.rb">benchmark supervisor</a>, pre-compiled <a href="https://github.com/evan/heroku-hello-world-tests/blob/master/tools.tar.gz">tools</a>, and <a href="https://github.com/evan/heroku-hello-world-tests/blob/master/chart.rb">charting script</a>, as well as all the raw data generated by the test, are on <a href="https://github.com/evan/heroku-hello-world-tests/">Github</a>. Please pardon my child-like R.</p>
<p>Hello-world sources are here:</p>
<ul>
<li><a href="https://github.com/jamesward/hellojavaheroku">Java/Jetty</a></li>
<li><a href="https://github.com/jamesward/hellojavawebapprunner">Java/Tomcat</a></li>
<li><a href="http://devcenter.heroku.com/articles/node-js">JS/Node</a></li>
<li><a href="https://github.com/kennethreitz/bottle-helloworld">Python/Bottle</a></li>
<li><a href="http://devcenter.heroku.com/articles/ruby">Ruby/Sinatra</a></li>
<li><a href="http://devcenter.heroku.com/articles/scala">Scala/Finagle</a></li>
<li><a href="http://rosettacode.org/wiki/Hello_world/Web_server#C">C/Accept</a> (A libevent implementation would be more representative.)</li>
</ul>
<p>All the testing ended up costing me $48.52 on Heroku and $23.25 on AWS. I would advise against repeating it to avoid troubling the Heroku ops team, but maybe if you have a real application to test&#8230;</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/evanweaver.wordpress.com/2137/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/evanweaver.wordpress.com/2137/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/evanweaver.wordpress.com/2137/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/evanweaver.wordpress.com/2137/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/evanweaver.wordpress.com/2137/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/evanweaver.wordpress.com/2137/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/evanweaver.wordpress.com/2137/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/evanweaver.wordpress.com/2137/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/evanweaver.wordpress.com/2137/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/evanweaver.wordpress.com/2137/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/evanweaver.wordpress.com/2137/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/evanweaver.wordpress.com/2137/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/evanweaver.wordpress.com/2137/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/evanweaver.wordpress.com/2137/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.evanweaver.com&amp;blog=18067431&amp;post=2137&amp;subd=evanweaver&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.evanweaver.com/2012/02/29/hello-heroku-world/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">evanweaver</media:title>
		</media:content>

		<media:content url="https://github.com/evan/heroku-hello-world-tests/raw/master/results_1-throughput.png?w=540" medium="image">
			<media:title type="html">throughput-results_1</media:title>
		</media:content>

		<media:content url="https://github.com/evan/heroku-hello-world-tests/raw/master/results_4-throughput.png?w=540" medium="image">
			<media:title type="html">throughput-results_4</media:title>
		</media:content>

		<media:content url="https://github.com/evan/heroku-hello-world-tests/raw/master/results_7-throughput.png?w=540" medium="image" />

		<media:content url="https://github.com/evan/heroku-hello-world-tests/raw/master/results_1-latency.png?w=540" medium="image">
			<media:title type="html">latency-results_11</media:title>
		</media:content>

		<media:content url="https://github.com/evan/heroku-hello-world-tests/raw/master/results_4-latency.png?w=540" medium="image">
			<media:title type="html">latency-results_4</media:title>
		</media:content>

		<media:content url="https://github.com/evan/heroku-hello-world-tests/raw/master/results_7-latency.png?w=540" medium="image" />
	</item>
		<item>
		<title>ideal hdtv settings for xbox 360</title>
		<link>http://blog.evanweaver.com/2012/01/10/ideal-hdtv-settings-for-xbox-360/</link>
		<comments>http://blog.evanweaver.com/2012/01/10/ideal-hdtv-settings-for-xbox-360/#comments</comments>
		<pubDate>Tue, 10 Jan 2012 21:34:02 +0000</pubDate>
		<dc:creator>evan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.evanweaver.com/?p=2106</guid>
		<description><![CDATA[My XBox 360 broke, and since my new one supported HDMI, I reworked the connection to the TV (a Samsung PN50A450 plasma). It&#8217;s tricky to get the best performance out of the combination so I wanted to mention it here. scalers Even though the HDMI connection is digital, both the XBox and the TV have [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.evanweaver.com&amp;blog=18067431&amp;post=2106&amp;subd=evanweaver&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>My XBox 360 broke, and since my new one supported HDMI, I reworked the connection to the TV (a Samsung PN50A450 plasma). It&#8217;s tricky to get the best performance out of the combination so I wanted to mention it here.</p>
<h2>scalers</h2>
<p>Even though the HDMI connection is digital, both the XBox and the TV have hardware scalers that degrade the signal. The conversion chain works like this:</p>
<p style="text-align:left;padding-left:30px;">Game resolution (for Battlefield 3, <code>704p</code>) → XBox HD resolution (for standard HD, <code>720p</code>) → TV native resolution (for this Samsung, <code>768p</code>)</p>
<p style="text-align:left;">Remember the XBox is essentially a Windows PC and games can choose <a href="http://forum.beyond3d.com/showthread.php?t=46241">whatever resolution they please</a>. Now, in a normal PC, the resolution requested by the game would be transmitted directly to the monitor, and the monitor&#8217;s scaler would scale it. If the game chooses the monitor&#8217;s native resolution then there is no scaling.</p>
<p style="text-align:left;">Also remember that a 720p-labeled TV doesn&#8217;t necessarily mean the TV&#8217;s native resolution is <code>720p</code>. It&#8217;s just <code>720p</code> &#8220;class&#8221;.</p>
<p style="text-align:left;">We can&#8217;t eliminate scaling entirely because we can&#8217;t change the game&#8217;s resolution, but we can still remove one scaler from the chain by having the XBox scale to the native TV resolution. When that happens, the Samsung shuts off its internal scaler (which also handles some post-processing effects). This gives us much sharper detail and reduces the notorious HDTV display latency.</p>
<p style="text-align:left;">How to do it:</p>
<ol>
<li>Connect the XBox to the TV via HDMI on <code>HDMI channel 2</code>.</li>
<li>Go into <code>Settings</code> → <code>Console Settings</code> → <code>Display</code> → <code>HDTV Settings</code> on the XBox and choose <code>1360 x 768</code>. If the setting isn&#8217;t available, it means you&#8217;re connected to the wrong HDMI port.</li>
</ol>
<p><a href="http://evanweaver.files.wordpress.com/2012/01/6675101191_43ded9c74d.jpg"><img class="aligncenter size-full wp-image-2109" title="Xbox 360 HDTV Display Settings" src="http://evanweaver.files.wordpress.com/2012/01/6675101191_43ded9c74d.jpg" alt="" width="490" height="312" /></a></p>
<p>Crispy pixels! This configuration also works for VGA output if your XBox doesn&#8217;t support HDMI.</p>
<p>You can also tell that you&#8217;re running at the native resolution via the TV&#8217;s menu, because the <code>Detailed Settings</code> option will be grayed out. This is because the TV&#8217;s scaler is not running.</p>
<h2>colors</h2>
<p>Now we need to open up the color response range of the TV while it&#8217;s in native resolution in order to return to high contrast. Since the scaler/post-processor is not running, my TV at least can&#8217;t do the usual 16-235 levels remapping for video signals.</p>
<p>Go into the service menu on the Samsung. (Dangerous! Stay away from anything that says &#8220;calibration&#8221; or your TV can become unusable).</p>
<p><a href="http://evanweaver.files.wordpress.com/2012/01/6675783291_9c02233f61.jpg"><img class="aligncenter size-full wp-image-2128" title="Samsung PN50A450 Service Menu" src="http://evanweaver.files.wordpress.com/2012/01/6675783291_9c02233f61.jpg" alt="" width="478" height="368" /></a></p>
<ol>
<li>With the TV off, press <code>MUTE 1 8 2 POWER</code> on the remote.</li>
<li>Using the up and down menu keys, choose <code>ADC Target</code>.</li>
<li>Use the following settings for <code>1st PC</code>, <code>2nd PC</code>, and <code>2nd HDMI</code>:
<ol>
<li><code>Low: 0</code></li>
<li><code>High: 255</code></li>
<li><code>Delta: 0</code></li>
</ol>
</li>
<li>Press <code>MUTE MUTE POWER</code> on the remote to save your settings.</li>
</ol>
<p>&nbsp;<br />
Go into <code>Settings</code> → <code>Console Settings</code> → <code>Display</code> → <code>Reference Levels</code> on the XBox and set it to <code>Expanded</code>. Also set <code>HDMI Color Space</code> to <code>RGB</code>.</p>
<h2>references</h2>
<ul>
<li>PN50A450 <a href="http://www.avsforum.com/avs-vb/showthread.php?t=1019776">owner&#8217;s thread</a> on AVS Forum</li>
<li>XBox 360 <a href="http://www.highdefforum.com/gaming-systems/84647-xbox-360-display-settings-hdmi-color-reference-levels.html">color levels</a> on High Def Forum</li>
</ul>
<p>Also note that the Samsung service menu will display the resolution the TV is running at, which is handy.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/evanweaver.wordpress.com/2106/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/evanweaver.wordpress.com/2106/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/evanweaver.wordpress.com/2106/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/evanweaver.wordpress.com/2106/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/evanweaver.wordpress.com/2106/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/evanweaver.wordpress.com/2106/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/evanweaver.wordpress.com/2106/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/evanweaver.wordpress.com/2106/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/evanweaver.wordpress.com/2106/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/evanweaver.wordpress.com/2106/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/evanweaver.wordpress.com/2106/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/evanweaver.wordpress.com/2106/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/evanweaver.wordpress.com/2106/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/evanweaver.wordpress.com/2106/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.evanweaver.com&amp;blog=18067431&amp;post=2106&amp;subd=evanweaver&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.evanweaver.com/2012/01/10/ideal-hdtv-settings-for-xbox-360/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">evanweaver</media:title>
		</media:content>

		<media:content url="http://evanweaver.files.wordpress.com/2012/01/6675101191_43ded9c74d.jpg" medium="image">
			<media:title type="html">Xbox 360 HDTV Display Settings</media:title>
		</media:content>

		<media:content url="http://evanweaver.files.wordpress.com/2012/01/6675783291_9c02233f61.jpg" medium="image">
			<media:title type="html">Samsung PN50A450 Service Menu</media:title>
		</media:content>
	</item>
		<item>
		<title>memcached gem performance across VMs</title>
		<link>http://blog.evanweaver.com/2011/09/23/memcached-gem-performance-across-vms/</link>
		<comments>http://blog.evanweaver.com/2011/09/23/memcached-gem-performance-across-vms/#comments</comments>
		<pubDate>Fri, 23 Sep 2011 10:22:04 +0000</pubDate>
		<dc:creator>evan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.evanweaver.com/?p=1871</guid>
		<description><![CDATA[Thanks to Evan Phoenix, memcached.gem 1.3.2 is compatible with Rubinius again. I have added Rubinius to the release QA, so it will stay this way.  The master branch is compatible with JRuby, but a JRuby segfault (as well as a mkmf bug) prevents it from working for most people. vm comparison Memcached.gem makes an unusual [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.evanweaver.com&amp;blog=18067431&amp;post=1871&amp;subd=evanweaver&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Thanks to Evan Phoenix, <a href="http://rubygems.org/gems/memcached"><code>memcached.gem</code> 1.3.2</a> is compatible with Rubinius again. I have added Rubinius to the release QA, so it will stay this way. </p>
<p>The <a href="https://github.com/fauna/memcached">master branch</a> is compatible with JRuby, but a JRuby segfault (as well as a <code>mkmf</code> bug) prevents it from working for most people.</p>
<h2>vm comparison</h2>
<p><code>Memcached.gem</code> makes an unusual benchmark case for VMs. The gem is highly optimized in general, and specially optimized for MRI. This means it will tend to not reward speedups of &#8220;dumb&#8221; aspects of MRI because it doesn&#8217;t exercise them—contrary to many micro-benchmarks.</p>
<pre>                                          user     system      total        real
JRuby-head
set: libm:ascii                       2.440000   1.760000   4.200000 (  8.284000)
get: libm:ascii                       [SEGFAULT]

RBX-head
set: libm:ascii                       1.387198   1.590912   2.978110 (  6.576674)
get: libm:ascii                       2.076829   1.705302   3.782131 (  7.237497)

REE 1.8.7-2011.03
set: libm:ascii                       1.130000   1.530000   2.660000 (  6.331992)
get: libm:ascii                       1.250000   1.540000   2.790000 (  6.142529)

Ruby 1.9.2-p290
set: libm:ascii                       0.860000   1.490000   2.350000 (  5.917467)
get: libm:ascii                       1.030000   1.580000   2.610000 (  6.238965)</pre>
<p>JRuby&#8217;s performance is surprisingly OK, but only once Hotspot has been convinced to JIT the function to native code (which the benchmark does ahead of time). Rubinius&#8217;s performance is good. Ruby 1.9.2 is the fastest.</p>
<h2>jruby client comparison</h2>
<p>Curiously, <code>memcached.gem</code> is the fastest Ruby memcached client on every VM <em>including</em> JRuby. It is 70% faster than <code>jruby-memcache-client</code>, which wraps <a href="https://github.com/gwhalin/Memcached-Java-Client/wiki/">Whalin&#8217;s Java client</a> via JRuby&#8217;s Java integration:</p>
<pre>memcached 1.3.3
remix-stash 1.1.3
jruby-memcache-client 1.7.0
dalli 1.1.2
                                          user     system      total        real
set: dalli:bin                       10.720000   7.250000  17.970000 ( 17.859000)
set: libm:ascii                       2.440000   1.760000   4.200000 (  8.284000)
set: libm:bin                         2.280000   1.960000   4.240000 (  8.600000)
set: mclient:ascii                    4.150000   3.010000   7.160000 ( 11.879000)
set: stash:bin                        5.870000   2.970000   8.840000 ( 13.677000)</pre>
<h2>conclusion</h2>
<p>This is great performance for C extensions in JRuby and Rubinius both. It&#8217;s handy that MRI&#8217;s extension interface is so simple.</p>
<p>One possible performance improvement remains in <code>memcached.gem</code> itself, which is rewriting the bundled copy of <a href="http://libmemcached.org/">libmemcached</a> to talk directly to Ruby instead of via SWIG, which introduces memory copy overhead.</p>
<p>Also, someone needs to write a faster client for JRuby; there&#8217;s no reason why binding to a good native library like Whalin&#8217;s or <a href="http://code.google.com/p/xmemcached/">xmemcached</a> should be slow. It should be possible to equal the speed of <code>memcached.gem</code> on Ruby 1.9.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/evanweaver.wordpress.com/1871/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/evanweaver.wordpress.com/1871/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/evanweaver.wordpress.com/1871/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/evanweaver.wordpress.com/1871/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/evanweaver.wordpress.com/1871/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/evanweaver.wordpress.com/1871/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/evanweaver.wordpress.com/1871/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/evanweaver.wordpress.com/1871/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/evanweaver.wordpress.com/1871/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/evanweaver.wordpress.com/1871/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/evanweaver.wordpress.com/1871/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/evanweaver.wordpress.com/1871/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/evanweaver.wordpress.com/1871/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/evanweaver.wordpress.com/1871/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.evanweaver.com&amp;blog=18067431&amp;post=1871&amp;subd=evanweaver&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.evanweaver.com/2011/09/23/memcached-gem-performance-across-vms/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">evanweaver</media:title>
		</media:content>
	</item>
		<item>
		<title>simplicity</title>
		<link>http://blog.evanweaver.com/2011/07/25/simplicity/</link>
		<comments>http://blog.evanweaver.com/2011/07/25/simplicity/#comments</comments>
		<pubDate>Tue, 26 Jul 2011 06:49:58 +0000</pubDate>
		<dc:creator>evan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.evanweaver.com/?p=1996</guid>
		<description><![CDATA[Maximizing simplicity is the only guaranteed way to minimize software maintenance. Other techniques exist, but are situational. No complex system will be cheaper to maintain than a simple one that meets the same goals. &#8216;Simple&#8217;, pedantically, means &#8216;not composed of parts&#8217;. However! Whatever system you are working on may already be a part of a whole. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.evanweaver.com&amp;blog=18067431&amp;post=1996&amp;subd=evanweaver&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Maximizing simplicity is the only guaranteed way to minimize software maintenance. Other techniques exist, but are situational. No complex system will be cheaper to maintain than a simple one that meets the same goals.</p>
<p>&#8216;Simple&#8217;, pedantically, means &#8216;not composed of parts&#8217;. However! Whatever system you are working on may already be a part of a whole. Your output should reduce the number and size of parts <em>over all</em>, not just in your own project domain.</p>
<div id="attachment_2000" class="wp-caption aligncenter" style="width: 159px"><a href="http://en.wikipedia.org/wiki/Electra"><img class="size-medium wp-image-2000 " title="Electra at the Tomb of Agamemnon" src="http://evanweaver.files.wordpress.com/2011/07/1869_frederic_leighton_-_electra_at_the_tomb_of_agamemnon-1.jpg?w=149&#038;h=300" alt="" width="149" height="300" /></a><p class="wp-caption-text">Electra at the Tomb of Agamemnon, Frederic Leighton</p></div>
<p>I&#8217;ve started asking myself, &#8220;does this add the least amount of new code?&#8221; A system in isolation may be quite simple, but if it duplicates existing functionality, it has increased complexity. The ideal change is <em>subtractive</em>, reducing the total amount of code: by collapsing features together, removing configuration, or merging overlapping components.</p>
<p>Better to put your configuration in version control you already understand, than introduce a remote discovery server. Better to use the crufty RPC library you already have, than introduce a new one with a handy feature—unless you entirely replace the old one.</p>
<p>Beware the daughter that aspires not to the throne of her mother.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/evanweaver.wordpress.com/1996/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/evanweaver.wordpress.com/1996/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/evanweaver.wordpress.com/1996/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/evanweaver.wordpress.com/1996/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/evanweaver.wordpress.com/1996/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/evanweaver.wordpress.com/1996/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/evanweaver.wordpress.com/1996/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/evanweaver.wordpress.com/1996/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/evanweaver.wordpress.com/1996/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/evanweaver.wordpress.com/1996/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/evanweaver.wordpress.com/1996/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/evanweaver.wordpress.com/1996/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/evanweaver.wordpress.com/1996/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/evanweaver.wordpress.com/1996/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.evanweaver.com&amp;blog=18067431&amp;post=1996&amp;subd=evanweaver&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.evanweaver.com/2011/07/25/simplicity/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">evanweaver</media:title>
		</media:content>

		<media:content url="http://evanweaver.files.wordpress.com/2011/07/1869_frederic_leighton_-_electra_at_the_tomb_of_agamemnon-1.jpg?w=149" medium="image">
			<media:title type="html">Electra at the Tomb of Agamemnon</media:title>
		</media:content>
	</item>
		<item>
		<title>performance engineering at twitter</title>
		<link>http://blog.evanweaver.com/2011/04/27/performance-engineering-at-twitter/</link>
		<comments>http://blog.evanweaver.com/2011/04/27/performance-engineering-at-twitter/#comments</comments>
		<pubDate>Wed, 27 Apr 2011 19:30:30 +0000</pubDate>
		<dc:creator>evan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.evanweaver.com/?p=1919</guid>
		<description><![CDATA[A few weeks ago I gave a performance engineering talk at QCon Beijing/Tokyo. The abstract and slides are below. abstract Twitter has undergone exponential growth with very limited staff, hardware, and time. This talk discusses principles by which the wise performance engineer can make dramatic improvements in a constrained environment. Of course, these apply to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.evanweaver.com&amp;blog=18067431&amp;post=1919&amp;subd=evanweaver&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>A few weeks ago I gave a performance engineering talk at QCon Beijing/Tokyo. The abstract and slides are below.</p>
<h2>abstract</h2>
<blockquote style="padding:0 40px;"><p>Twitter has undergone exponential growth with very limited staff, hardware, and time. This talk discusses principles by which the wise performance engineer can make dramatic improvements in a constrained environment. Of course, these apply to any systems architect who wants to do more with less. Principles will be illustrated with concrete examples of successes and lessons learned from Twitter&#8217;s development and operations history.</p></blockquote>
<h2>slides</h2>
<iframe frameborder="0" width="558" height="408" src="http://wpcomwidgets.com/?id=preziEmbed_x_cw02rviaqq&amp;name=preziEmbed_x_cw02rviaqq&amp;src=http%3A%2F%2Fprezi.com%2Fbin%2Fpreziloader.swf&amp;type=application%2Fx-shockwave-flash&amp;allowfullscreen=true&amp;allowscriptaccess=always&amp;width=550&amp;height=400&amp;bgcolor=%23ffffff&amp;flashvars=prezi_id%3Dx_cw02rviaqq%26lock_to_path%3D0%26color%3Dffffff%26autoplay%3Dno%26autohide_ctrls%3D0&amp;_tag=gigya&amp;_hash=fa7337d57c0aac708b56d8c14a848ac5" id="fa7337d57c0aac708b56d8c14a848ac5"></iframe>
<p><a title="QCon Beijing/Tokyo 2011" href="http://prezi.com/x_cw02rviaqq/performance-engineering-at-twitter/">Performance Engineering at Twitter</a> on <a href="http://prezi.com">Prezi</a></p>
<p>This is the first time I&#8217;ve used <a href="http://prezi.com">Prezi</a>; the non-linear flow is compelling.</p>
<h2>see it again sam</h2>
<p>I will be giving the same talk this fall at <a href="http://www.qconsp.com/">QCon São Paulo</a> and <a href="http://qconsf.com/">QCon San Francisco</a>, so you can catch it there, and I think eventually the video will be online. This was also my first time speaking publicly in two years. Tons of new things to share with the world!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/evanweaver.wordpress.com/1919/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/evanweaver.wordpress.com/1919/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/evanweaver.wordpress.com/1919/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/evanweaver.wordpress.com/1919/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/evanweaver.wordpress.com/1919/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/evanweaver.wordpress.com/1919/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/evanweaver.wordpress.com/1919/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/evanweaver.wordpress.com/1919/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/evanweaver.wordpress.com/1919/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/evanweaver.wordpress.com/1919/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/evanweaver.wordpress.com/1919/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/evanweaver.wordpress.com/1919/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/evanweaver.wordpress.com/1919/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/evanweaver.wordpress.com/1919/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.evanweaver.com&amp;blog=18067431&amp;post=1919&amp;subd=evanweaver&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.evanweaver.com/2011/04/27/performance-engineering-at-twitter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">evanweaver</media:title>
		</media:content>
	</item>
		<item>
		<title>distributed systems primer, updated</title>
		<link>http://blog.evanweaver.com/2010/08/12/distributed-systems-primer-update/</link>
		<comments>http://blog.evanweaver.com/2010/08/12/distributed-systems-primer-update/#comments</comments>
		<pubDate>Thu, 12 Aug 2010 08:00:00 +0000</pubDate>
		<dc:creator>evan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.evanweaver.com/?p=117</guid>
		<description><![CDATA[Well, it&#8217;s been a long time. But! I have five papers to add to my original distributed systems primer: coordination CRDTs: Consistency Without Concurrency Control, Mihai Letia, Nuno Preguiça, and Marc Shapiro, 2009. Guaranteeing eventual consistency by constraining your data structure, rather than adding heavyweight distributed algorithms. FlockDB works this way. partitioning The Little Engines [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.evanweaver.com&amp;blog=18067431&amp;post=117&amp;subd=evanweaver&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Well, it&#8217;s been a long time. But! I have five papers to add to my original <a href="http://blog.evanweaver.com/articles/2009/05/04/distributed-systems-primer/">distributed systems primer</a>:</p>
<h2>coordination</h2>
<p style="margin-bottom:2px;"><a href="http://pagesperso-systeme.lip6.fr/Marc.Shapiro/papers/RR-6956.pdf">CRDTs: Consistency Without Concurrency Control</a>, Mihai Letia, Nuno Preguiça, and Marc Shapiro, 2009.</p>
<p>Guaranteeing eventual consistency by constraining your data structure, rather than adding heavyweight distributed algorithms. <a href="http://github.com/twitter/flockdb">FlockDB</a> works this way.</p>
<h2>partitioning</h2>
<p style="margin-bottom:2px;"><a href="http://ccr.sigcomm.org/online/files/p375.pdf">The Little Engines That Could: Scaling Online Social Networks</a>, Josep M. Pujol, Vijay Erramilli, Georgos Siganos, Xiaoyuan Yang Nikos Laoutaris, Parminder Chhabra, and Pablo Rodriguez, 2010.</p>
<p>Optimally partitioning overlapping graphs through lazy replication. Think of applying this technique at a cluster level, not just a server level.</p>
<p style="margin-bottom:2px;"><a href="http://research.yahoo.com/files/sigmod278-silberstein.pdf">Feeding Frenzy: Selectively Materializing Users&#8217; Event Feeds</a>, Adam Silberstein, Jeff Terrace, Brian F. Cooper, and Raghu Ramakrishnan, 2010.</p>
<p>Judicious session management and application of domain knowledge allow for optimal high-velocity mailbox updates in a memory grid. Twitter&#8217;s timeline system works this way.</p>
<h2>systems integration</h2>
<p style="margin-bottom:2px;"><a href="http://static.googleusercontent.com/external_content/untrusted_dlcp/research.google.com/en/us/archive/papers/dapper-2010-1.pdf">Dapper, a Large-Scale Distributed Systems Tracing Infrastructure</a>, Benjamin H. Sigelman, Luiz André Barroso, Mike Burrows, Pat Stephenson, Manoj Plakal, Donald Beaver, Saul Jaspan, and Chandan Shanbhag, 2010.</p>
<p>Add a transaction-tracking, sampling profiler to a reusable RPC framework and get full stack visibility without performance degradation.</p>
<p style="margin-bottom:2px;"><a href="http://www.percona.com/files/white-papers/forecasting-mysql-scalability.pdf">Forecasting MySQL Scalability with the Universal Scalability Law</a>, Baron Schwartz and Ewen Fortune, 2010.</p>
<p>An example of data-driven scalability modeling in a concurrent system, via a least-squares regression approach.</p>
<p>Happy scaling. Make sure to read the <a href="http://blog.evanweaver.com/articles/2009/05/04/distributed-systems-primer/">original post</a> if you haven&#8217;t.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/evanweaver.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/evanweaver.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/evanweaver.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/evanweaver.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/evanweaver.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/evanweaver.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/evanweaver.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/evanweaver.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/evanweaver.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/evanweaver.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/evanweaver.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/evanweaver.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/evanweaver.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/evanweaver.wordpress.com/117/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.evanweaver.com&amp;blog=18067431&amp;post=117&amp;subd=evanweaver&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.evanweaver.com/2010/08/12/distributed-systems-primer-update/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">evanweaver</media:title>
		</media:content>
	</item>
		<item>
		<title>object allocations on the web</title>
		<link>http://blog.evanweaver.com/2009/10/21/object-allocations-on-the-web/</link>
		<comments>http://blog.evanweaver.com/2009/10/21/object-allocations-on-the-web/#comments</comments>
		<pubDate>Wed, 21 Oct 2009 08:00:00 +0000</pubDate>
		<dc:creator>evan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.evanweaver.com/?p=116</guid>
		<description><![CDATA[How many objects does a Rails request allocate? Here are Twitter&#8217;s numbers: API: 22,700 objects per request Website: 67,500 objects per request Daemons: 27,900 objects per action I want them to be lower. Overall, we burn 20% of our front-end CPU on garbage collection, which seems high. Each process handles ~29,000 requests before getting killed [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.evanweaver.com&amp;blog=18067431&amp;post=116&amp;subd=evanweaver&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>How many objects does a Rails request allocate? Here are Twitter&#8217;s numbers:</p>
<ul>
<li>
<b>API</b>: 22,700 objects per request</li>
<li>
<b>Website</b>: 67,500 objects per request </li>
<li>
<b>Daemons</b>: 27,900 objects per action</li>
</ul>
<p>I want them to be lower. Overall, we burn 20% of our front-end CPU on garbage collection, which seems high. Each process handles ~29,000 requests before getting killed by the memory limit, and the GC is triggered about every 30 requests.</p>
<p>In memory-managed languages, you pay a performance penalty at object allocation time and also at collection time. Since Ruby lacks a generational GC (although there are <a href="http://github.com/authorNari/patch_bag/blob/master/ruby/gc_partial_longlife_r23386.patch">patches</a> available), the collection penalty is linear with the number of objects on the heap.</p>
<h2>a note about structs and immediates</h2>
<p>In Ruby 1.8, <code>Struct</code> instances <a href="http://eigenclass.org/R2/writings/object-size-ruby-ocaml">use fewer bytes</a> and allocate less objects than  <code>Hash</code> and friends. This can be an optimization opportunity in circumstances where the <code>Struct</code> class is reusable.</p>
<p>A little bit of code shows the difference (you need <a href="http://www.rubyenterpriseedition.com/">REE</a> or Sylvain Joyeux&#8217;s <a href="http://rubyforge.org/tracker/download.php/426/1700/11497/2087/ruby-track-alloc.patch">patch</a> to track allocations):</p>
<pre>
GC.enable_stats
def sizeof(obj)
  GC.clear_stats
  obj.clone
  puts "#{GC.num_allocations} allocations"
  GC.clear_stats
  obj.clone
  puts "#{GC.allocated_size} bytes"
end
</pre>
<p>Let&#8217;s try it:</p>
<pre>
&gt;&gt; Struct.new("Test", :a, :b, :c)
&gt;&gt; struct = Struct::Test.new(1,2,3)
=&gt; #&lt;struct Struct::Test a=1, b=2, c=3&gt;
&gt;&gt; sizeof(struct)
1 allocations
24 bytes

&gt;&gt; hash = {:a =&gt; 1, :b =&gt; 2, :c =&gt; 3}
&gt;&gt; sizeof(hash)
5 allocations
208 bytes
</pre>
<p>Watch out, though. The <code>Struct</code> class itself is expensive:</p>
<pre>
&gt;&gt; sizeof(Struct::Test)
29 allocations
1216 bytes
</pre>
<p>In my understanding, each key in a <code>Hash</code> is a <code>VALUE</code> pointer to another object, while each slot in a <code>Struct</code> is merely a named position.</p>
<p>Immediate types (<code>Fixnum</code>, <code>nil</code>, <code>true</code>, <code>false</code>, and <code>Symbol</code>) don&#8217;t allocate, except for <code>Symbol</code>. <code>Symbol</code> is interned and keeps its string representations on a special heap that is not garbage-collected.</p>
<h2>your turn</h2>
<p>If you have allocation counts from a production web application, I would be delighted to know them. I am especially interested in Python, PHP, and Java.</p>
<p>Python should be about the same as Ruby. PHP, though, discards the entire heap per-request in some configurations, so collection can be  dramatically cheaper. And I would expect Java to allocate fewer objects and have a more efficient collection cycle.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/evanweaver.wordpress.com/116/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/evanweaver.wordpress.com/116/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/evanweaver.wordpress.com/116/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/evanweaver.wordpress.com/116/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/evanweaver.wordpress.com/116/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/evanweaver.wordpress.com/116/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/evanweaver.wordpress.com/116/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/evanweaver.wordpress.com/116/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/evanweaver.wordpress.com/116/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/evanweaver.wordpress.com/116/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/evanweaver.wordpress.com/116/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/evanweaver.wordpress.com/116/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/evanweaver.wordpress.com/116/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/evanweaver.wordpress.com/116/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.evanweaver.com&amp;blog=18067431&amp;post=116&amp;subd=evanweaver&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.evanweaver.com/2009/10/21/object-allocations-on-the-web/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">evanweaver</media:title>
		</media:content>
	</item>
		<item>
		<title>scribe client</title>
		<link>http://blog.evanweaver.com/2009/09/30/scribe-client-gem/</link>
		<comments>http://blog.evanweaver.com/2009/09/30/scribe-client-gem/#comments</comments>
		<pubDate>Wed, 30 Sep 2009 08:00:00 +0000</pubDate>
		<dc:creator>evan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.evanweaver.com/?p=115</guid>
		<description><![CDATA[I&#8217;ve released Scribe 0.1, a Ruby client for the Scribe remote log server. sudo gem install scribe Usage is simple: client = Scribe.new client.log("I'm lonely in a crowded room.", "Rails") Documentation is here. about scribe The primary benefit of Scribe over something like syslog-ng is increased scalability, because of Scribe&#8217;s fundamentally distributed architecture. Scribe also [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.evanweaver.com&amp;blog=18067431&amp;post=115&amp;subd=evanweaver&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve released Scribe 0.1, a Ruby client for the <a href="http://sourceforge.net/apps/mediawiki/scribeserver/index.php?title=Main_Page">Scribe</a>  remote log server.</p>
<pre>sudo gem install scribe</pre>
<p>Usage is simple:</p>
<pre>
client = Scribe.new
client.log("I'm lonely in a crowded room.", "Rails")
</pre>
<p>Documentation is <a href="http://evanweaver.files.wordpress.com/2010/12/doc/fauna/scribe/files/README.html">here</a>.</p>
<h2>about scribe</h2>
<p>The primary benefit of Scribe over something like <a href="http://www.balabit.com/network-security/syslog-ng/">syslog-ng</a> is  increased scalability, because of Scribe&#8217;s fundamentally distributed architecture. Scribe also does away with the legacy  <code>syslog</code> alert levels, and lets you define more application-appropriate categories on the fly instead.</p>
<p>Dmytro Shteflyuk has <a href="http://kpumuk.info/development/installing-and-using-scribe-with-ruby-on-mac-os/">good article</a> about installing the Scribe  server itself on OS X. It would be nice if someone would put it in MacPorts, but it may be blocked on the  release of Thrift.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/evanweaver.wordpress.com/115/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/evanweaver.wordpress.com/115/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/evanweaver.wordpress.com/115/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/evanweaver.wordpress.com/115/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/evanweaver.wordpress.com/115/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/evanweaver.wordpress.com/115/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/evanweaver.wordpress.com/115/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/evanweaver.wordpress.com/115/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/evanweaver.wordpress.com/115/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/evanweaver.wordpress.com/115/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/evanweaver.wordpress.com/115/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/evanweaver.wordpress.com/115/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/evanweaver.wordpress.com/115/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/evanweaver.wordpress.com/115/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.evanweaver.com&amp;blog=18067431&amp;post=115&amp;subd=evanweaver&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.evanweaver.com/2009/09/30/scribe-client-gem/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">evanweaver</media:title>
		</media:content>
	</item>
		<item>
		<title>ree</title>
		<link>http://blog.evanweaver.com/2009/09/24/ree/</link>
		<comments>http://blog.evanweaver.com/2009/09/24/ree/#comments</comments>
		<pubDate>Thu, 24 Sep 2009 08:00:00 +0000</pubDate>
		<dc:creator>evan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.evanweaver.com/?p=114</guid>
		<description><![CDATA[We recently migrated Twitter from a custom Ruby 1.8.6 build to a Ruby Enterprise Edition release candidate, courtesy of Phusion. Our primary motivation was the integration of Brent&#8217;s MBARI patches, which increase memory stability. Some features of REE have no effect on our codebase, but we definitely benefit from the MBARI patchset, the Railsbench tunable [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.evanweaver.com&amp;blog=18067431&amp;post=114&amp;subd=evanweaver&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>We recently migrated Twitter from a custom Ruby 1.8.6 build to a <a href="http://www.rubyenterpriseedition.com/">Ruby Enterprise Edition</a> release candidate, courtesy of <a href="http://www.phusion.nl/">Phusion</a>. Our primary motivation was the integration of Brent&#8217;s <a href="http://github.com/brentr/matzruby/tree/v1_8_7_72-mbari">MBARI patches</a>, which increase memory stability.</p>
<p>Some features of REE have no effect on our codebase, but we definitely benefit from the MBARI patchset, the Railsbench tunable GC, and the various leak fixes in 1.8.7p174. These are difficult to integrate and Phusion has done a fine job.</p>
<h2>testing notes</h2>
<p>I ran into an interesting issue. Ruby is faster if compiled with <code>-Os</code> (optimize for size) than with <code>-O2</code> or <code>-O3</code> (optimize for speed). Hongli pointed out that Ruby has poor instruction locality and benefits most from squeezing tightly into the instruction cache. This is an unusual phenomenon, although probably more common in interpreters and virtual machines than in &#8220;standard&#8221; C programs.</p>
<p>I also tested a build that included Joe Damato&#8217;s <a href="http://timetobleed.com/fixing-threads-in-ruby-18-a-2-10x-performance-boost/">heaped thread frames</a>, but it would hang Mongrel in <code>rb_thread_schedule()</code> after the first GC run, which is not exactly what we want. Hopefully this can be integrated later.</p>
<h2>benchmarks</h2>
<p>I ran a suite of benchmarks via <a href="http://www.xenoclast.org/autobench/">Autobench/httperf</a> and plotted them with <a href="http://plot.micw.eu/">Plot</a>. The hardware was a 4-core Xeon machine with RHEL5, running 8 Mongrels balanced behind Apache 2.2. I made a typical API request that is answered primarily from composed caches.</p>
<div style="margin:0;padding:0;"><img src="http://evanweaver.files.wordpress.com/2010/12/ree_benchmark.png"/></div>
<p>As usual, we see that <a href="http://blog.evanweaver.com/articles/2009/04/09/ruby-gc-tuning/">tuning the GC parameters</a> has the greatest impact on throughput, but there is a definite gain from switching to the REE bundle. It&#8217;s also interesting how much the standard deviation is improved by the GC settings. (Some data points are skipped due to errors at high concurrency.)</p>
<h2>upgrading</h2>
<p>Moving from 1.8.6 to REE 1.8.7 was trivial, but moving to 1.9 will be more of an ordeal. It will be interesting to see what patches are still necessary on 1.9. Many of them are getting upstreamed, but some things (such as <a href="http://goog-perftools.sourceforge.net/doc/tcmalloc.html">tcmalloc</a>) will probably remain only available from 3rd parties.</p>
<p>All in all, good times in MRI land.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/evanweaver.wordpress.com/114/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/evanweaver.wordpress.com/114/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/evanweaver.wordpress.com/114/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/evanweaver.wordpress.com/114/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/evanweaver.wordpress.com/114/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/evanweaver.wordpress.com/114/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/evanweaver.wordpress.com/114/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/evanweaver.wordpress.com/114/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/evanweaver.wordpress.com/114/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/evanweaver.wordpress.com/114/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/evanweaver.wordpress.com/114/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/evanweaver.wordpress.com/114/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/evanweaver.wordpress.com/114/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/evanweaver.wordpress.com/114/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.evanweaver.com&amp;blog=18067431&amp;post=114&amp;subd=evanweaver&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.evanweaver.com/2009/09/24/ree/feed/</wfw:commentRss>
		<slash:comments>24</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">evanweaver</media:title>
		</media:content>

		<media:content url="http://evanweaver.files.wordpress.com/2010/12/ree_benchmark.png" medium="image" />
	</item>
		<item>
		<title>memcached gem release</title>
		<link>http://blog.evanweaver.com/2009/08/04/memcached-gem-release/</link>
		<comments>http://blog.evanweaver.com/2009/08/04/memcached-gem-release/#comments</comments>
		<pubDate>Tue, 04 Aug 2009 08:00:00 +0000</pubDate>
		<dc:creator>evan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.evanweaver.com/?p=113</guid>
		<description><![CDATA[One of the hardest gems to install is no more. It&#8217;s now easy to install! Memcached 0.15 features: Update to libmemcached 0.31.1 Bundle libmemcached itself with the gem (antifuchs) UDP connection support Unix domain socket support (hellvinz) AUTO_EJECT_HOSTS bugfixes (mattknox) Install with gem install memcached. Since libmemcached is bundled in, there are no longer any [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.evanweaver.com&amp;blog=18067431&amp;post=113&amp;subd=evanweaver&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>One of the hardest gems to install is no more. It&#8217;s now easy to install!</p>
<p><a href="http://evanweaver.files.wordpress.com/2010/12/doc/fauna/memcached">Memcached 0.15</a> features:</p>
<ul>
<li>Update to libmemcached 0.31.1</li>
<li>Bundle libmemcached itself with the gem (<a href="http://github.com/antifuchs">antifuchs</a>)</li>
<li>UDP connection support</li>
<li>Unix domain socket support (<a href="http://github.com/hellvinz/">hellvinz</a>)</li>
<li>
<code>AUTO_EJECT_HOSTS</code> bugfixes (<a href="http://github.com/mattknox">mattknox</a>)</li>
</ul>
<p>Install with <code>gem install memcached</code>. Since <a href="http://tangent.org/552/libmemcached.html">libmemcached</a> is bundled in, there are no longer any dependencies.</p>
<h2>on coordination</h2>
<p><a href="http://github.com/antifuchs">Andreas Fuchs</a> suggested several months ago that I include libmemcached itself in the gem, but at the time I resisted. I was wrong.</p>
<p>My opposition was based on the idea that libmemcached itself would be an integration point, so running multiple versions on a system would be bad.</p>
<p>In real life, the hash algorithm became the integration point, not the library itself. And since the library&#8217;s ABI kept changing, the gem always required a very specific custom build. This annoyed the public and caused extra work for my operations team, who had to make sure to upgrade both the library and the gem at the same time.</p>
<p>Updates can come thick and fast now because I don&#8217;t have to worry about publishing custom builds or waiting for the libmemcached developers to merge my patches.</p>
<p>In retrospect it seems obvious—it&#8217;s always a win to remove coordination from a system.</p>
<h2>linker woes</h2>
<p>Unfortunately, it was easier to make that decision than it was to implement it. Linux and OS X link libraries differently, and I had a lot of trouble making sure that no system-installed version of libmemcached would get linked, instead of the custom one built during <code>gem install</code>.</p>
<p>When you link a shared object, OS X seems to maintain a reference to the original <code>.dylib</code>. Linux does not, and depends on ldconfig and <code>LD_LIBRARY_PRELOAD</code> to find the object at runtime. Since you can&#8217;t modify the shell environment from within a running process, there&#8217;s no way to override <code>LD_LIBRARY_PRELOAD</code>, so I needed to statically link libmemcached into the gem&#8217;s own <code>.so</code> or <code>.bundle</code>.</p>
<p>The only way I could do this on both systems was to configure libmemcached with <code>CFLAGS=-fPIC --disable-shared</code>, rename the <code>libemcached.*</code> static object files to <code>libemcached_gem.*</code>, and pass <code>-lmemcached_gem</code> to the linker rather than <code>-lmemcached</code>. Otherwise the linker would prefer the system-installed dynamic objects, even with the correct paths and <code>-static</code> option set.</p>
<p>Note that you can check what objects a binary has linked to via <code>otool -F</code> on OS X, and <code>ldd</code> on Linux.</p>
<p>Feel free to look at the <a href="http://github.com/fauna/memcached/blob/6f2c517df97a5a6c871802d93ef56fdb4358c22c/ext/extconf.rb">extconf.rb source</a> and let me know if there&#8217;s a better way to do this.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/evanweaver.wordpress.com/113/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/evanweaver.wordpress.com/113/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/evanweaver.wordpress.com/113/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/evanweaver.wordpress.com/113/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/evanweaver.wordpress.com/113/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/evanweaver.wordpress.com/113/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/evanweaver.wordpress.com/113/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/evanweaver.wordpress.com/113/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/evanweaver.wordpress.com/113/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/evanweaver.wordpress.com/113/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/evanweaver.wordpress.com/113/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/evanweaver.wordpress.com/113/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/evanweaver.wordpress.com/113/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/evanweaver.wordpress.com/113/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.evanweaver.com&amp;blog=18067431&amp;post=113&amp;subd=evanweaver&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.evanweaver.com/2009/08/04/memcached-gem-release/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">evanweaver</media:title>
		</media:content>
	</item>
	</channel>
</rss>
