<?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>domas mituzas &#187; memory</title>
	<atom:link href="http://dom.as/tag/memory/feed/" rel="self" type="application/rss+xml" />
	<link>http://dom.as</link>
	<description></description>
	<lastBuildDate>Thu, 02 Feb 2012 21:29:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='dom.as' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://0.gravatar.com/blavatar/6e344c6e0cd7462eb056f8b98eb2cbcd?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>domas mituzas &#187; memory</title>
		<link>http://dom.as</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://dom.as/osd.xml" title="domas mituzas" />
	<atom:link rel='hub' href='http://dom.as/?pushpress=hub'/>
		<item>
		<title>Blowing up in memory</title>
		<link>http://dom.as/2011/09/25/blowing-up-in-memory/</link>
		<comments>http://dom.as/2011/09/25/blowing-up-in-memory/#comments</comments>
		<pubDate>Sun, 25 Sep 2011 16:19:38 +0000</pubDate>
		<dc:creator>Domas Mituzas</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[efficiency]]></category>
		<category><![CDATA[innodb]]></category>
		<category><![CDATA[memory]]></category>
		<category><![CDATA[partitions]]></category>

		<guid isPermaLink="false">http://dom.as/?p=1509</guid>
		<description><![CDATA[MySQL isn&#8217;t too concerned about table handler memory usage &#8211; it will allocate row size buffer thrice per each table invocation. There&#8217;s a few year old bug discussing UNION memory usage &#8211; for each mention in an union one can allocate &#8230; <a href="http://dom.as/2011/09/25/blowing-up-in-memory/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dom.as&amp;blog=190075&amp;post=1509&amp;subd=domasmituzas&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>MySQL isn&#8217;t too concerned about table handler memory usage &#8211; it will allocate row size buffer thrice per each table invocation. There&#8217;s a few year <a href="http://bugs.mysql.com/bug.php?id=44626">old bug</a> discussing UNION memory usage &#8211; for each mention in an union one can allocate nearly 200k of unaccounted memory &#8211; so a megabyte sized query can consume 7GB of RAM already.</p>
<p>Partitioning though adds even more pain here &#8211; it will allocate those three buffers per each partition, so opening a table with 1000 partitions looks like this on memory profile:</p>
<p><a href="http://domasmituzas.files.wordpress.com/2011/09/partitions-memory-usage1.png"><img class="alignnone size-medium wp-image-1507" title="Partitions memory usage" src="http://domasmituzas.files.wordpress.com/2011/09/partitions-memory-usage1.png?w=300&#038;h=239" alt="" width="300" height="239" /></a></p>
<p>Click to enlarge, and you will see 191MB sent to execute a simple single-row fetching query from a table (I filed <a href="http://bugs.mysql.com/bug.php?id=62536">a bug</a> on this).</p>
<p>There&#8217;re multiple real life situations when this is painful (e.g. any kind of server stall may lead to multiple concurrent threads reading from same table, consuming additional gigabytes or tens of gigabytes of memory). It gets even more painful when combined with UNION bug &#8211; a megabyte query on an empty table can now consume 7TB of memory and I doubt anyone has that much on their MySQL servers :-)</p>
<p>P.S. Also, <a href="http://bugs.mysql.com/bug.php?id=62535">check out</a> how much memory can be wasted for malloc overhead, once discussed <a title="Wasting InnoDB memory" href="http://dom.as/2008/05/29/wasting-innodb-memory/">here</a>.<br />
P.P.S. And <a href="http://bugs.mysql.com/bug.php?id=62534">here</a> you can see why innodb_max_dirty_pages_pct=0 doesn&#8217;t do what you&#8217;d expect.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/domasmituzas.wordpress.com/1509/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/domasmituzas.wordpress.com/1509/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/domasmituzas.wordpress.com/1509/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/domasmituzas.wordpress.com/1509/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/domasmituzas.wordpress.com/1509/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/domasmituzas.wordpress.com/1509/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/domasmituzas.wordpress.com/1509/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/domasmituzas.wordpress.com/1509/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/domasmituzas.wordpress.com/1509/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/domasmituzas.wordpress.com/1509/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/domasmituzas.wordpress.com/1509/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/domasmituzas.wordpress.com/1509/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/domasmituzas.wordpress.com/1509/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/domasmituzas.wordpress.com/1509/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dom.as&amp;blog=190075&amp;post=1509&amp;subd=domasmituzas&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dom.as/2011/09/25/blowing-up-in-memory/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c660a6eb3a4005232acb111303bef12c?s=96&#38;d=http%3A%2F%2Fs0.wp.com%2Fi%2Fmu.gif&#38;r=G" medium="image">
			<media:title type="html">domasmituzas</media:title>
		</media:content>

		<media:content url="http://domasmituzas.files.wordpress.com/2011/09/partitions-memory-usage1.png?w=300" medium="image">
			<media:title type="html">Partitions memory usage</media:title>
		</media:content>
	</item>
		<item>
		<title>Stonebraker trapped in Stonebraker &#039;fate worse than death&#039;</title>
		<link>http://dom.as/2011/07/08/stonebraker-trapped/</link>
		<comments>http://dom.as/2011/07/08/stonebraker-trapped/#comments</comments>
		<pubDate>Fri, 08 Jul 2011 09:25:12 +0000</pubDate>
		<dc:creator>Domas Mituzas</dc:creator>
				<category><![CDATA[facebook]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[disks]]></category>
		<category><![CDATA[io]]></category>
		<category><![CDATA[memory]]></category>
		<category><![CDATA[newsql]]></category>
		<category><![CDATA[rant]]></category>

		<guid isPermaLink="false">http://dom.as/?p=880</guid>
		<description><![CDATA[Oh well, I know I shouldn&#8217;t poke directly at people, but they deserve that sometimes (at least in my very personal opinion). Heck, I even gave 12h window for this not to be hot-headed opinion. Those who followed MySQL at &#8230; <a href="http://dom.as/2011/07/08/stonebraker-trapped/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dom.as&amp;blog=190075&amp;post=880&amp;subd=domasmituzas&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href='http://en.wikipedia.org/wiki/Troll_(Internet)'><img src='http://upload.wikimedia.org/wikipedia/en/thumb/7/73/Trollface.png/150px-Trollface.png' align='right' /></a></p>
<p>Oh well, I know I shouldn&#8217;t poke directly at people, but they <a href='http://gigaom.com/cloud/facebook-trapped-in-mysql-fate-worse-than-death/'>deserve</a> that sometimes (at least in my very personal opinion). Heck, I even gave 12h window for this not to be hot-headed opinion.</p>
<p>Those who followed <a href='http://facebook.com/MySQLatFacebook/'>MySQL at facebook</a> development probably know how much we focus on actual performance on top of mixed-composition I/O devices (flashcache, etc) &#8211; not just retreating to comfortable zone of in-memory (or in-pure-flash) data.</p>
<p>I feel somewhat sad that I have to put this truism out here &#8211; disks are way more cost efficient, and if used properly can be used to facilitate way more long-term products, not just real time data. Think Wikipedia without history, think comments that disappear on old posts, together with old posts, think all 404s you hit on various articles you remember from the past and want to read.</p>
<p>Building the web that lasts is completely different task from what academia people imagine building the web is.</p>
<p>I already had this issue with other RDBMS pioneer (there&#8217;s something in common among top database luminaries) &#8211; he also suggested that disks are things of the past and now everything has to be in memory, because memory is cheap. And data can be whatever unordered clutter, because CPUs can sort it, because CPUs are cheap.</p>
<p>They probably missed Al Gore message. Throwing more and more hardware without fine tuning for actual operational efficiency requirements is wasteful and harms our planet. Yes, we do lots of in-memory efficiency work, so that we reduce our I/O, but at the same time we balance the workload so that I/O subsystem provides as efficient as possible delivery of the long tail.</p>
<p>What happens in real world if one gets 2x efficiency gain? Twice more data can be stored, twice more data intensive products can be launched.<br />
What happens in academia of in-memory databases, if one gets 2x efficiency gain? A paper.<br />
What happens when real world doesn&#8217;t read your papers anymore? You troll everyone via GigaOM.</p>
<p>Though sure, there&#8217;s some operational overhead in handling sharding and availability of MySQL deployments, at large scale it becomes somewhat constant cost, whereas operational efficiency gains are linear.</p>
<p><b>Update:</b> Quite a few people pointed out that I was dissing a person who has done incredible amount of contributions, or that I&#8217;m anti-academia. I&#8217;m not, and I extremely value any work that people do wherever they are, albeit I do apply critical thinking to whatever they speak.</p>
<p>In my text above (I don&#8217;t want to edit and hide what I said) I don&#8217;t mean that &#8220;a paper&#8221; is useless. Me and my colleagues do read papers and try to understand the direction of computer science and how it applies to our work (there are indeed various problems yet to solve). I&#8217;d love to come up with something worth a paper (and quite a few of my colleagues did).</p>
<p>Still, if someone does not find that direction useful, there&#8217;s no way to portray them the way the original GigaOM article did.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/domasmituzas.wordpress.com/880/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/domasmituzas.wordpress.com/880/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/domasmituzas.wordpress.com/880/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/domasmituzas.wordpress.com/880/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/domasmituzas.wordpress.com/880/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/domasmituzas.wordpress.com/880/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/domasmituzas.wordpress.com/880/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/domasmituzas.wordpress.com/880/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/domasmituzas.wordpress.com/880/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/domasmituzas.wordpress.com/880/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/domasmituzas.wordpress.com/880/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/domasmituzas.wordpress.com/880/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/domasmituzas.wordpress.com/880/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/domasmituzas.wordpress.com/880/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dom.as&amp;blog=190075&amp;post=880&amp;subd=domasmituzas&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dom.as/2011/07/08/stonebraker-trapped/feed/</wfw:commentRss>
		<slash:comments>30</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c660a6eb3a4005232acb111303bef12c?s=96&#38;d=http%3A%2F%2Fs0.wp.com%2Fi%2Fmu.gif&#38;r=G" medium="image">
			<media:title type="html">domasmituzas</media:title>
		</media:content>

		<media:content url="http://upload.wikimedia.org/wikipedia/en/thumb/7/73/Trollface.png/150px-Trollface.png" medium="image" />
	</item>
		<item>
		<title>Logs memory pressure</title>
		<link>http://dom.as/2010/11/18/logs-memory-pressure/</link>
		<comments>http://dom.as/2010/11/18/logs-memory-pressure/#comments</comments>
		<pubDate>Thu, 18 Nov 2010 14:59:33 +0000</pubDate>
		<dc:creator>Domas Mituzas</dc:creator>
				<category><![CDATA[facebook]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[directio]]></category>
		<category><![CDATA[innodb]]></category>
		<category><![CDATA[io]]></category>
		<category><![CDATA[memory]]></category>

		<guid isPermaLink="false">http://dom.as/?p=818</guid>
		<description><![CDATA[Warning, this may be kernel version specific, albeit this kernel is used by many database systems Lately I&#8217;ve been working on getting more memory used by InnoDB buffer pool &#8211; besides obvious things like InnoDB memory tax there were seemingly &#8230; <a href="http://dom.as/2010/11/18/logs-memory-pressure/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dom.as&amp;blog=190075&amp;post=818&amp;subd=domasmituzas&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><i>Warning, this may be kernel version specific, albeit this kernel is used by many database systems</i></p>
<p>Lately I&#8217;ve been working on getting more memory used by InnoDB buffer pool &#8211; besides obvious things like InnoDB <a href='http://dom.as/2008/05/29/wasting-innodb-memory/'>memory tax</a> there were seemingly external factors that were pushing out MySQL into swap (even with swappiness=0). We were working a lot on getting low hanging fruits like scripts that use too much memory, but they seem to be all somewhat gone, but MySQL has way too much memory pressure from outside.</p>
<p>I grabbed my <a href='http://dom.as/2009/06/26/uncache/'>uncache</a> utility to assist with the investigation and started uncaching various bits on two systems, one that had larger buffer pool (60G), which was already being sent to swap, and a conservatively allocated (55G) machine, both 72G boxes. Initial finds were somewhat surprising &#8211; apparently on both machines most of external-to-mysqld memory was conserved by two sets of items:</p>
<ul>
<li><b>binary logs</b> &#8211; write once, read only tail (sometimes, if MySQL I/O cache cannot satisfy) &#8211; we saw nearly 10G consumed by binlogs on conservatively allocated machines</li>
<li><b>transaction logs</b> &#8211; write many, read never (by MySQL), buffered I/O &#8211; full set of transaction logs was found in memory</li>
</ul>
<p>It was remarkably easy to get rid of binlogs from cache, both by calling out &#8216;uncache&#8217; from scripts, or using this tiny Python class:</p>
<pre>
libc = ctypes.CDLL("libc.so.6")
class cachedfile (file):
    FADV_DONTNEED = 4
    def uncache(self):
        libc.posix_fadvise(self.fileno(), 0, 0, self.FADV_DONTNEED)
</pre>
<p>As it was major memory stress source, it was somewhat a no brainer that binlogs have to be removed from cache &#8211; something that can be serially re-read is taking space away from a buffer pool which avoids random reads. It may make sense to call posix_fadvise() right after writes to them, even.</p>
<p>Transaction logs, on the other hand, are entirely different beast. From MySQL perspective they should be uncached immediately, as nobody ever ever reads them (crash recovery aside, but re-reading then is relatively cheap, as no writes or random reads are done during log read phase). Unfortunately, the problem lies way below MySQL, and thanks to PeterZ for reminding me (we had a small chat about this at Jeremy&#8217;s <a href='http://www.meetup.com/mysql-silicon-valley/'>Silicon Valley MySQL Meetup</a>).</p>
<p>MySQL transaction records are stored in multiple log groups per transaction, then written out as per-log-group writes (each is in multiple of 512 bytes), followed by fsync(). This allows FS to do transaction log write as single I/O operation. This also means that it will be doing partial page writes to buffered files &#8211; overwriting existing data in part of the page, so it has to be read from storage.</p>
<p>So, if all transaction log pages are removed from cache, quite some of them will have to be read back in (depending on sizes of transactions, probably all of them in some cases). Oddly enough, when I tried to hit the edge case, single thread transactions-per-second remained same, but I saw consistent read I/O traffic on disks. So, this would probably work on systems, that have spare I/O (e.g. flash based ones).</p>
<p>Of course, as writes are already in multiples of 512 (and appears that memory got allocated just fine), I could try out direct I/O &#8211; it should avoid page read-in problem and not cause any memory pressure by itself. In this case switching InnoDB to use O_DIRECT was a bit dirtier &#8211; one needs to edit source code and rebuild the server, restart, etc, or&#8230;<br />
<code><br />
# lsof ib_logfile*<br />
# gdb -p $(pidof mysqld)<br />
(gdb) call os_file_set_nocache(9, "test", "test")<br />
(gdb) call os_file_set_nocache(10, "test", "test")<br />
</code><br />
I did not remove fsync() call, but as it is somewhat noop on O_DIRECT files, I left it there, probably it would change benchmark results, but not much.</p>
<p>Some observations:</p>
<ul>
<li>O_DIRECT was ~10% faster at best case scenario &#8211; lots of tiny transactions in single thread</li>
<li>If group commit is used (without binlogs), InnoDB can have way more transactions with multiple threads using buffered I/O, as it does multiple writes per fsync</li>
<li>Enabling sync_binlog makes the difference not that big &#8211; even with many parallel writes direct writes are 10-20% slower than buffered ones</li>
<li>Same for innodb_flush_log_on_trx_commit0 &#8211; multiple writes per fsync are much more efficient with buffered I/O</li>
<li>One would need to do log group merge to have more efficient O_DIRECT for larger transactions</li>
<li>O_DIRECT does not have theoretical disadvantage, current deficiencies are just implementation oriented at buffered I/O &#8211; and can be resolved by (in same areas &#8211; extensive) engineering</li>
<li>YMMV. In certain cases it definitely makes sense even right now, in some other &#8211; not so much</li>
</ul>
<p>So, the outcome here depends on many variables &#8211; with flash read-on-write is not as expensive, especially if read-ahead works. With disks one has to see what is better use for the memory &#8211; using it for buffer pool reduces amount of data reads, but causes log reads. And of course, O_DIRECT wins in the long run :-)</p>
<p>With this data moved away from cache and InnoDB memory tax reduced one could switch from using 75 % of memory to 90% or even 95% for InnoDB buffer pools. Yay?</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/domasmituzas.wordpress.com/818/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/domasmituzas.wordpress.com/818/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/domasmituzas.wordpress.com/818/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/domasmituzas.wordpress.com/818/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/domasmituzas.wordpress.com/818/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/domasmituzas.wordpress.com/818/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/domasmituzas.wordpress.com/818/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/domasmituzas.wordpress.com/818/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/domasmituzas.wordpress.com/818/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/domasmituzas.wordpress.com/818/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/domasmituzas.wordpress.com/818/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/domasmituzas.wordpress.com/818/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/domasmituzas.wordpress.com/818/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/domasmituzas.wordpress.com/818/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dom.as&amp;blog=190075&amp;post=818&amp;subd=domasmituzas&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dom.as/2010/11/18/logs-memory-pressure/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c660a6eb3a4005232acb111303bef12c?s=96&#38;d=http%3A%2F%2Fs0.wp.com%2Fi%2Fmu.gif&#38;r=G" medium="image">
			<media:title type="html">domasmituzas</media:title>
		</media:content>
	</item>
		<item>
		<title>uncache!</title>
		<link>http://dom.as/2009/06/26/uncache/</link>
		<comments>http://dom.as/2009/06/26/uncache/#comments</comments>
		<pubDate>Fri, 26 Jun 2009 13:40:50 +0000</pubDate>
		<dc:creator>Domas Mituzas</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[cache]]></category>
		<category><![CDATA[memory]]></category>

		<guid isPermaLink="false">http://dammit.lt/?p=512</guid>
		<description><![CDATA[this is source code for a tiny program I just wrote that traverses specified directories and removes them from file system cache. There are few use cases for it. One is for all these people who benchmark stuff and want &#8230; <a href="http://dom.as/2009/06/26/uncache/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dom.as&amp;blog=190075&amp;post=512&amp;subd=domasmituzas&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://bazaar.launchpad.net/%7Edomas-mituzas/%2Bjunk/uncache/annotate/head%3A/uncache.c">this is source code for a tiny program</a> I just wrote that traverses specified directories and removes them from file system cache.</p>
<p>There are few use cases for it. One is for all these people who benchmark stuff and want selective OS cache purges, another is for those who run high performance databases. Remember the <a href="http://dom.as/2008/08/11/notes-from-land-of-io/">O_DIRECT serialization</a> everywhere? Well, XFS does direct I/O in parallel, unless there are cached pages (and they can happen because of any random outside-of-database activity, like &#8216;file&#8217; command). Once you &#8216;uncache&#8217; the files, XFS will be very much parallel again \o/ \o/</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/domasmituzas.wordpress.com/512/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/domasmituzas.wordpress.com/512/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/domasmituzas.wordpress.com/512/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/domasmituzas.wordpress.com/512/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/domasmituzas.wordpress.com/512/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/domasmituzas.wordpress.com/512/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/domasmituzas.wordpress.com/512/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/domasmituzas.wordpress.com/512/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/domasmituzas.wordpress.com/512/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/domasmituzas.wordpress.com/512/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/domasmituzas.wordpress.com/512/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/domasmituzas.wordpress.com/512/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/domasmituzas.wordpress.com/512/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/domasmituzas.wordpress.com/512/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dom.as&amp;blog=190075&amp;post=512&amp;subd=domasmituzas&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dom.as/2009/06/26/uncache/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c660a6eb3a4005232acb111303bef12c?s=96&#38;d=http%3A%2F%2Fs0.wp.com%2Fi%2Fmu.gif&#38;r=G" medium="image">
			<media:title type="html">domasmituzas</media:title>
		</media:content>
	</item>
		<item>
		<title>Memcached for small objects</title>
		<link>http://dom.as/2008/12/25/memcached-for-small-objects/</link>
		<comments>http://dom.as/2008/12/25/memcached-for-small-objects/#comments</comments>
		<pubDate>Thu, 25 Dec 2008 14:06:00 +0000</pubDate>
		<dc:creator>Domas Mituzas</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[efficiency]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[memcached]]></category>
		<category><![CDATA[memory]]></category>

		<guid isPermaLink="false">http://dammit.lt/?p=296</guid>
		<description><![CDATA[Memcached quite often ends up as a store for very small objects (small key and some integer value), though it isn&#8217;t really designed to do this kind of work by default. Current memory management is based on slabs (200 of &#8230; <a href="http://dom.as/2008/12/25/memcached-for-small-objects/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dom.as&amp;blog=190075&amp;post=296&amp;subd=domasmituzas&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Memcached quite often ends up as a store for very small objects (small key and some integer value), though it isn&#8217;t really designed to do this kind of work by default. Current memory management is based on slabs (200 of them), where objects are grouped by similar size &#8211; though actual sizes are pre-defined at startup based on few configuration parameters.</p>
<p>By default memcached would have slabs based on assumption, that smallest object size will have 48 bytes of data (thats without item header), and will increase the slab sizes in +25% steps:</p>
<pre>
slab class   1: chunk size    104 perslab 10082
slab class   2: chunk size    136 perslab  7710
slab class   3: chunk size    176 perslab  5957
slab class   4: chunk size    224 perslab  4681
...
</pre>
<p>So, in this case, it allocates at least 104 bytes per object, and next steps are way behind. Fortunately, there&#8217;re some quick steps to have better efficiency:<span id="more-296"></span></p>
<h3>Configuration!</h3>
<p>There&#8217;re two parameters for this:</p>
<ul>
<li>-n &#8211; minimum space allocated for key+value+flags, defaults at 48</li>
<li>-f &#8211; chunk growth factor, default 1.25</li>
</ul>
<p>With these settings memcached will define just 38 slabs, ranging from 104 to 458992 byte sized chunks. Even in case of mixed workloads one can use <code>-n 5 -f 1.05</code> &#8211; this will define ~170 slabs, where low values will increase in 8-byte chunks, and smallest slabs would look like this:</p>
<pre>
slab class   1: chunk size     64 perslab 16384
slab class   2: chunk size     72 perslab 14563
slab class   3: chunk size     80 perslab 13107
...
</pre>
<p>It would get way higher memory efficiency for larger objects too (6k steps at 100k object sizes, rather than 30k steps with default configuration). Of course, more slabs means that there&#8217;re more eviction queues, and in case distribution of object sizes changes, it would have more memory fragmentation, though thats nothing a restart can&#8217;t resolve ;-)</p>
<h3>Internal storage</h3>
<p>Every data item has a header, which includes pointers to other item structures, and additional metadata. One of obvious things that will be fixed in later releases is the CAS (compare-and-swap) metadata (8 bytes per object), which is stored for every object &#8211; though very rarely used by users (one needs to use special breed commands). In future versions this might get resolved, and a very dirty hack would be changing cas_id to be uint8_t in memcached.h (heeeee!).</p>
<p>There&#8217;re also multiple pointers inside the header &#8211; and on 64 bit systems they take 64 bits &#8211; though in theory chunks inside memory pages (slabs can have multiple memory pages assigned) can be addressed with 16-bit pointers. Of course, the easy workaround here is simply compiling memcached as 32-bit binary &#8211; though then it won&#8217;t be able to address more than ~3GB per-instance (and running multiple memcached instances is straightforward).</p>
<p>There&#8217;s another internal CPU-vs-memory optimization, where objects internally end up aligned at 8-byte boundaries. Hacking CHUNK_ALIGN_BYTES at slabs.c (I set it to 2) allows us to have chunk sizes increased in much smaller steps.</p>
<h3>Data!</h3>
<p>Have small keys. Have small data. Compression at application will reduce network i/o, less roundtrips and system calls, and better memory efficiency in the end. Pack integers inside keys into base250 or so (skip whitespace), store binary data.</p>
<p>It is usually way less cycles to have more efficient storage, compared to additional cycles when a cache miss happens :)</p>
<h3>Testing &amp; summary</h3>
<p>I tried to simulate the most edge case out of all edge cases &#8211; integer key and one byte data objects being inserted into 64M memcached instance.</p>
<ul>
<li>I could fit in 645k objects inside regular memcached, 932k after factor changes.</li>
<li>Simple 32-bit build fit in 763k objects, 1164k after factor changes, 1180k after alignment change</li>
<li>After removing CAS support, it fit 1378k, 1461k after reducing key with base250</li>
</ul>
<p>So, I could have such slab size distribution (it facilitates objects up to 45k in size):</p>
<pre>
slab class   1: chunk size     33 perslab 31775
slab class   2: chunk size     34 perslab 30840
slab class   3: chunk size     35 perslab 29959
slab class   4: chunk size     36 perslab 29127
...
</pre>
<h3>MySQL!</h3>
<p>64M-sized MEMORY table will be able to store 2087k (INT,TINYINT) entries. When people aim for no-eviction storage, MySQL can be way more efficient.</p>
<p>Interesting though, the PK will take as much space as data itself (what simply asks PK to be held together with data, like InnoDB does (it will actually fit 2500k entries in 64M).  With custom MySQL engines this shouldn&#8217;t be too difficult for those who really hit the edge cases, right? :)</p>
<p>Oh well, last I&#8217;ve heard, memcached is going to have storage engine support too, I wonder how fun will be hacking those (someone ages ago plugged BDB into memcached and called it Tugela.. ;)</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/domasmituzas.wordpress.com/296/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/domasmituzas.wordpress.com/296/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/domasmituzas.wordpress.com/296/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/domasmituzas.wordpress.com/296/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/domasmituzas.wordpress.com/296/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/domasmituzas.wordpress.com/296/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/domasmituzas.wordpress.com/296/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/domasmituzas.wordpress.com/296/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/domasmituzas.wordpress.com/296/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/domasmituzas.wordpress.com/296/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/domasmituzas.wordpress.com/296/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/domasmituzas.wordpress.com/296/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/domasmituzas.wordpress.com/296/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/domasmituzas.wordpress.com/296/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dom.as&amp;blog=190075&amp;post=296&amp;subd=domasmituzas&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dom.as/2008/12/25/memcached-for-small-objects/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c660a6eb3a4005232acb111303bef12c?s=96&#38;d=http%3A%2F%2Fs0.wp.com%2Fi%2Fmu.gif&#38;r=G" medium="image">
			<media:title type="html">domasmituzas</media:title>
		</media:content>
	</item>
		<item>
		<title>mmap()</title>
		<link>http://dom.as/2008/08/17/mmap/</link>
		<comments>http://dom.as/2008/08/17/mmap/#comments</comments>
		<pubDate>Sun, 17 Aug 2008 23:51:00 +0000</pubDate>
		<dc:creator>Domas Mituzas</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[memory]]></category>
		<category><![CDATA[mmap]]></category>
		<category><![CDATA[myisam]]></category>
		<category><![CDATA[vm]]></category>

		<guid isPermaLink="false">http://dammit.lt/?p=187</guid>
		<description><![CDATA[I&#8217;ve seen quite some work done on implementing mmap() in various places, including MySQL. mmap() is also used for malloc()&#8217;ing huge blocks of memory. mmap() data cache is part of VM cache, not file cache (though those are inside kernels &#8230; <a href="http://dom.as/2008/08/17/mmap/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dom.as&amp;blog=190075&amp;post=187&amp;subd=domasmituzas&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve seen quite some work done on implementing <a href='http://en.wikipedia.org/wiki/Mmap'>mmap()</a> in various places, including MySQL.<br />
mmap() is also used for malloc()&#8217;ing huge blocks of memory.<br />
mmap() data cache is part of VM cache, not file cache (though those are inside kernels tightly coupled, priorities still remain different).</p>
<p>If a small program with low memory footprint maps a file, it will probably make file access faster (as it will be cached more aggressively in memory, and will provide pressure on other cached file data -thats cheating though).</p>
<p>If a large program with lots and lots of allocated memory maps a file, that will pressure the filesystem cache to flush pages, and then&#8230; will pressure existing VM pages of the very same large program to be swapped out. Thats certainly bad.</p>
<p>For now MySQL is <a href='http://bugs.mysql.com/bug.php?id=37408'>using mmap()</a> just for compressed MyISAM files. <a href='http://www.mysqlperformanceblog.com/2006/05/26/myisam-mmap-feature-51/'>Vadim wrote</a> a patch to do more of mmap()ing.</p>
<p>If there&#8217;s less data than RAM, mmap() may provide somewhat more efficient CPU cycles. If there&#8217;s more data than RAM, mmap() will kill the system.</p>
<p>Interesting though, few months ago there was a <a href='http://kerneltrap.org/mailarchive/linux-kernel/2008/6/19/2166494/thread'>discussion on lkml</a> where <a href='http://en.wikipedia.org/wiki/Linus_Torvalds'>Linus</a> wrote:</p>
<blockquote><p>
Because quite frankly, the mixture of doing mmap() and write() system calls is quite fragile &#8211; and I&#8217;m not saying that just because of this particular bug, but because there are all kinds of nasty cache aliasing issues with virtually indexed caches etc that just fundamentally mean that it&#8217;s often a mistake to mix mmap with read/write at the same time.
</p></blockquote>
<p>So, simply, don&#8217;t.</p>
<p><b>Update:</b> Oh well, 5.1: &#8211;myisam_use_mmap option&#8230; Argh.<br />
<b>Update on update:</b> after few minutes of internal testing all mmap()ed MyISAM tables <a href='http://bugs.mysql.com/bug.php?id=38848'>went fubar</a>.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/domasmituzas.wordpress.com/187/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/domasmituzas.wordpress.com/187/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/domasmituzas.wordpress.com/187/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/domasmituzas.wordpress.com/187/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/domasmituzas.wordpress.com/187/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/domasmituzas.wordpress.com/187/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/domasmituzas.wordpress.com/187/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/domasmituzas.wordpress.com/187/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/domasmituzas.wordpress.com/187/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/domasmituzas.wordpress.com/187/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/domasmituzas.wordpress.com/187/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/domasmituzas.wordpress.com/187/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/domasmituzas.wordpress.com/187/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/domasmituzas.wordpress.com/187/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/domasmituzas.wordpress.com/187/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/domasmituzas.wordpress.com/187/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dom.as&amp;blog=190075&amp;post=187&amp;subd=domasmituzas&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dom.as/2008/08/17/mmap/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c660a6eb3a4005232acb111303bef12c?s=96&#38;d=http%3A%2F%2Fs0.wp.com%2Fi%2Fmu.gif&#38;r=G" medium="image">
			<media:title type="html">domasmituzas</media:title>
		</media:content>
	</item>
		<item>
		<title>Wasting InnoDB memory</title>
		<link>http://dom.as/2008/05/29/wasting-innodb-memory/</link>
		<comments>http://dom.as/2008/05/29/wasting-innodb-memory/#comments</comments>
		<pubDate>Thu, 29 May 2008 08:08:00 +0000</pubDate>
		<dc:creator>Domas Mituzas</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[efficiency]]></category>
		<category><![CDATA[innodb]]></category>
		<category><![CDATA[memory]]></category>

		<guid isPermaLink="false">http://dammit.lt/?p=137</guid>
		<description><![CDATA[I usually get strange looks when I complain about memory handling inside InnoDB. It seems as if terabytes of RAM are so common and cheap, that nobody should really care about memory efficiency. Unfortunately for me, I do. Examples: The &#8230; <a href="http://dom.as/2008/05/29/wasting-innodb-memory/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dom.as&amp;blog=190075&amp;post=137&amp;subd=domasmituzas&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I usually get strange looks when I complain about memory handling inside InnoDB. It seems as if terabytes of RAM are so common and cheap, that nobody should really care about memory efficiency. Unfortunately for me, I do.</p>
<p>Examples:</p>
<ul>
<li>The infamous <a href='http://bugs.mysql.com/bug.php?id=15815'>Bug#15815</a> &#8211; buffer pool mutex contention. The patch for the bug added lots of small mutexes, and by &#8216;lots&#8217; I mean really really lots &#8211; two mutexes (and rwlock structure) for each buffer pool page. That makes two million mutexes for 16GB buffer pool, um, four million mutexes for 32GB buffer pool, and I guess more for larger buffer pools. Result &#8211; 16GB buffer pool gets 625MB locking tax to solve a 8-core locking problem. Solution? Between giant lock and armies of page mutexes there lives a land of mutex pools, where locks are shared happily by multiple entities. I even made a <a href='http://noc.wikimedia.org/~midom/nomutex.txt'>patch</a>, unfortunately it gets some ibuf assertion after server restart though at first everything works great :)</li>
<li>InnoDB data dictionary <a href='http://bugs.mysql.com/bug.php?id=20877'>always grows, never shrinks</a>. It is not considered a bug, as it isn&#8217;t memory leak &#8211; all memory is accounted by (hidden) dict_sys-&gt;size, and valgrind doesn&#8217;t print errors. 1-column table takes 2k of memory in InnoDB data dictionary, a table with few more columns and indexes takes already 10k. 100000 tables, and 1GB of memory is wasted.  Who needs 100000 tables? People running application farms do. Actually, there even is a code for cleaning up data dictionary, just wasn&#8217;t finished, and is commented out at the moment. Even worse, the fix for #20877 was a joke &#8211; reducing the in-memory structure size, still not caring about structure count. And of course, do note that every InnoDB partition of a table takes space there too&#8230;</li>
</ul>
<p>So generally if you&#8217;re running bigger InnoDB deployment, you may be hitting various hidden memory taxes &#8211; in hundreds of megabytes, or gigabytes &#8211; that don&#8217;t provide too much value anyway. Well, memory is cheap, our next database boxes will be 32GB-class instead of those &#8216;amnesia&#8217; 16GB types, and I can probably stop ranting :)</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/domasmituzas.wordpress.com/137/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/domasmituzas.wordpress.com/137/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/domasmituzas.wordpress.com/137/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/domasmituzas.wordpress.com/137/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/domasmituzas.wordpress.com/137/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/domasmituzas.wordpress.com/137/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/domasmituzas.wordpress.com/137/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/domasmituzas.wordpress.com/137/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/domasmituzas.wordpress.com/137/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/domasmituzas.wordpress.com/137/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/domasmituzas.wordpress.com/137/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/domasmituzas.wordpress.com/137/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/domasmituzas.wordpress.com/137/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/domasmituzas.wordpress.com/137/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/domasmituzas.wordpress.com/137/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/domasmituzas.wordpress.com/137/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dom.as&amp;blog=190075&amp;post=137&amp;subd=domasmituzas&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dom.as/2008/05/29/wasting-innodb-memory/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c660a6eb3a4005232acb111303bef12c?s=96&#38;d=http%3A%2F%2Fs0.wp.com%2Fi%2Fmu.gif&#38;r=G" medium="image">
			<media:title type="html">domasmituzas</media:title>
		</media:content>
	</item>
		<item>
		<title>LAMPS on steroids</title>
		<link>http://dom.as/2006/12/06/google-perftools-tcmalloc-squid/</link>
		<comments>http://dom.as/2006/12/06/google-perftools-tcmalloc-squid/#comments</comments>
		<pubDate>Wed, 06 Dec 2006 15:04:33 +0000</pubDate>
		<dc:creator>Domas Mituzas</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[wikitech]]></category>
		<category><![CDATA[efficiency]]></category>
		<category><![CDATA[lamps]]></category>
		<category><![CDATA[memory]]></category>
		<category><![CDATA[squid]]></category>
		<category><![CDATA[tcmalloc]]></category>

		<guid isPermaLink="false">http://dammit.lt/2006/12/06/google-perftools-tcmalloc-squid/</guid>
		<description><![CDATA[I&#8217;m not sure if I&#8217;m the first coining in &#8216;LAMPS&#8217; &#8211; scaled out LAMP environment with Squid in front, but it sounds cool. Squid is major component in content distribution systems, reducing the load from all the backend systems dramatically &#8230; <a href="http://dom.as/2006/12/06/google-perftools-tcmalloc-squid/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dom.as&amp;blog=190075&amp;post=51&amp;subd=domasmituzas&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m not sure if I&#8217;m the first coining in &#8216;LAMPS&#8217; &#8211; scaled out LAMP environment with Squid in front, but it sounds cool. Squid is major component in content distribution systems, reducing the load from all the backend systems dramatically (especially with proper caching rules). We had various issues in past, where we used code nobody else seemed to be using &#8211; cache coordination, purges and of course, load.</p>
<p>Quite a few problems resulted in memory leaks, but one was particularly nasty: Squid processes under high load started leaking CPU cycles somewhere. After deploying profiling for squid we actually ended up seeing that the problem is inside libc. Once we started profiling libc, one of initial assumptions appeared to be true &#8211; our heap was awfully fragmented, slowing down malloc().</p>
<p>Here comes our steroids part: <a href='http://www.google.com'>Google</a> has developed a drop-in malloc replacement, <a href='http://goog-perftools.sourceforge.net/doc/tcmalloc.html'>tcmalloc</a>, that is really efficient. Space efficient, cpu efficient, lock efficient. This is probably mostly used (and sophisticated) libc function, that was suffering performance issues not that many people wanted to actually tackle. The description sounded really nice, so we ended up using it for our suffering Squids.</p>
<p>The <a href='http://wiki.wikked.net/wiki/Squid_memory_fragmentation_problem'>results</a> were what we expected &#8211; awesome :) Now the nice part is that the library is optimized for multi-threaded applications, doing lots of allocations for small objects without too much of lock contention, and uses spinlocks for large allocations. MySQL exactly fits the definition, so just by using simple drop-in replacement you may achieve increased performance over standard libc implementations.</p>
<p>For any developers working on high-performance applications, <a href='http://goog-perftools.sourceforge.net/'>Google performance tools</a> provide easy ways to access information that was PITA to work on before. Another interesting toy they have is <a href='http://code.google.com/p/gperftools-httpd/'>embedded http server</a> providing run-time profiling info. I&#8217;m already wondering if we&#8217;d should combine that with our profiling framework. Yummy. Steroids.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/domasmituzas.wordpress.com/51/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/domasmituzas.wordpress.com/51/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/domasmituzas.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/domasmituzas.wordpress.com/51/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/domasmituzas.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/domasmituzas.wordpress.com/51/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/domasmituzas.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/domasmituzas.wordpress.com/51/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/domasmituzas.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/domasmituzas.wordpress.com/51/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/domasmituzas.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/domasmituzas.wordpress.com/51/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/domasmituzas.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/domasmituzas.wordpress.com/51/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/domasmituzas.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/domasmituzas.wordpress.com/51/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dom.as&amp;blog=190075&amp;post=51&amp;subd=domasmituzas&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dom.as/2006/12/06/google-perftools-tcmalloc-squid/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c660a6eb3a4005232acb111303bef12c?s=96&#38;d=http%3A%2F%2Fs0.wp.com%2Fi%2Fmu.gif&#38;r=G" medium="image">
			<media:title type="html">domasmituzas</media:title>
		</media:content>
	</item>
	</channel>
</rss>
