<?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>Fellinghaug Blog &#187; cache</title>
	<atom:link href="http://asbjorn.fellinghaug.com/blog/tag/cache/feed/" rel="self" type="application/rss+xml" />
	<link>http://asbjorn.fellinghaug.com/blog</link>
	<description>&#62;&#62;&#62; from fellinghaug import asbjorn; asbjorn.play()</description>
	<lastBuildDate>Thu, 19 Nov 2009 21:22:01 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Python and memcached</title>
		<link>http://asbjorn.fellinghaug.com/blog/2008/09/python-and-memcached/</link>
		<comments>http://asbjorn.fellinghaug.com/blog/2008/09/python-and-memcached/#comments</comments>
		<pubDate>Mon, 08 Sep 2008 14:26:59 +0000</pubDate>
		<dc:creator>Asbjørn Alexander Fellinghaug</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[cache]]></category>
		<category><![CDATA[memcache]]></category>
		<category><![CDATA[memory]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[scale]]></category>
		<category><![CDATA[webapp]]></category>

		<guid isPermaLink="false">http://asbjorn.fellinghaug.com/blog/?p=54</guid>
		<description><![CDATA[Hi.
There has been some delay since the last time I&#8217;ve presented some stuff in this blog - sorry about that. I guess I can somewhat blame it on my work which is requiring a whole lot of my time nowadays. However, today I have an interesting concept to discuss. Namely the concept of applications and cache.
Nowadays, [...]]]></description>
			<content:encoded><![CDATA[<p>Hi.</p>
<p>There has been some delay since the last time I&#8217;ve presented some stuff in this blog - sorry about that. I guess I can somewhat blame it on my work which is requiring a whole lot of my time nowadays. However, today I have an interesting concept to discuss. Namely the concept of applications and cache.</p>
<p>Nowadays, delays in software is a factor which could mean the difference between failure and success. So, how does most applications cope with this challenge? Well, some does a significant amount of work in regards to create more efficient algorithms, others focus primarily on the overall design of the application in order to reduce time delays, and also the widespread usage of compression of the data flow between systems. Not that these things is not worth thinking of, but an often forgot concept is the usage of a caching system.</p>
<p>A caching system would in this context mean a system specifically designed to hold &#8220;fresh data&#8221;, in a much similar way as a standard database. Now you may think, &#8220;why not just use the database?&#8221;. Well, we will in most cases use a database. However, when your web page (or application) has a wide range of users, and a large set of those users request the same set of data, then your database would be overwhelmed by the amount of incoming requests. A database has a large overhead as a result of all the features which it needs to support (think of JOIN operations, RELATIONS, CONSTRAINTS, etc), and therefore there would be a need to have a much faster retrieval of &#8220;fresh data&#8221; which is frequently requested.</p>
<p>How do you think <a href="http://www.digg.com">Digg</a>, <a href="http://www.reddit.com">Reddit</a> or <a href="http://www.slashdot.org">Slashdot</a> handles its requests? 1. Route HTTP request to web application. 2. Execute a SQL SELECT statement to retrieve the articles 3. Render and return the HTML ? That would not scale very well for such large web sites. Instead, they take advantage of a caching system to hold the result of a SQL SELECT statement for a defined amount of time, and then re-initiate the SQL SELECT statement. With such an approach the database server would be much less overwhelmed by the frequent requests, and the caching system, which just holds the data, would take over the load. Since the caching system is built to hold data in memory, and to make it easy and fast retrievable, the data would be much faster loaded into the application, thus reducing the time delay previously involved.</p>
<p>Enough &#8220;mombo-jombo&#8221;, lets talk technical. The Danga Interactive <a href="http://www.danga.com/memcached/"><em>memcached</em></a> is a &#8220;high-performance, distributed memory object caching system&#8221;. Its main purpose is to hold objects in a distributed manner, and to provide fast retrieval of those objects. This is done with the help of a distributed hash table across the nodes running <em>memcached</em>. Setting up and running a <em>memcached</em> server on Ubuntu and Debian is trivial:</p>
<div class="code"><code><br />
#$ aptitude install memcached<br />
#$ memcached -d -m 2048 -l 192.168.0.10 -p 12345<br />
</code></div>
<p>This would fire up a memcached server with 2GB of memory on IP 192.168.0.10:12345. Now, given the usage of python and the python memcached client library (libmcache):</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="python python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">sys</span>
<span style="color: #ff7700;font-weight:bold;">try</span>:
   <span style="color: #ff7700;font-weight:bold;">import</span> memcache
<span style="color: #ff7700;font-weight:bold;">except</span> <span style="color: #008000;">ImportError</span>:
   <span style="color: #dc143c;">sys</span>.<span style="color: black;">exit</span><span style="color: black;">&#40;</span>0<span style="color: black;">&#41;</span>
mc = memcache.<span style="color: black;">Client</span><span style="color: black;">&#40;</span> <span style="color: black;">&#91;</span><span style="color: #483d8b;">'192.168.0.10:12345'</span><span style="color: black;">&#93;</span> <span style="color: black;">&#41;</span>
mc.<span style="color: #008000;">set</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;fellinghaug&quot;</span>, <span style="color: #483d8b;">&quot;rocks&quot;</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">assert</span> mc.<span style="color: black;">get</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;fellinghaug&quot;</span><span style="color: black;">&#41;</span> == <span style="color: #483d8b;">&quot;rocks&quot;</span></pre></td></tr></table></div>

<p>This may not be the best example of the usage of <em>memcached</em>, but the basic principle is shown. I would highly recommend reading the FAQ/Wiki at Danga&#8217;s homepage, and further these articles:</p>
<ul>
<li><a href="http://en.wikipedia.org/wiki/Memcached">http://en.wikipedia.org/wiki/Memcached</a></li>
<li><a href="http://www.linuxjournal.com/article/7451">http://www.linuxjournal.com/article/7451</a></li>
</ul>
<p>As a final note: if your application shares the characteristics described in this article, then you should consider using a caching system.</p>
]]></content:encoded>
			<wfw:commentRss>http://asbjorn.fellinghaug.com/blog/2008/09/python-and-memcached/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Linux and internal OS caching</title>
		<link>http://asbjorn.fellinghaug.com/blog/2008/04/linux-and-internal-os-caching/</link>
		<comments>http://asbjorn.fellinghaug.com/blog/2008/04/linux-and-internal-os-caching/#comments</comments>
		<pubDate>Sat, 19 Apr 2008 19:46:34 +0000</pubDate>
		<dc:creator>Asbjørn Alexander Fellinghaug</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[cache]]></category>
		<category><![CDATA[memory]]></category>

		<guid isPermaLink="false">http://asbjorn.fellinghaug.com/wp/?p=5</guid>
		<description><![CDATA[Caching inside Linux such as pages and inodes can become quite hugh, and thats the point. Linux wants to utilize all the available memory to create a faster working environment&#8230;
Now, lately I&#8217;ve been experimenting on some IR-software (http://lucene.apache.org), and for these experiments I needed to clear the internal page caching of I/O data. Basicly, whenever [...]]]></description>
			<content:encoded><![CDATA[<p>Caching inside Linux such as pages and inodes can become quite hugh, and thats the point. Linux wants to utilize all the available memory to create a faster working environment&#8230;</p>
<p>Now, lately I&#8217;ve been experimenting on some IR-software <a href="http://lucene.apache.org/">(http://lucene.apache.org)</a>, and for these experiments I needed to clear the internal page caching of I/O data. Basicly, whenever I open a file, then Linux caches that particular file, so that if I need it again later on, it will be available in &#8220;no-time&#8221;. For my experiments, I needed a &#8220;clean&#8221; cache for every run, and therefor needed to clear my cache.</p>
<p>After some Googling I stumbled upon this site:  <a href="http://linux-mm.org/Drop_Caches">http://linux-mm.org/Drop_Caches</a>. There was a lot of interessting stuff there, so I would recommend people to read it.</p>
<p>Basically, whenever you need to <em>uncache</em> something in your computer, you can (in Linux that is), write the following in a terminal:</p>
<p>This one below will free pagecache:</p>
<div class="code">
# echo 1 > /proc/sys/vm/drop_caches
</div>
<p>This one below will free dentries and inodes:</p>
<div class="code">
# echo 2 > /proc/sys/vm/drop_caches
</div>
<p>This one below will free both pagecache, dentries and inodes:</p>
<div class="code">
# echo 3 > /proc/sys/vm/drop_caches
</div>
]]></content:encoded>
			<wfw:commentRss>http://asbjorn.fellinghaug.com/blog/2008/04/linux-and-internal-os-caching/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
