<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="http://feeds.feedburner.com/~d/styles/rss2full.xsl" type="text/xsl" media="screen"?><?xml-stylesheet href="http://feeds.feedburner.com/~d/styles/itemcontent.css" type="text/css" media="screen"?><rss 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:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Homo-Adminus Blog</title>
	
	<link>http://blog.kovyrin.net</link>
	<description>Yet Another Admin's blog</description>
	<pubDate>Thu, 27 Nov 2008 07:15:30 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.3</generator>
	<language>en</language>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/Homo-Adminus" type="application/rss+xml" /><item>
		<title>Lighttpd Book from Packt - Great Thanksgiving Present</title>
		<link>http://feeds.feedburner.com/~r/Homo-Adminus/~3/467036346/</link>
		<comments>http://blog.kovyrin.net/2008/11/27/lighttpd-book-from-packt-great-thanksgiving-present/#comments</comments>
		<pubDate>Thu, 27 Nov 2008 07:15:30 +0000</pubDate>
		<dc:creator>Scoundrel</dc:creator>
		
		<category><![CDATA[Admin-tips]]></category>

		<category><![CDATA[Networks]]></category>

		<category><![CDATA[books]]></category>

		<category><![CDATA[Lighttpd]]></category>

		<category><![CDATA[Nginx]]></category>

		<guid isPermaLink="false">http://blog.kovyrin.net/?p=146</guid>
		<description><![CDATA[Many people know me as a nginx web server evangelist. But as (IMHO) any professional I think that it is really rewarding to know as much as possible about all the tools available on the market so every time you need to make a decision on some technical issue, you&#8217;d consider all pros and cons [...]]]></description>
			<content:encoded><![CDATA[<p>Many people know me as a nginx web server evangelist. But as (IMHO) any professional I think that it is really rewarding to know as much as possible about all the tools available on the market so every time you need to make a decision on some technical issue, you&#8217;d consider all pros and cons based on my own knowledge. </p>
<p>This is why when I received an email from <a href="http://www.packtpub.com/" onClick="javascript:urchinTracker ('/outbound/article/www.packtpub.com');">Packt</a> company asking if I&#8217;d like to read and review <a href="http://www.packtpub.com/lighttpd/book" onClick="javascript:urchinTracker ('/outbound/article/www.packtpub.com');">their book on Lighttpd</a> I decided to give it a shot (I usually do not review any books because I do not always have enough time to read a book thoroughly to be able to write a review). So, here are my impressions from this book.</p>
<p><span id="more-146"></span></p>
<p>First, when I received the book, I was in doubt: how such a small book could cover so flexible and multi-purpose piece of software like <a href="http://www.lighttpd.net/" onClick="javascript:urchinTracker ('/outbound/article/www.lighttpd.net');">Lighttpd</a>? But after reading a few first chapters I understood that the book is written as any <b>professional</b> book should be written - no weird long chapters explaining what is Internet, web server, HTTP or HTML. From the first pages you dive to the world of Lighttpd starting from installation and going through the most popular and useful configuration options to really interesting virtual hosting configurations.</p>
<p>Pretty interesting security-related chapters explain typical process of obtaining and installing SSL certificates. This always was the most painful process for me in almost any web setup I worked on, don&#8217;t know why though, this process seemed kind of messy for me, but I think those chapters could help novice web server administrators understand the process of securing a web server. </p>
<p>For many new lighttpd users the most interesting chapters should be ones that explain typical problems and use cases of using apache with or instead of apache servers and describe how to set up lighttpd to be used with the most popular backend web software (Ruby on Rails, wordpress, phpmyadmin and more). From my consulting experience I should say that this is the most popular lighttpd deployment scheme (lighttpd frontend + some backends) and this is why these chapters should be the most interesting for new users. As a RoR server administrator I wish authors would explain more different deployment options for Rails, but of course I understand that the book is dedicated to lighttpd, not Rails so it is OK to miss some options. </p>
<p>And finally, for experienced users like me who understands all the internals of the web traffic handling and needs to get more control over the traffic there is <b>just awesome</b> chapters on using Lua with lighttpd and writing custom lighttpd modules. I really wish I had such an explanations when I was doing nginx modules development for <a href="http://www.scribd.com" onClick="javascript:urchinTracker ('/outbound/article/www.scribd.com');">our</a> projects! If I&#8217;d write some lighttpd module I&#8217;d definitely buy this book just because of those Lua and modules-related chapters - there is not so much info on these topics on the Net and such a solid explanation of the basics of web server extension could help a lot.</p>
<p>So, as the final words on <a href="http://www.packtpub.com/lighttpd/book" onClick="javascript:urchinTracker ('/outbound/article/www.packtpub.com');">this book</a>, I&#8217;d like to recommend it to all web services administrators (even if they do not use lighttpd yet) - this book explains many fundamental things that you&#8217;d really like to know. As for professional developers/admins, this books could be useful if they are going to work on some advanced configurations or modules for lighttpd (yes, I loved those lua and modules sections).</p>

<p><a href="http://feeds.feedburner.com/~a/Homo-Adminus?a=IaglHy"><img src="http://feeds.feedburner.com/~a/Homo-Adminus?i=IaglHy" border="0"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~f/Homo-Adminus?a=5VUZn"><img src="http://feeds.feedburner.com/~f/Homo-Adminus?i=5VUZn" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/Homo-Adminus?a=zTTEN"><img src="http://feeds.feedburner.com/~f/Homo-Adminus?i=zTTEN" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/Homo-Adminus?a=64RUn"><img src="http://feeds.feedburner.com/~f/Homo-Adminus?i=64RUn" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://blog.kovyrin.net/2008/11/27/lighttpd-book-from-packt-great-thanksgiving-present/feed/</wfw:commentRss>
		<feedburner:origLink>http://blog.kovyrin.net/2008/11/27/lighttpd-book-from-packt-great-thanksgiving-present/</feedburner:origLink></item>
		<item>
		<title>ActiveMQ + Ruby Stomp Client: How to process elements one by one</title>
		<link>http://feeds.feedburner.com/~r/Homo-Adminus/~3/436554696/</link>
		<comments>http://blog.kovyrin.net/2008/10/30/activemq-ruby-stomp-client-how-to-process-elements-one-by-one/#comments</comments>
		<pubDate>Thu, 30 Oct 2008 04:42:39 +0000</pubDate>
		<dc:creator>Scoundrel</dc:creator>
		
		<category><![CDATA[Admin-tips]]></category>

		<category><![CDATA[Databases]]></category>

		<category><![CDATA[Development]]></category>

		<category><![CDATA[My Projects]]></category>

		<category><![CDATA[activemq]]></category>

		<category><![CDATA[database]]></category>

		<category><![CDATA[development]]></category>

		<category><![CDATA[MySQL]]></category>

		<category><![CDATA[performance]]></category>

		<category><![CDATA[queue]]></category>

		<category><![CDATA[Ruby]]></category>

		<category><![CDATA[scalability]]></category>

		<category><![CDATA[scribd]]></category>

		<category><![CDATA[stomp]]></category>

		<guid isPermaLink="false">http://blog.kovyrin.net/?p=135</guid>
		<description><![CDATA[Few months ago I&#8217;ve switched one of our internal projects from doing synchronous database saves of analytics data to an asynchronous processing using starling + a pool of workers. This was the day when I really understood the power of specialized queue servers. I was using database (mostly, MySQL) for this kind of tasks for [...]]]></description>
			<content:encoded><![CDATA[<p>Few months ago I&#8217;ve switched one of <a href="http://www.scribd.com" onClick="javascript:urchinTracker ('/outbound/article/www.scribd.com');">our</a> internal projects from doing synchronous database saves of analytics data to an asynchronous processing using <a href="http://github.com/starling/starling/tree/master" onClick="javascript:urchinTracker ('/outbound/article/github.com');">starling</a> + a pool of workers. This was the day when I really understood the power of specialized queue servers. I was using database (mostly, MySQL) for this kind of tasks for years and sometimes (especially under a highly concurrent load) it worked not so fast&#8230; Few times I worked with some queue servers, but those were either some small tasks or I didn&#8217;t have a time to really get the idea, that specialized queue servers were created just to do these tasks quickly and efficiently.</p>
<p>All this time (few months now) I was using starling noticed really bad thing in how it works: if workers die (really die, or lock on something for a long time, or just start lagging) and queue start growing, the thing could kill your server and you won&#8217;t be able to do something about it - it just eats all your memory and this is it. Since then I&#8217;ve started looking for a better solution for our queuing, the technology was too cool to give up. I&#8217;ve tried 5 or 6 different popular solutions and all of them sucked&#8230; They ALL had the same problem - if your queue grows, this is your problem and not queue broker&#8217;s :-/ The last solution I&#8217;ve tested was <a href="http://activemq.apache.org/" onClick="javascript:urchinTracker ('/outbound/article/activemq.apache.org');">ActiveMQ</a> and either I wasn&#8217;t able to push it to its limits or it is really so cool, but looks like it does not have this memory problem. So, we&#8217;ve started using it recently.</p>
<p>In this small post I&#8217;d like to describe a few things that took me pretty long to figure out in <a href="http://github.com/grempe/stomp/tree/master" onClick="javascript:urchinTracker ('/outbound/article/github.com');">ruby Stomp client</a>: how to make queues persistent (really!) and how to process elements one by one with clients&#8217; acknowledgments.<br />
<span id="more-135"></span><br />
First, we need to connect to the queue server and this code is the same for clients and servers:</p>
<div class="codecolorer-container ruby"><div class="codecolorer" style="font-family: monospace;">client = <span class="re2">Stomp::Client</span>.<span class="kw3">open</span> <span class="st0">&quot;stomp://localhost:61613&quot;</span><br /><br><span class="kw1">or</span><br /><br>client = <span class="re2">Stomp::Client</span>.<span class="kw3">open</span><span class="br0">&#40;</span>login, password, host, port, reliable<span class="br0">&#41;</span></div></div>
<p>Second form looks better for me because it allows you to specify if you want client to be reliable (lock on errors and try to reconnect, etc) or just want client to raise an error in case of any problems.</p>
<p>When you&#8217;ve connected to the server, you can push your data to a queue:</p>
<div class="codecolorer-container ruby" style="height:35px;"><div class="codecolorer" style="font-family: monospace;">client.<span class="me1">send</span><span class="br0">&#40;</span><span class="st0">'/queue/some_queue'</span>, <span class="st0">&quot;hello world&quot;</span>, headers<span class="br0">&#41;</span></div></div>
<p>And this is where you have an ability to specify if you want your data to be persistent (survive server crashes, etc): <tt>headers</tt> is a hash that could have an element <tt>:persistent => true</tt>, which would do the thing. So, your code would looks like this (for example):</p>
<div class="codecolorer-container ruby"><div class="codecolorer" style="font-family: monospace;">client.<span class="me1">send</span><span class="br0">&#40;</span><span class="st0">'/queue/some_queue'</span>, <span class="st0">&quot;hello world&quot;</span>, <span class="re3">:persistent</span> =&gt; <span class="kw2">true</span><span class="br0">&#41;</span><br /><br>client.<span class="me1">close</span> <span class="co1"># this is needed only in your push code</span></div></div>
<p>Now, when you have your data submitted to the queue, you need to be able to read it and process with some script. This is as simple as the following code:</p>
<div class="codecolorer-container ruby"><div class="codecolorer" style="font-family: monospace;"><span class="co1"># Processing loop</span><br /><br>client.<span class="me1">subscribe</span><span class="br0">&#40;</span><span class="st0">'/queue/some_queue'</span>, headers<span class="br0">&#41;</span> <span class="kw1">do</span> |msg|<br /><br>&nbsp; <span class="co1"># Process your message here</span><br /><br>&nbsp; <span class="co1"># Your submitted data is in msg.body</span><br /><br><span class="kw1">end</span><br /><br>client.<span class="me1">join</span> <span class="co1"># Wait until listening thread dies</span></div></div>
<p>Again, we wanted to receive messages one by one and acknowledge successful processing in our code. This is simple too. You need:</p>
<ul>
<li>Pass <tt>:ack => :client</tt> as an element in your <tt>headers</tt> hash</li>
<li>Call <tt>client.acknowledge(msg)</tt> in the loop if you&#8217;re sure that an element could be removed from the queue</li>
</ul>
<p>This is basically it with the stuff I wanted to explain today. If you&#8217;ve never tried to work with any queue servers, try today and maybe tomorrow you won&#8217;t be able to imagine your systems architecture without such a component <img src='http://blog.kovyrin.net/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /></p>

<p><a href="http://feeds.feedburner.com/~a/Homo-Adminus?a=AEqPrT"><img src="http://feeds.feedburner.com/~a/Homo-Adminus?i=AEqPrT" border="0"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~f/Homo-Adminus?a=hzxHm"><img src="http://feeds.feedburner.com/~f/Homo-Adminus?i=hzxHm" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/Homo-Adminus?a=44I7M"><img src="http://feeds.feedburner.com/~f/Homo-Adminus?i=44I7M" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/Homo-Adminus?a=H5dWm"><img src="http://feeds.feedburner.com/~f/Homo-Adminus?i=H5dWm" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://blog.kovyrin.net/2008/10/30/activemq-ruby-stomp-client-how-to-process-elements-one-by-one/feed/</wfw:commentRss>
		<feedburner:origLink>http://blog.kovyrin.net/2008/10/30/activemq-ruby-stomp-client-how-to-process-elements-one-by-one/</feedburner:origLink></item>
		<item>
		<title>Blog outage</title>
		<link>http://feeds.feedburner.com/~r/Homo-Adminus/~3/432774576/</link>
		<comments>http://blog.kovyrin.net/2008/10/26/blog-outage/#comments</comments>
		<pubDate>Sun, 26 Oct 2008 07:33:57 +0000</pubDate>
		<dc:creator>Scoundrel</dc:creator>
		
		<category><![CDATA[Blog]]></category>

		<category><![CDATA[General]]></category>

		<category><![CDATA[outage]]></category>

		<guid isPermaLink="false">http://blog.kovyrin.net/2008/10/25/131-revision/</guid>
		<description><![CDATA[Sorry for a short outage today - we were moving to a new server we had some problems because of software incompatibilities on the new box. Now all sites on this box should behave as usual 
]]></description>
			<content:encoded><![CDATA[<p>Sorry for a short outage today - we were moving to a new server we had some problems because of software incompatibilities on the new box. Now all sites on this box should behave as usual <img src='http://blog.kovyrin.net/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /></p>

<p><a href="http://feeds.feedburner.com/~a/Homo-Adminus?a=Qpv8gM"><img src="http://feeds.feedburner.com/~a/Homo-Adminus?i=Qpv8gM" border="0"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~f/Homo-Adminus?a=3hfjm"><img src="http://feeds.feedburner.com/~f/Homo-Adminus?i=3hfjm" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/Homo-Adminus?a=WWC2M"><img src="http://feeds.feedburner.com/~f/Homo-Adminus?i=WWC2M" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/Homo-Adminus?a=MlpEm"><img src="http://feeds.feedburner.com/~f/Homo-Adminus?i=MlpEm" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://blog.kovyrin.net/2008/10/26/blog-outage/feed/</wfw:commentRss>
		<feedburner:origLink>http://blog.kovyrin.net/2008/10/26/blog-outage/</feedburner:origLink></item>
		<item>
		<title>Advanced Squid Caching for Rails Applications: Preface</title>
		<link>http://feeds.feedburner.com/~r/Homo-Adminus/~3/432045100/</link>
		<comments>http://blog.kovyrin.net/2008/10/25/advanced-squid-caching-for-rails-applications-preface/#comments</comments>
		<pubDate>Sat, 25 Oct 2008 21:28:30 +0000</pubDate>
		<dc:creator>Scoundrel</dc:creator>
		
		<category><![CDATA[Databases]]></category>

		<category><![CDATA[Development]]></category>

		<category><![CDATA[My Projects]]></category>

		<category><![CDATA[Networks]]></category>

		<category><![CDATA[caching]]></category>

		<category><![CDATA[http]]></category>

		<category><![CDATA[memcache]]></category>

		<category><![CDATA[MySQL]]></category>

		<category><![CDATA[performance]]></category>

		<category><![CDATA[scalability]]></category>

		<category><![CDATA[scribd]]></category>

		<category><![CDATA[squid]]></category>

		<guid isPermaLink="false">http://blog.kovyrin.net/?p=131</guid>
		<description><![CDATA[Since the day one when I joined Scribd, I was thinking about the fact that 90+% of our traffic is going to the document view pages, which is a single action in our documents controller. I was wondering how could we improve this action responsiveness and make our users happier.
Few times I was creating a [...]]]></description>
			<content:encoded><![CDATA[<p>Since the day one when <a href="http://kovyrin.info/2008/07/23/new-job-scalability-expert-in-scribdcom/" onClick="javascript:urchinTracker ('/outbound/article/kovyrin.info');">I joined Scribd</a>, I was thinking about the fact that 90+% of our traffic is going to the document view pages, which is a single action in our documents controller. I was wondering how could we improve this action responsiveness and make our users happier.</p>
<p>Few times I was creating a git branches and hacking this action trying to implement some sort of page-level caching to make things faster. But all the time results weren&#8217;t as good as I&#8217;d like them to be. So, branches were sitting there and waiting for a better idea.<br />
<span id="more-131"></span><br />
Few months ago <a href="http://kpumuk.info" onClick="javascript:urchinTracker ('/outbound/article/kpumuk.info');">my good friend</a> has joined Scribd and we&#8217;ve started thinking on this problem together. As the result of our brainstorming we&#8217;ve managed to figure out what were the problems preventing us from doing efficient caching:</p>
<ul>
<li>First of all, a lots of code in the action is changing the page view if our visitor is a bot (no, not a cloaking, just some minor adjustments of the view).</li>
<li>Second problem was a set of differences in the view for anonymous and logged in users.</li>
<li>And finally, third problem was the fact that the page has a few blocks that change pretty dynamically: document stats pane and comments lists.</li>
</ul>
<p>All these problems when combined were creating a lots of pain when I was trying to cache a whole page. When we&#8217;ve figured them out, we&#8217;ve started thinking on how could we generalize possible combinations of those factors and possible approaches to caching.</p>
<p>There is a well known idea in web applications development: the fastest web app action is an action that does not require any code to be executed on your application server. So, first idea we&#8217;ve tried to think about was some approach that would definitely reduce the number of hits on our app servers. This idea was based on HTTP protocol features related to <strong>Last-Modified</strong> and <strong>E-Tag</strong> headers. But there was a problem - not so many users go to the same page twice so even if we&#8217;d make the page cacheable, it wouldn&#8217;t help too much. But the idea of full page caching outside of the application was really good and we&#8217;ve started playing with it to figure out how to use it in production.</p>
<p>Long time ago, when Internet was slow and expensive many ISPs and large companies were trying to reduce their traffic w/o hurting users&#8217; experience. Then <a href="http://www.squid-cache.org/" onClick="javascript:urchinTracker ('/outbound/article/www.squid-cache.org');">caching proxy servers</a> were born. The idea of those servers was to handle all web requests going from a network (ISP or a company office) and try to cache as much content as possible so when the same or some other user would request a cached page, proxy server would return it really fast. If we&#8217;d implement support for those Last-Modified headers, all proxy servers would be happy to cache our pages. But there was a problem - no one uses caching proxies in 2008 <img src='http://blog.kovyrin.net/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> So, we&#8217;ve got an idea - why can&#8217;t we place such a server in front of our application and make it cache content for all users in the world? (Yes, we knew about a caching reverse proxies before - I&#8217;m just trying to explain the flow of our thoughts and words when we were brainstorming the problem).</p>
<p>The only problem with this approach would be to differentiate logged in users, anonymous users and bots. Considering the fact that our proxy server could be placed between the app and our web servers (nginx), we&#8217;ve decided to create a nginx module that would translate the same document page URLs to a set of URLs, which would be different for all those 3 kinds of users.</p>
<p>When all those problems with different kinds of users were solved, we&#8217;ve decided to solve the last one - non-cacheable dynamic stats pane. The solution was pretty simple - we&#8217;ve added a small ajax call to the page which would update stats on the cached version of our page for all real users while bots will see the same page, but with a bit stale stats pane.</p>
<p>Long story short, the results is really great. Application servers load reduced by 50-70%, database servers  load is reduced by 30-60%, response times dropped down to 150-200 msec from 500-750 msec. As an additional positive effect of the caching we&#8217;ve managed to remove all fragments caches from the application and free more of memcached resources for data caches. Here are a few cacti graphs of our servers load/traffic (the caching was introduced on Oct 9th at night):</p>
<p><strong>Main MySQL command counters:</strong></p>
<div class="thumbnail"><a href="http://skitch.com/kovyrin/2jq2/cacti" onClick="javascript:urchinTracker ('/outbound/article/skitch.com');"><img src="http://img.skitch.com/20081025-kkeqfuqp87w22fgpqwpa99ri4f.preview.jpg" alt="Cacti" /></a><br /><span style="font-family: Lucida Grande, Trebuchet, sans-serif, Helvetica, Arial; font-size: 10px; color: #808080">Uploaded with <a href="http://plasq.com/" onClick="javascript:urchinTracker ('/outbound/article/plasq.com');">plasq</a>&#8217;s <a href="http://skitch.com" onClick="javascript:urchinTracker ('/outbound/article/skitch.com');">Skitch</a>!</span></div>
<p><br/></p>
<p><strong>One of our Application Servers CPU Usage:</strong></p>
<div class="thumbnail"><a href="http://skitch.com/kovyrin/2jqh/cacti" onClick="javascript:urchinTracker ('/outbound/article/skitch.com');"><img src="http://img.skitch.com/20081025-be4571a18h2ijh75idgipsw4u1.preview.jpg" alt="Cacti" /></a><br /><span style="font-family: Lucida Grande, Trebuchet, sans-serif, Helvetica, Arial; font-size: 10px; color: #808080">Uploaded with <a href="http://plasq.com/" onClick="javascript:urchinTracker ('/outbound/article/plasq.com');">plasq</a>&#8217;s <a href="http://skitch.com" onClick="javascript:urchinTracker ('/outbound/article/skitch.com');">Skitch</a>!</span></div>
<p><br/></p>
<p><strong>One of our Application Servers Load Average:</strong></p>
<div class="thumbnail"><a href="http://skitch.com/kovyrin/2jxy/cacti" onClick="javascript:urchinTracker ('/outbound/article/skitch.com');"><img src="http://img.skitch.com/20081025-mdjxgquferw1tdwrqecssbafby.preview.jpg" alt="Cacti" /></a><br /><span style="font-family: Lucida Grande, Trebuchet, sans-serif, Helvetica, Arial; font-size: 10px; color: #808080">Uploaded with <a href="http://plasq.com/" onClick="javascript:urchinTracker ('/outbound/article/plasq.com');">plasq</a>&#8217;s <a href="http://skitch.com" onClick="javascript:urchinTracker ('/outbound/article/skitch.com');">Skitch</a>!</span></div>
<p><br/></p>
<p>Unfortunately there are a lot of things to share related to this caching experience, so I&#8217;ve decided to make a series of posts that would explain all the problems we had and solutions we&#8217;ve found for each of the following parts of the caching system:</p>
<ul>
<li>Nginx module development</li>
<li>Squid Server setup (configs and hardware)</li>
<li>Rails code to support Last-Modified headers and how we purge caches</li>
</ul>
<p>So, if you&#8217;re interested in details, subscribe to this blog&#8217;s <a href="http://feeds.feedburner.com/Homo-Adminus" onClick="javascript:urchinTracker ('/outbound/article/feeds.feedburner.com');">RSS feed</a> and in a few days you&#8217;ll see the first article from this series.</p>

<p><a href="http://feeds.feedburner.com/~a/Homo-Adminus?a=WnOePE"><img src="http://feeds.feedburner.com/~a/Homo-Adminus?i=WnOePE" border="0"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~f/Homo-Adminus?a=S0ndm"><img src="http://feeds.feedburner.com/~f/Homo-Adminus?i=S0ndm" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/Homo-Adminus?a=tatGM"><img src="http://feeds.feedburner.com/~f/Homo-Adminus?i=tatGM" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/Homo-Adminus?a=EF8xm"><img src="http://feeds.feedburner.com/~f/Homo-Adminus?i=EF8xm" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://blog.kovyrin.net/2008/10/25/advanced-squid-caching-for-rails-applications-preface/feed/</wfw:commentRss>
		<feedburner:origLink>http://blog.kovyrin.net/2008/10/25/advanced-squid-caching-for-rails-applications-preface/</feedburner:origLink></item>
		<item>
		<title>Bounces-handler Released</title>
		<link>http://feeds.feedburner.com/~r/Homo-Adminus/~3/354237856/</link>
		<comments>http://blog.kovyrin.net/2008/08/03/bounce-handler-released/#comments</comments>
		<pubDate>Sun, 03 Aug 2008 08:46:05 +0000</pubDate>
		<dc:creator>Scoundrel</dc:creator>
		
		<category><![CDATA[Development]]></category>

		<category><![CDATA[My Projects]]></category>

		<category><![CDATA[Networks]]></category>

		<category><![CDATA[email]]></category>

		<category><![CDATA[rails]]></category>

		<category><![CDATA[release]]></category>

		<category><![CDATA[Ruby]]></category>

		<category><![CDATA[Ruby On Rails]]></category>

		<category><![CDATA[scribd]]></category>

		<category><![CDATA[spam]]></category>

		<guid isPermaLink="false">http://blog.kovyrin.net/?p=130</guid>
		<description><![CDATA[Today I&#8217;ve managed to finish initial version of our bounces-handler package we use for mailing-related stuff in Scribd. 
Bounces-handler package is a simple set of scripts to automatically process email bounces and ISP‘s feedback loops emails, maintain your mailing blacklists and a Rails plugin to use those blacklists in your RoR applications.
This piece of software [...]]]></description>
			<content:encoded><![CDATA[<p>Today I&#8217;ve managed to finish <a href="http://github.com/kovyrin/bounces-handler/tree/master" onClick="javascript:urchinTracker ('/outbound/article/github.com');">initial version of our bounces-handler package</a> we use for mailing-related stuff in <a href="http://www.scribd.com" onClick="javascript:urchinTracker ('/outbound/article/www.scribd.com');">Scribd</a>. </p>
<p>Bounces-handler package is a simple set of scripts to automatically process email bounces and ISP‘s feedback loops emails, maintain your mailing blacklists and a Rails plugin to use those blacklists in your RoR applications.</p>
<p>This piece of software has been developed as a part of more global work on mailing quality improvement in Scribd.com, but it was one of the most critical steps after setting up reverse DNS records, DKIM and SPF. </p>
<p>The <a href="http://github.com/kovyrin/bounces-handler/tree/master" onClick="javascript:urchinTracker ('/outbound/article/github.com');">package</a> itself consists of two parts:</p>
<ul>
<li>Perl scripts to process incoming email:
<ul>
<li>bounces processor — could be assigned to process all your bounce emails</li>
<li>feedback loops messages processor — more specific for Scribd, but still - could be modified for your needs (will be released soon).</li>
</ul>
</li>
<li>Rails plugin to work with mailing blacklists</li>
</ul>
<p>For more information, please check our <a href="http://github.com/kovyrin/bounces-handler/tree/master/README.rdoc" onClick="javascript:urchinTracker ('/outbound/article/github.com');">README file</a>. If you have any questions, comments or suggestions, please leave them here as a comments and I&#8217;ll try to reply as soon as possible.</p>

<p><a href="http://feeds.feedburner.com/~a/Homo-Adminus?a=w8SByv"><img src="http://feeds.feedburner.com/~a/Homo-Adminus?i=w8SByv" border="0"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~f/Homo-Adminus?a=kcwuo"><img src="http://feeds.feedburner.com/~f/Homo-Adminus?i=kcwuo" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/Homo-Adminus?a=4280O"><img src="http://feeds.feedburner.com/~f/Homo-Adminus?i=4280O" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/Homo-Adminus?a=9smoo"><img src="http://feeds.feedburner.com/~f/Homo-Adminus?i=9smoo" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://blog.kovyrin.net/2008/08/03/bounce-handler-released/feed/</wfw:commentRss>
		<feedburner:origLink>http://blog.kovyrin.net/2008/08/03/bounce-handler-released/</feedburner:origLink></item>
		<item>
		<title>Found an Ideal I/O Scheduler for my MySQL boxes</title>
		<link>http://feeds.feedburner.com/~r/Homo-Adminus/~3/340256730/</link>
		<comments>http://blog.kovyrin.net/2008/07/20/found-an-ideal-io-scheduler-for-my-mysql-boxes/#comments</comments>
		<pubDate>Sun, 20 Jul 2008 00:49:56 +0000</pubDate>
		<dc:creator>Scoundrel</dc:creator>
		
		<category><![CDATA[Admin-tips]]></category>

		<category><![CDATA[Databases]]></category>

		<category><![CDATA[i/O]]></category>

		<category><![CDATA[linux]]></category>

		<category><![CDATA[MySQL]]></category>

		<category><![CDATA[performance]]></category>

		<category><![CDATA[scalability]]></category>

		<category><![CDATA[scheduler]]></category>

		<guid isPermaLink="false">http://blog.kovyrin.net/?p=129</guid>
		<description><![CDATA[Today I was doing some work on one of our database servers (each of them has 4 SAS disks in RAID10 on an Adaptec controller) and it required huge multi-thread I/O-bound read load. Basically it was a set of parallel full-scan reads from a 300Gb compressed innodb table (yes, we use innodb plugin). Looking at [...]]]></description>
			<content:encoded><![CDATA[<p>Today I was doing some work on one of <a href="http://www.scribd.com" onClick="javascript:urchinTracker ('/outbound/article/www.scribd.com');">our</a> database servers (each of them has 4 SAS disks in RAID10 on an Adaptec controller) and it required huge multi-thread I/O-bound read load. Basically it was a set of parallel full-scan reads from a 300Gb compressed innodb table (yes, we use innodb plugin). Looking at the iostat I saw pretty expected results: 90-100% disk utilization and lots of read operations per second. Then I decided to play around with linux I/O schedulers and try to increase disk subsystem throughput. Here are the results:</p>
<p><span id="more-129"></span></p>
<table border="1">
<tr>
<th>Scheduler</th>
<th>Reads per second</th>
</tr>
<tr>
<td>cfq</td>
<td>20000-25000</td>
</tr>
<tr>
<td>noop</td>
<td>35000-60000</td>
</tr>
<tr>
<td>deadline</td>
<td>33000-45000</td>
</tr>
<tr>
<td>anticipatory</td>
<td>22000-29000</td>
</tr>
</table>
<p><em>Notice:</em> The box can&#8217;t be restarted to check with clean caches and stuff, but I was doing full reads from this huge table on a machine with 16Gb RAM so all caches were washed out by this load anyways.</p>
<p>As you can see, less work linux does on its side to optimize disk I/O, slower it works <img src='http://blog.kovyrin.net/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> Actually it was pretty expected, but still - surprising result. The problem (as guys from Youtube explained on the last year MySQL Conf) is there because Linux knows nothing about RAID&#8217;s internals and specific drives&#8217; queues so when it is trying to re-arrange requests in its own queue it wastes CPU resources and could potentially prevent RAID controller from doing its own queue optimizations. </p>
<p>After this test I&#8217;ve tried it on a few other I/O-bound servers (both read and write bound) and the result was the same - noop (do nothing) I/O scheduler gave me the best results. Long story short, I&#8217;ve decided to try this scheduler on all our boxes for a week and look at the results in cacti graphs to see how it works.</p>

<p><a href="http://feeds.feedburner.com/~a/Homo-Adminus?a=5YjSIw"><img src="http://feeds.feedburner.com/~a/Homo-Adminus?i=5YjSIw" border="0"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~f/Homo-Adminus?a=iXKCo"><img src="http://feeds.feedburner.com/~f/Homo-Adminus?i=iXKCo" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/Homo-Adminus?a=Nu0BO"><img src="http://feeds.feedburner.com/~f/Homo-Adminus?i=Nu0BO" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/Homo-Adminus?a=HT07o"><img src="http://feeds.feedburner.com/~f/Homo-Adminus?i=HT07o" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://blog.kovyrin.net/2008/07/20/found-an-ideal-io-scheduler-for-my-mysql-boxes/feed/</wfw:commentRss>
		<feedburner:origLink>http://blog.kovyrin.net/2008/07/20/found-an-ideal-io-scheduler-for-my-mysql-boxes/</feedburner:origLink></item>
		<item>
		<title>Fwd: Scorching hot Startup Needs Scalability Sorcerer and Optimization Freak</title>
		<link>http://feeds.feedburner.com/~r/Homo-Adminus/~3/338669234/</link>
		<comments>http://blog.kovyrin.net/2008/07/18/fwd-scorching-hot-startup-needs-scalability-sorcerer-and-optimization-freak/#comments</comments>
		<pubDate>Fri, 18 Jul 2008 04:26:22 +0000</pubDate>
		<dc:creator>Scoundrel</dc:creator>
		
		<category><![CDATA[Databases]]></category>

		<category><![CDATA[Development]]></category>

		<category><![CDATA[Networks]]></category>

		<category><![CDATA[mysql scalability job]]></category>

		<guid isPermaLink="false">http://blog.kovyrin.net/?p=128</guid>
		<description><![CDATA[Question: Do you think you have what it takes to take a service from a few hundred thousand users to tens of millions of users in 1 year flat? If you do read on and perhaps become the next beloved scalability rockstar of our age.
We are looking for a data charmer. A mysql magician. A [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Question:</strong> Do you think you have what it takes to take a service from a few hundred thousand users to tens of millions of users in 1 year flat? If you do read on and perhaps become the next beloved scalability rockstar of our age.</p>
<p>We are looking for a data charmer. A mysql magician. A code hack. A funny man. A mad man. A passionate man. Or perhaps a woman who does all these things and more. </p>
<p><strong>Here&#8217;s what you gotta do:</strong></p>
<ul>
<li>Pro-active and reactive performance analysis, monitoring and general database plumbing of all leaky issues.</li>
<li>Work with others on the team to help maintain/improve and support the infrastructure for a high traffic, high growth site</li>
<li>Optimize and tune the database day to day</li>
<li>Algorithmic bent. Develop algos to quicken search times, response times, find shortest paths between various connections on site.</li>
<li>Have solid low level networking/protocol/computer security skills</li>
<li>Log everything. Usage stats, search stats, user behaviour stats. Draw conclusions. Constantly refine and tinker.</li>
<li>Help with periodic large storage migrations</li>
<li>Work intimately with operations, development, and strategy team to ensure smooth deployments of new iterations, high availability of database services.</li>
<li>Understand capacity planning. Always thinking 10 steps ahead. (Whether it means looking at distributed systems services, cloud computing options, evaluating HA models used in other industries etc)</li>
<li>Have a pulse on the state of the web, social media, social networking, different scalability architectures, benefits/negatives of each.</li>
<li>Interest in high concurrency, distributed systems architectures. </li>
<li>General low level hacking/scripting/optimizations in perl/python. </li>
<li>Evaluate changing conditions in the archi</li>
<li>Think creatively. No dogmatists.</li>
</ul>
<p><strong>Ideal skillset:</strong></p>
<ul>
<li>BS in Comp Sci or equivalent</li>
<li>5+ years experiene with Linux/Unix systems</li>
<li>3+ years with MySQL in production environment</li>
<li>Knowledge and experience with partitioned architectures and a database sharding techniques</li>
<li>Capacity planning/high growth planning/emergency planning experience</li>
<li>Passion, bordering on paranoia, for hunting bottlenecks, and optimizing IO operations</li>
<li>Experience with MySQL replication</li>
<li>Deep experience with MySQL internals</li>
<li>Experience with performance analysis tools, storage engines, backup methodologies for MySQL</li>
<li>Great perl/shell scripting experience</li>
<li>Team player, self motivated, able to handle high stress situations while maintaining a calm disposition</li>
<li>Great communication skills, attention for detail, and an interest in the business side of the equation of systems/scale planning</li>
<li>Eat/sleep/breathe the web, startups, and the landscape of the social web</li>
<li>Insomniac</li>
</ul>
<p>We&#8217;re ready to offer an aggressive salary with tremendous upside by way of stock options, commensurate with your experience, your drive and your results. </p>
<p>Apply directly to: </p>
<p><strong>net &#8216;dot&#8217; startup &#8216;at&#8217; googles mail service dot com</strong></p>
<p>by sending us a CV/resume, and optionally, a link to your blog or Linkedin profile.</p>

<p><a href="http://feeds.feedburner.com/~a/Homo-Adminus?a=Lr9oaT"><img src="http://feeds.feedburner.com/~a/Homo-Adminus?i=Lr9oaT" border="0"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~f/Homo-Adminus?a=pniOo"><img src="http://feeds.feedburner.com/~f/Homo-Adminus?i=pniOo" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/Homo-Adminus?a=D5NOO"><img src="http://feeds.feedburner.com/~f/Homo-Adminus?i=D5NOO" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/Homo-Adminus?a=8SdMo"><img src="http://feeds.feedburner.com/~f/Homo-Adminus?i=8SdMo" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://blog.kovyrin.net/2008/07/18/fwd-scorching-hot-startup-needs-scalability-sorcerer-and-optimization-freak/feed/</wfw:commentRss>
		<feedburner:origLink>http://blog.kovyrin.net/2008/07/18/fwd-scorching-hot-startup-needs-scalability-sorcerer-and-optimization-freak/</feedburner:origLink></item>
		<item>
		<title>Ivan Needs Your Help</title>
		<link>http://feeds.feedburner.com/~r/Homo-Adminus/~3/334766237/</link>
		<comments>http://blog.kovyrin.net/2008/07/14/ivan-needs-your-help/#comments</comments>
		<pubDate>Mon, 14 Jul 2008 04:20:18 +0000</pubDate>
		<dc:creator>Scoundrel</dc:creator>
		
		<category><![CDATA[Databases]]></category>

		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://blog.kovyrin.net/?p=127</guid>
		<description><![CDATA[Please help save Ivan, son of Andrii Nikitin (MySQL Support Engineer), who needs a bone marrow transplant. Andrii&#8217;s message is below:

&#8220;My family got bad news - doctors said allogenic bone marrow transplantation is the only chance for my son Ivan.
&#8220;8 months of heavy and expensive immune suppression brought some positive results so we hoped that [...]]]></description>
			<content:encoded><![CDATA[<p>Please help <a href="http://www.mysql.com/about/help-ivan.html" onClick="javascript:urchinTracker ('/outbound/article/www.mysql.com');">save Ivan</a>, son of Andrii Nikitin (MySQL Support Engineer), who needs a bone marrow transplant. Andrii&#8217;s message is below:</p>
<blockquote><p>
&#8220;My family got bad news - doctors said allogenic bone marrow transplantation is the only chance for my son Ivan.</p>
<p>&#8220;8 months of heavy and expensive immune suppression brought some positive results so we hoped that recovering is just question of time.</p>
<p>&#8220;Ivan is very brave boy - not every human meets so much suffering during whole life, like Ivan already met in his 2,5 years. But long road is still in front of us to get full recover - we are ready to come it through.</p>
<p>&#8220;Ukrainian clinics have no technical possibility to do such complex operation, so we need 150-250K EUR for Israel or European or US clinic. The final decision will be made considering amount we able to find. Perhaps my family is able to get ~60% of that by selling the flat where parents leave and some other goods, but we still require external help.&#8221;</p>
<p>&#8211; Andrii Nikitin, MySQL Engineer
</p></blockquote>
<p>For donation: <a href="http://www.mysql.com/about/help-ivan.html" onClick="javascript:urchinTracker ('/outbound/article/www.mysql.com');">Donation can be made through PayPal (via MySQL/Sun website)</a></p>

<p><a href="http://feeds.feedburner.com/~a/Homo-Adminus?a=LSessL"><img src="http://feeds.feedburner.com/~a/Homo-Adminus?i=LSessL" border="0"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~f/Homo-Adminus?a=S9mRo"><img src="http://feeds.feedburner.com/~f/Homo-Adminus?i=S9mRo" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/Homo-Adminus?a=aemkO"><img src="http://feeds.feedburner.com/~f/Homo-Adminus?i=aemkO" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/Homo-Adminus?a=H7TIo"><img src="http://feeds.feedburner.com/~f/Homo-Adminus?i=H7TIo" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://blog.kovyrin.net/2008/07/14/ivan-needs-your-help/feed/</wfw:commentRss>
		<feedburner:origLink>http://blog.kovyrin.net/2008/07/14/ivan-needs-your-help/</feedburner:origLink></item>
		<item>
		<title>RSS Feed has been  fixed</title>
		<link>http://feeds.feedburner.com/~r/Homo-Adminus/~3/322943235/</link>
		<comments>http://blog.kovyrin.net/2008/06/30/rss-feed-has-been-fixed/#comments</comments>
		<pubDate>Mon, 30 Jun 2008 03:26:24 +0000</pubDate>
		<dc:creator>Scoundrel</dc:creator>
		
		<category><![CDATA[Blog]]></category>

		<category><![CDATA[feed]]></category>

		<category><![CDATA[fix]]></category>

		<category><![CDATA[rss]]></category>

		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://blog.kovyrin.net/?p=126</guid>
		<description><![CDATA[Because of some weird bug my RSS feeds were broken ever since I&#8217;ve upgraded to WP 2.5. Today they were fixed and I hope they&#8217;ll have some new posts there soon  Stay tuned.
]]></description>
			<content:encoded><![CDATA[<p>Because of some weird bug my RSS feeds were broken ever since I&#8217;ve upgraded to WP 2.5. Today they were fixed and I hope they&#8217;ll have some new posts there soon <img src='http://blog.kovyrin.net/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> Stay tuned.</p>

<p><a href="http://feeds.feedburner.com/~a/Homo-Adminus?a=FTS59o"><img src="http://feeds.feedburner.com/~a/Homo-Adminus?i=FTS59o" border="0"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~f/Homo-Adminus?a=Y7Zro"><img src="http://feeds.feedburner.com/~f/Homo-Adminus?i=Y7Zro" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/Homo-Adminus?a=wrGpO"><img src="http://feeds.feedburner.com/~f/Homo-Adminus?i=wrGpO" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/Homo-Adminus?a=doiHo"><img src="http://feeds.feedburner.com/~f/Homo-Adminus?i=doiHo" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://blog.kovyrin.net/2008/06/30/rss-feed-has-been-fixed/feed/</wfw:commentRss>
		<feedburner:origLink>http://blog.kovyrin.net/2008/06/30/rss-feed-has-been-fixed/</feedburner:origLink></item>
		<item>
		<title>Using Sphinx for Non-Fulltext Queries</title>
		<link>http://feeds.feedburner.com/~r/Homo-Adminus/~3/293592757/</link>
		<comments>http://blog.kovyrin.net/2008/05/19/using-sphinx-for-non-fulltext-queries/#comments</comments>
		<pubDate>Mon, 19 May 2008 16:18:54 +0000</pubDate>
		<dc:creator>Scoundrel</dc:creator>
		
		<category><![CDATA[Admin-tips]]></category>

		<category><![CDATA[Databases]]></category>

		<category><![CDATA[Development]]></category>

		<category><![CDATA[My Projects]]></category>

		<category><![CDATA[full-text]]></category>

		<category><![CDATA[index]]></category>

		<category><![CDATA[MySQL]]></category>

		<category><![CDATA[optimization]]></category>

		<category><![CDATA[Ruby]]></category>

		<category><![CDATA[scalability]]></category>

		<category><![CDATA[scribd]]></category>

		<category><![CDATA[sphinx]]></category>

		<guid isPermaLink="false">http://blog.kovyrin.net/2008/05/19/using-sphinx-for-non-fulltext-queries/</guid>
		<description><![CDATA[How often do you think about the reasons why your favorite RDBMS sucks?  Last few months I was doing this quite often and yes, my favorite RDBMS is MySQL. The reason why I was thinking so because one of my recent tasks at Scribd was fixing scalability problems in documents browsing. 
The problem with [...]]]></description>
			<content:encoded><![CDATA[<p>How often do you think about the reasons why your favorite RDBMS sucks? <img src='http://blog.kovyrin.net/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> Last few months I was doing this quite often and yes, my favorite RDBMS is MySQL. The reason why I was thinking so because one of my recent tasks at <a href="http://www.scribd.com" onClick="javascript:urchinTracker ('/outbound/article/www.scribd.com');">Scribd</a> was fixing scalability problems in documents browsing. </p>
<p>The problem with browsing was pretty simple to describe and as hard to fix - we have large data set which consists of a few tables with many fields with really bad selectivity (flag fields like is_deleted, is_private, etc; file_type, language_id , category_id and others). As the result of this situation it becomes really hard (if possible at all) to display documents lists like &#8220;<a href="http://www.scribd.com/browse?c=123&#038;ft=pdf&#038;l=8&#038;p=1&#038;page=1&#038;t=popular" onClick="javascript:urchinTracker ('/outbound/article/www.scribd.com');">most popular 1-10 pages PDF documents in Italian language from the category &#8220;Business&#8221;</a> (of course, non-deleted, non-private, etc). If you&#8217;ll try to create appropriate indexes for each possible filters combination, you&#8217;ll end up having tens or hundreds of indexes and every INSERT query in your tables will take ages.</p>
<p><span id="more-125"></span></p>
<p>So, we were doing many weird things to solve this problem, like having really huge covering indexes for most popular browsing situations, having powerful (and expensive) dedicated servers for browsing queries, etc. Nothing helped and we ended up reducing filters number to 1-2 per query. But with continuously growing documents base we&#8217;d really love to help people find interesting content and filters is what we&#8217;d really want to add to the project.</p>
<p>Long story short, we&#8217;ve decided to try to use <a href="http://www.sphinxsearch.com/" onClick="javascript:urchinTracker ('/outbound/article/www.sphinxsearch.com');">Sphinx search engine</a> for really unusual thing - we decided to move all SELECT queries for our documents to a small (proof of concept) sphinx installation on one of our DB servers and use Sphinx&#8217; <a href="http://www.sphinxsearch.com/doc.html#matching-modes" onClick="javascript:urchinTracker ('/outbound/article/www.sphinxsearch.com');">full-scan feature</a>. After a few hours of development I&#8217;ve created a simple to use module which mimics ActiveRecord&#8217;s find method interface and allows us to perform queries like the following (sometimes even more powerful than AR):</p>
<div class="codecolorer-container ruby" style="height:280px;"><div class="codecolorer" style="font-family: monospace;">browser = <span class="re2">Scribd::SphinxBrowser</span>.<span class="me1">new</span><span class="br0">&#40;</span><span class="re3">:host</span> =&gt; <span class="st0">'ip.add.re.ss'</span><span class="br0">&#41;</span><br /><br><br /><br><span class="co1"># Get top 10 hottest docs</span><br /><br>result = browser.<span class="me1">browse</span><br /><br><br /><br><span class="co1"># Get top 10 most commented docs this week</span><br /><br>result = browser.<span class="me1">browse</span><span class="br0">&#40;</span><span class="re3">:order</span> =&gt; <span class="st0">'comments_week DESC'</span><span class="br0">&#41;</span><br /><br><br /><br><span class="co1"># Get top 5 most voted docs of all times</span><br /><br>result = browser.<span class="me1">browse</span><span class="br0">&#40;</span><span class="re3">:order</span> =&gt; <span class="st0">'votes_total DESC'</span>, <span class="re3">:limit</span> =&gt; <span class="nu0">5</span><span class="br0">&#41;</span><br /><br><br /><br><span class="co1"># Get top 10 most viewed docs for today (only docs with language_id = 5 returned)</span><br /><br>result = browser.<span class="me1">browse</span><span class="br0">&#40;</span><span class="re3">:order</span> =&gt; <span class="st0">'views_today DESC'</span>, <span class="re3">:filters</span> =&gt; <span class="br0">&#123;</span> <span class="re3">:language_id</span> =&gt; <span class="nu0">5</span> <span class="br0">&#125;</span><span class="br0">&#41;</span><br /><br><br /><br><span class="co1"># Get 10th to 19th hottest docs with language_id = 1, 2 or 3</span><br /><br>result = browser.<span class="me1">browse</span><span class="br0">&#40;</span><span class="re3">:filters</span> =&gt; <span class="br0">&#123;</span> <span class="re3">:language_id</span> =&gt; <span class="br0">&#91;</span><span class="nu0">1</span>, <span class="nu0">2</span>, <span class="nu0">3</span><span class="br0">&#93;</span> <span class="br0">&#125;</span>, <span class="re3">:limit</span> =&gt; <span class="nu0">10</span>, <span class="re3">:offset</span> =&gt; <span class="nu0">10</span><span class="br0">&#41;</span><br /><br><br /><br><span class="co1"># Get top 10 hottest docs with language_id = 1 and pages count between 1 and 10 (excluding doc with ID = 5)</span><br /><br>result = browser.<span class="me1">browse</span><span class="br0">&#40;</span><span class="re3">:filters</span> =&gt; <span class="br0">&#123;</span> <span class="re3">:language_id</span> =&gt; <span class="nu0">1</span>, <span class="re3">:page_count</span> =&gt; <span class="nu0">1</span>..<span class="nu0">10</span> <span class="br0">&#125;</span>, <span class="re3">:remove_id</span> =&gt; <span class="nu0">5</span><span class="br0">&#41;</span><br /><br><br /><br><span class="co1"># Get top 10 latest docs with file_type = 1 and word_user_id = 12345</span><br /><br>result = browser.<span class="me1">browse</span><span class="br0">&#40;</span><span class="re3">:order</span> =&gt; <span class="st0">'created_at DESC'</span>, <span class="re3">:filters</span> =&gt; <span class="br0">&#123;</span> <span class="re3">:file_type</span> =&gt; <span class="nu0">1</span>, <span class="re3">:user_id</span> =&gt; <span class="nu0">12345</span> <span class="br0">&#125;</span><span class="br0">&#41;</span></div></div>
<p>After a short testing we&#8217;ve got our performance benchmarks results and here are some facts: </p>
<ul>
<li>documents count - 3000000+</li>
<li>re-indexing time - 20-30 seconds for an entire data set (4 large joined tables)</li>
<li>longest query (surprisingly - a query without any filters) takes about 0.5 sec on one core</li>
<li>generic query with 1-2 filters takes 0.01-0.05 sec on one core</li>
<li>queries with many filters take 0.01 sec and less on one core</li>
<li>queries time could be reduced almost linearly when adding more cores (splitting index on many pieces).</li>
<li>sphinx scales really easily on more than one box if we&#8217;ll need it to.</li>
</ul>
<p>As you can see here, it is really useful sometimes to think &#8220;out of the box&#8221; when you work with some tools - we were using sphinx for a quite a long time now, but this solution for browsing was like a blessing and really helped us to keep up with service popularity growth.</p>

<p><a href="http://feeds.feedburner.com/~a/Homo-Adminus?a=l0gXBj"><img src="http://feeds.feedburner.com/~a/Homo-Adminus?i=l0gXBj" border="0"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~f/Homo-Adminus?a=CaKgo"><img src="http://feeds.feedburner.com/~f/Homo-Adminus?i=CaKgo" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/Homo-Adminus?a=PTQiO"><img src="http://feeds.feedburner.com/~f/Homo-Adminus?i=PTQiO" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/Homo-Adminus?a=DkXLo"><img src="http://feeds.feedburner.com/~f/Homo-Adminus?i=DkXLo" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://blog.kovyrin.net/2008/05/19/using-sphinx-for-non-fulltext-queries/feed/</wfw:commentRss>
		<feedburner:origLink>http://blog.kovyrin.net/2008/05/19/using-sphinx-for-non-fulltext-queries/</feedburner:origLink></item>
	</channel>
</rss>
