<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>matthewjamesward.co.uk</title>
	<atom:link href="http://matthewjamesward.co.uk/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://matthewjamesward.co.uk/blog</link>
	<description></description>
	<lastBuildDate>Mon, 12 Sep 2011 09:35:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>InnoDB memory usage increasing with many databases and tables</title>
		<link>http://matthewjamesward.co.uk/blog/2011/09/innodb-memory-usage/</link>
		<comments>http://matthewjamesward.co.uk/blog/2011/09/innodb-memory-usage/#comments</comments>
		<pubDate>Sun, 11 Sep 2011 22:12:18 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[databases]]></category>
		<category><![CDATA[dictionary]]></category>
		<category><![CDATA[innodb]]></category>
		<category><![CDATA[memory]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[percona]]></category>
		<category><![CDATA[tables]]></category>

		<guid isPermaLink="false">http://matthewjamesward.co.uk/blog/?p=95</guid>
		<description><![CDATA[Recently we were having an issue at work with MySQL consuming large amounts of memory when trying to import a dataset that consisted of not an inordinately large amount of data (about 60GB on disk) but with a large amount of databases &#8211; about 6,500 databases with 120 tables per database &#8211; making up that [...]]]></description>
			<content:encoded><![CDATA[<p>Recently we were having an issue at work with MySQL consuming large amounts of memory when trying to import a dataset that consisted of not an inordinately large amount of data (about 60GB on disk) but with a large amount of databases &#8211; about 6,500 databases with 120 tables per database &#8211; making up that dataset. The import was happening on a KVM guest with 8GB RAM which highlighted the memory issue as it was previously running on a host with a much larger amount of memory.</p>
<p>We&#8217;d previously castrated InnoDB&#8217;s buffer pool in attempt to counteract the problem to get the dataset at least imported in to the guest, but even that wasn&#8217;t helping. Whatever the buffer pool was set to, from anywhere between 32MB and 6GB, MySQL showed a slow but consistent memory usage increase to the point that two-thirds of the way through the dataset import the guest would run out of RAM and swap and the OOM killer would remove the MySQL process (as MySQL would be consuming about 98% of all available memory, RAM and swap).</p>
<p>After speaking with Percona and analysing the InnoDB stats (the ever useful SHOW ENGINE INNODB STATUS) it appeared that it was actually InnoDB&#8217;s data dictionary that was consuming memory during the import. This is InnoDB&#8217;s internal cache or catalog of the tables it&#8217;s operating on. It&#8217;s similar to MySQL&#8217;s table cache, but specific to InnoDB, and information on any tables that InnoDB will access must be stored in the dictionary. Traditionally once tables are added to this dictionary they are never removed, which means on hosts with a large number of tables in which these tables are accessed often (as in our import, all ~78M tables were opened sequentially) MySQL&#8217;s memory usage will just grow continuously. Percona have exposed the size this dictionary can be in their build of MySQL, which gave us a way to try and limit it during the import, by setting the following option in my.cnf:</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;">innodb_dict_size_limit <span style="color: #CC0099;">=</span> 32M</pre></div></div>

<p>This will set a soft upper bound on the amount of memory MySQL and InnoDB should use for storing tables in the dictionary. It&#8217;s important to note that this is only a soft upper bound; InnoDB knows what information it needs to store in the dictionary at any given time, and if MySQL is opening lots of tables in a small timeframe, it may be that your limit won&#8217;t be that realistic and MySQL will consume the memory it needs to anyway. The memory limit is unlimited by default.</p>
<p>More information on the InnoDB data dictionary is available at <a title="innodb_dict_size_limit" href="http://www.percona.com/docs/wiki/percona-server:features:innodb_dict_size_limit" target="_blank">Percona&#8217;s site</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://matthewjamesward.co.uk/blog/2011/09/innodb-memory-usage/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Solving NSURLConnection leaks</title>
		<link>http://matthewjamesward.co.uk/blog/2009/06/solving-nsurlconnection-leaks/</link>
		<comments>http://matthewjamesward.co.uk/blog/2009/06/solving-nsurlconnection-leaks/#comments</comments>
		<pubDate>Mon, 29 Jun 2009 17:25:29 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[cache]]></category>
		<category><![CDATA[leak]]></category>
		<category><![CDATA[nsurlconnection]]></category>
		<category><![CDATA[xcode]]></category>

		<guid isPermaLink="false">http://blog.fanattic.it/?p=65</guid>
		<description><![CDATA[Recently I was having a problem with NSURLConnection showing memory leaks in Instruments even though it was being correctly allocated and released. On investigation it seemed the problem may be lying with the cache policy, however I was using NSURLRequestReloadIgnoringLocalCacheData in the NSURLRequest to completely ignore any caching requirements and was confused as to why [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I was having a problem with NSURLConnection showing memory leaks in <a title="Instruments (application)" href="http://en.wikipedia.org/wiki/Instruments_(application)" target="_blank">Instruments</a> even though it was being correctly allocated and released. On investigation it seemed the problem may be lying with the cache policy, however I was using NSURLRequestReloadIgnoringLocalCacheData in the NSURLRequest to completely ignore any caching requirements and was confused as to why allocation problems would then be associated with caching.</p>
<p>I&#8217;m still not exactly sure what the problem is (according to <a title="NSURLConnection leaking on multi-threaded apps?" href="http://archives.devshed.com/forums/bsd-93/nsurlconnection-leaking-on-multi-threaded-apps-2220129.html" target="_blank">this thread</a> it may be due to having the NSURLConnection run in a method that&#8217;s detached from the main thread) however, forceably setting the capacity of the URL cache before initiating the connection using the URL request seems to solve the problem. For example:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSURLCache</span> sharedURLCache<span style="color: #002200;">&#93;</span> setMemoryCapacity<span style="color: #002200;">:</span><span style="color: #2400d9;">0</span><span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSURLCache</span> sharedURLCache<span style="color: #002200;">&#93;</span> setDiskCapacity<span style="color: #002200;">:</span><span style="color: #2400d9;">0</span><span style="color: #002200;">&#93;</span>;
&nbsp;
<span style="color: #400080;">NSURLConnection</span> <span style="color: #002200;">*</span>connection <span style="color: #002200;">=</span>
	<span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSURLConnection</span> alloc<span style="color: #002200;">&#93;</span> initWithRequest<span style="color: #002200;">:</span>request delegate<span style="color: #002200;">:</span>self<span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>Hey presto! No more NSURLConnection leaks.</p>
]]></content:encoded>
			<wfw:commentRss>http://matthewjamesward.co.uk/blog/2009/06/solving-nsurlconnection-leaks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

