<?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>UNIXy &#187; Apache</title>
	<atom:link href="http://blog.unixy.net/tag/apache/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.unixy.net</link>
	<description>Fully Managed Dedicated Servers</description>
	<lastBuildDate>Fri, 03 Feb 2012 17:37:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>How does Varnish v3.0 compare to v2.1?</title>
		<link>http://blog.unixy.net/2011/07/how-does-varnish-v3-0-compare-to-v2-1/</link>
		<comments>http://blog.unixy.net/2011/07/how-does-varnish-v3-0-compare-to-v2-1/#comments</comments>
		<pubDate>Thu, 07 Jul 2011 06:32:10 +0000</pubDate>
		<dc:creator>Joe</dc:creator>
				<category><![CDATA[Interesting]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[2.1.x]]></category>
		<category><![CDATA[3.0]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[benchmark]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[UNIXy]]></category>
		<category><![CDATA[varnish]]></category>

		<guid isPermaLink="false">http://blog.unixy.net/?p=1356</guid>
		<description><![CDATA[We've performed a benchmark of Varnish Cache 2.1.4 vs 3.0.0. The results are outstanding!]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.unixy.net%2F2011%2F07%2Fhow-does-varnish-v3-0-compare-to-v2-1%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.unixy.net%2F2011%2F07%2Fhow-does-varnish-v3-0-compare-to-v2-1%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>We&#8217;ve just upgraded our cPanel <a title="Varnish" href="http://www.unixy.net/varnish">Varnish</a> plugin from Varnish 2.1.4 to 3.0.0. To kick off the new release I&#8217;ve performed a before and after <a title="Death Match Benchmark" href="http://blog.unixy.net/2011/06/death-match-benchmark-web-servers-battle-one-another/" target="_blank">benchmark</a> to get a feel of the performance boost. The results are outstanding! I spun up one <a title="VPS" href="http://www.unixy.net/vps-hosting" target="_blank">VPS</a>, loaded it with our plugin version 1.4.5rc1, and performed a benchmark using ab. Then loaded the same VPS with plugin version 1.4.5rc2 to perform the same benchmark. Keep in mind that these results are relative and that&#8217;s what I&#8217;m focusing on here.</p>
<p>Here are the VPS specs (typical of medium sized virtual machine):</p>
<ul>
<li><strong>4-core Opteron Magny-Cours </strong>(vcpu allocation)</li>
<li><strong>1gb ddr3</strong></li>
<li><strong>thread_pools@2 and thread_pool_min@200</strong></li>
<li><strong>Custom VCL </strong>(same across both experiments)</li>
</ul>
<p>Here are the results from the first run against 2.1.4 (<a title="ab results" href="http://www.unixy.net/files/ab.2.out" target="_blank">full ab results</a>):</p>
<pre>Concurrency Level:      1600
Time taken for tests:   1.514520 seconds
Complete requests:      10000
Failed requests:        0
Write errors:           0
Total transferred:      3764888 bytes
HTML transferred:       60078 bytes
Requests per second:    <strong>6602.75</strong> [#/sec] (mean)
Time per request:       242.323 [ms] (mean)
Time per request:       0.151 [ms] (mean, across all concurrent requests)
Transfer rate:          2427.17 [Kbytes/sec] received</pre>
<p>Here are the results from the first run against 3.0.0 (<a title="ab results" href="http://www.unixy.net/files/ab.3.out" target="_blank">full ab results</a>):</p>
<pre>Concurrency Level:      1600
Time taken for tests:   1.371934 seconds
Complete requests:      10000
Failed requests:        0
Write errors:           0
Total transferred:      4001094 bytes
HTML transferred:       60318 bytes
Requests per second:    <strong>7288.98</strong> [#/sec] (mean)
Time per request:       219.509 [ms] (mean)
Time per request:       0.137 [ms] (mean, across all concurrent requests)
Transfer rate:          2847.80 [Kbytes/sec] received</pre>
<p>It&#8217;s important to note that the resources allocated to both experiments are the same and the goal is to stress test 2.1.4 and 3.0.0. Release 3.0.0 is over 600 requests per second or 10% faster than 2.1.4, which is great! Congratulations to the Varnish Cache dev team for job well done :)</p>
<p>That&#8217;s all folks!</p>
<h2><strong>About UNIXY</strong></h2>
<p><a title="UNIXY" href="http://www.unixy.net">UNIXY</a> is a long-time Varnish Cache user and evangelist. They have been offering Varnish acceleration to their clients for more than three years. They have released the first c<a title="cPanel Varnish" href="http://www.unixy.net/varnish">Panel Varnish plugin</a> as well as spun a new startup,<a title="Fastlayer" href="http://fastlayer.com">Fastlayer</a>, the on-demand HTTP accelerator for the <a title="Fastlayer for the cloud" href="http://fastlayer.com">cloud</a>.</p>
<p style="text-align: center;"><a href="http://fastlayer.com"><img class="aligncenter" title="Fastlayer" src="http://fastlayer.com/wp-content/uploads/2011/05/logo2.png" alt="" width="184" height="64" /></a><br />
That&#8217;s all folks!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.unixy.net/2011/07/how-does-varnish-v3-0-compare-to-v2-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Death Match Benchmark &#8211; Web Servers Battle One Another</title>
		<link>http://blog.unixy.net/2011/06/death-match-benchmark-web-servers-battle-one-another/</link>
		<comments>http://blog.unixy.net/2011/06/death-match-benchmark-web-servers-battle-one-another/#comments</comments>
		<pubDate>Wed, 22 Jun 2011 03:46:00 +0000</pubDate>
		<dc:creator>UNIXy</dc:creator>
				<category><![CDATA[Interesting]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[benchmark]]></category>
		<category><![CDATA[death match]]></category>
		<category><![CDATA[fastlayer]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[varnish]]></category>
		<category><![CDATA[web server]]></category>

		<guid isPermaLink="false">http://blog.unixy.net/?p=1301</guid>
		<description><![CDATA[Here is a post detailing an interesting setup of Web servers made to go against one another in real time. This could prove to be entertaining for benchmarkers or perhaps decisive for those who need an ultimate killer proof that their favorite Web server can kick some behind.]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.unixy.net%2F2011%2F06%2Fdeath-match-benchmark-web-servers-battle-one-another%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.unixy.net%2F2011%2F06%2Fdeath-match-benchmark-web-servers-battle-one-another%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p style="text-align: left;">Here is a post detailing an interesting setup of <a title="Web server" href="http://www.unixy.net/advanced-hosting" target="_blank">Web servers</a> made to go against one another in real time. This could prove to be entertaining for benchmarkers or perhaps decisive for those who need an ultimate <em>killer</em> proof that their favorite Web server can kick some behind.</p>
<p>Definition of <a title="Server" href="http://www.unixy.net">server</a> Web benchmarking (according to Wikipedia):</p>
<blockquote><p>It is the process of estimating a web server performance in order to find if the server can serve sufficiently high workload [sic].</p></blockquote>
<p>In this article, I&#8217;m going to butcher this definition and depart from the tradition &#8211; a tad bit. Here are a some interesting questions that come to mind: What if the end goal is not to obtain measurements but to take a knock-out approach? What if we were to put three Web servers all against one another is a threesome match? Is the outcome of this death match meaningful? How do we select the winner? Switching gears forward a bit, could this death match approach be maliciously leveraged in a <a title="Botnet" href="http://en.wikipedia.org/wiki/Botnet" target="_blank">botnet</a> situation?</p>
<p><img class="aligncenter size-full wp-image-1331" title="Death Match Diagram" src="http://blog.unixy.net/wp-content/uploads/2011/06/dmdiag.png" alt="" width="404" height="306" /></p>
<p>Let&#8217;s dive right into the code! But first, let&#8217;s discuss the logic necessary to trigger, enable, and maintain a match until death occurs or an apparent draw ensues. The death match in this post is triggered via a single GET action from a regular browser and can be sent to any Web server (or all) that is participating in the fight. The trigger calls a server-side python script called <a title="Bench.py" href="http://www.unixy.net/files/bench.py" target="_blank">bench.py</a>, which in turns forks a threaded python program, called <em><a title="Benchlet.py" href="http://www.unixy.net/files/benchlet.py" target="_blank">benchlet.py</a></em>, that perpetuates the  match. Each Web server participating in the death match receives a GET request and then resonates another similar multi-threaded request against the other Web server. This back and forth exchange escalates the match further and further&#8230;until death occurs.</p>
<p>&nbsp;</p>
<p><a href="http://blog.unixy.net/wp-content/uploads/2011/06/bench.py_.png"><img class="aligncenter size-full wp-image-1314" title="Bench.py" src="http://blog.unixy.net/wp-content/uploads/2011/06/bench.py_.png" alt="" width="547" height="120" /></a></p>
<p>&nbsp;</p>
<p style="text-align: center;"><a href="http://blog.unixy.net/wp-content/uploads/2011/06/benchlet.py_2.png"><img class="aligncenter size-full wp-image-1317" title="Benchlet.py" src="http://blog.unixy.net/wp-content/uploads/2011/06/benchlet.py_2.png" alt="" width="350" height="304" /></a></p>
<p>&nbsp;</p>
<p>The following video illustrates the trigger action and an excerpt from the match.</p>
<p>&nbsp;</p>
<p><object width="640" height="390"><param name="movie" value="http://www.youtube.com/v/iZl2NSZomHA&amp;hl=en_US&amp;feature=player_embedded&amp;version=3" /><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="always" /><embed type="application/x-shockwave-flash" width="640" height="390" src="http://www.youtube.com/v/iZl2NSZomHA&amp;hl=en_US&amp;feature=player_embedded&amp;version=3&amp;rel=0" rel="0" allowfullscreen="true" allowscriptaccess="always"></embed></object></p>
<p>The mechanism used to trigger and maintain the match is written in python but it could be just about any server-side processing language like PHP or Ruby.</p>
<p><strong>About UNIXy</strong></p>
<p>UNIXy is a fully managed server and cluster services providers with a focus on high traffic Web sites. Server and cluster management is offered courtesy at not extra costs to their clients. They have been offering <a title="Varnish" href="http://www.unixy.net/varnish">Varnish</a> acceleration to their clients for more than three years. They have released the first c<a title="cPanel Varnish" href="http://www.unixy.net/varnish">Panel Varnish plugin</a> as well as spun a new startup, <a title="Fastlayer" href="http://fastlayer.com/">Fastlayer</a>, the on-demand HTTP accelerator for the <a title="Fastlayer for the cloud" href="http://fastlayer.com/">cloud</a>.</p>
<p>That&#8217;s all folks!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.unixy.net/2011/06/death-match-benchmark-web-servers-battle-one-another/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Notable changes in Apache 2.4 release</title>
		<link>http://blog.unixy.net/2010/11/notable-changes-in-apache-2-4-release/</link>
		<comments>http://blog.unixy.net/2010/11/notable-changes-in-apache-2-4-release/#comments</comments>
		<pubDate>Sat, 13 Nov 2010 04:26:29 +0000</pubDate>
		<dc:creator>UNIXy</dc:creator>
				<category><![CDATA[Future]]></category>
		<category><![CDATA[Interesting]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[Apache 2.4]]></category>
		<category><![CDATA[HTTPD]]></category>
		<category><![CDATA[release]]></category>

		<guid isPermaLink="false">http://blog.unixy.net/?p=995</guid>
		<description><![CDATA[If you haven't had a chance to check on the new features in the next release of Apache's HTTPD then here is a digest. The most notable changes have been made to the core and those are KeepAliveTimeout and Loadable MPMs]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.unixy.net%2F2010%2F11%2Fnotable-changes-in-apache-2-4-release%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.unixy.net%2F2010%2F11%2Fnotable-changes-in-apache-2-4-release%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>If you haven&#8217;t had a chance to check on the new features in the next release of Apache&#8217;s HTTPD then here is a digest. The most notable changes have been made to the core and those are KeepAliveTimeout and Loadable MPMs. One interesting change is the addition of mod_lua; lua being an embeddable scripting language that is not so popular in the Web app world. Interesting nonetheless&#8230;</p>
<p>In Apache 2.2, the KeepAliveTimeout directive tells Apache how many seconds  it should wait for subsequent requests from the same client before it closes the connection. In Apache 2.4, KeepAliveTimeout can be specified in milliseconds. If you&#8217;ve ever had to fine tune Apache, you know this is good news. It means Apache can shed and/or recycle idle threads much faster providing more bandwidth to handle more connections.</p>
<p>Also in Apache 2.4, you now have the option to pre-build all MPMs (like prefork, event, and worker) and then switch back and forth amongst them as needed at runtime. This is more of a convenience feature than anything else.</p>
<p>That&#8217;s all folks!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.unixy.net/2010/11/notable-changes-in-apache-2-4-release/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>3-state throttle Web server</title>
		<link>http://blog.unixy.net/2010/11/3-state-throttle-web-server/</link>
		<comments>http://blog.unixy.net/2010/11/3-state-throttle-web-server/#comments</comments>
		<pubDate>Sat, 06 Nov 2010 21:05:27 +0000</pubDate>
		<dc:creator>UNIXy</dc:creator>
				<category><![CDATA[Challenge]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[3-state server]]></category>
		<category><![CDATA[adaptable server]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[dugg]]></category>
		<category><![CDATA[managed server]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[slashdotted]]></category>
		<category><![CDATA[varnish]]></category>
		<category><![CDATA[web server]]></category>

		<guid isPermaLink="false">http://blog.unixy.net/?p=798</guid>
		<description><![CDATA[While we are in the business of providing managed server and cluster services, some folks still keep it a heart to manage their own dedicated server nodes. Incontestably, and however much you cherish your web servers, family always takes priority. In this post, we are going to cover a peculiar server configuration that can adapt to abnormal traffic without the server dropping down.]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.unixy.net%2F2010%2F11%2F3-state-throttle-web-server%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.unixy.net%2F2010%2F11%2F3-state-throttle-web-server%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Update (2011-03-14): UNIXy has released the first &#038; only <a href="http://www.unixy.net/varnish">cPanel Varnish</a> Plugin. The plugin installs, configures, and makes it very easy to manage Varnish via WHM. The plugin is fully integrated with cPanel EasyApache, cPanel URLs, and everything else that makes a functional cPanel server. Read about it more here: <a href="http://www.unixy.net/varnish">http://www.unixy.net/varnish</a></p>
<p>While we are in the business of providing <a title="Managed server" href="http://www.unixy.net" target="_self">managed server</a> and <a title="Cluster Services" href="http://www.unixy.net/advanced-hosting">cluster services</a>, some folks still keep it a heart to manage their own <a title="dedicated server" href="http://www.unixy.net" target="_self">dedicated server</a> or <a title="VPS" href="http://www.unixy.net/vps-hosting" target="_self">vps</a> nodes. Incontestably, and however much you cherish your web servers, family always takes priority. In this post, we are going to cover a peculiar <a title="Server" href="http://www.unixy.net">server</a> configuration that can adapt to abnormal traffic without the server dropping down to its knees or you getting involved&#8230; at 3AM on new year&#8217;s eve.</p>
<p>The goal is to configure such server to be autonomous for weeks or months at a time without requiring your involvement. Based on observatory experience, we decided to develop a 3-state throttle mechanism where each state is triggered based on server vitals like load average (run queue depth).</p>
<div id="attachment_848" class="wp-caption aligncenter" style="width: 429px"><a href="http://blog.unixy.net/wp-content/uploads/2010/10/3-state.png"><img class="size-full wp-image-848" title="3-state throttle Web server" src="http://blog.unixy.net/wp-content/uploads/2010/10/3-state.png" alt="3-state throttle Web server" width="419" height="239" /></a><p class="wp-caption-text">3-state throttle Web server</p></div>
<p>Let&#8217;s lay down the requirements and goals. We want our shiny adaptable server to be able to:</p>
<ol>
<li><strong>graciously handle <a title="C10K Problem" href="http://en.wikipedia.org/wiki/C10k_problem" target="_blank">C10K</a></strong><strong> challenges</strong></li>
<li><strong>handle a Slashdot / Digg effect without dropping off the net</strong></li>
<li><strong>change operating state and adapt to the traffic load</strong></li>
</ol>
<p><strong>Background</strong></p>
<p>Before we delve into the specifics, we&#8217;ll need to cover some important aspects of high performance web servers. All web servers, at least the ones worthy to be called as such, must implement the standards defined in RFC2616. What differentiates these web servers, however, is their feature set and their ability to manage large sets of concurrent connections. More specifically, they need to be able to handle the C10K problem gracefully. At least that&#8217;s what matters the most to us in this article.</p>
<p>So what is this C10K problem? C10K is a condensed term coined to mean 10000 concurrent clients. A Web server that solves the C10K problem should be able to handle much more than 10000 concurrent connections transferring small-size files on a <a title="100TB data transfer on 1Gbps link for $500/Mo!" href="http://unixy.net/100tb-managed-server/" target="_self">1Gbps</a> internet connection using 1GB of memory without causing any noticeable slow down</p>
<p>At a first glance, the C10K challenge appears to be easily achievable. The truth of the matter, the implementation not only requires efficient programming but also a mastery of low level system API and system calls. We&#8217;re not going to cover the fine details here. But implementors that focus too much on looking good in benchmarks end up building software that performs poorly in the real world. As a matter of fact, such systems have little practicality in this new hip Web world.</p>
<p>In this new hip online world, serving static files represent a very tiny fraction of the work put forth by a Web server. Server side processing accounts for the majority of the effort. So now not only do we expect a Web server to deliver relatively-simple static objects at sub milisecond speeds but also hold it accountable for the time it takes to complete server-side request. Server-side requests could be anything from PHP, Perl, to Python and Ruby. It doesn&#8217;t matter.</p>
<p><strong>Implementation</strong></p>
<p>How are we going to achieve this bullet proof Web server? We have been imposed the following requirement as far as Web server stack:</p>
<ul>
<li><strong>Linux 2.6.x</strong></li>
<li><strong>Apache 2.2.x</strong></li>
<li><strong>MySQL 5.x</strong></li>
<li><strong>PHP 5.2.x</strong></li>
</ul>
<p>While the requirement is reasonable we still need a secret sauce engine that will make a decision for us so we know how to throttle back and forth between the three states. We have very little flexibility in implementing this engine &#8220;inside&#8221; the LAMP stack as it means fiddling with the client&#8217;s environment. We needed a seamless dynamic way of throttling. That is no Web server restarts are permitted and the whole throttling action should take less than a 100ms.</p>
<p>We decided to leverage <a title="Varnish Cache Forum" href="http://www.varnish-cache.info">Varnish</a> Cache&#8217;s ability to load and compile a new set of configuration instructions on the fly. This essential function is not the only feature that sold us; the main advantage is that Varnish is a very capable caching engine and satisfies all three of our initial requirements (adaptability, state machine, C10K). We will load three Varnish configuration and these are as follow:</p>
<ul>
<li><strong>Light configuration:</strong></li>
</ul>
<p style="padding-left: 60px;">This configuration of Varnish caches static files only. We&#8217;re still letting Apache do a lot of leg work still and that is fine considering we&#8217;re getting low traffic in this state and a low impact on perceivable performance.</p>
<ul>
<li><strong>Moderate configuration:</strong></li>
</ul>
<p style="padding-left: 60px;">In this state, we enable caching but we respect cache control headers coming out of Apache and PHP. In other words, we cache only what we are told to cache. Sessions do not get cached in this state. Having too many &#8220;logged in&#8221; users could overpower the server. Hence, the need for a third state.</p>
<ul>
<li><strong>Heavy configuration:</strong></li>
</ul>
<p style="padding-left: 60px;">Enable caching but still respecting cache headers. Additionally, we enable per-user session caching (cookie based caching). There needs to be plenty of memory to handle as many users as possible since Varnish will be creating a cache entry for each registered user and accessed object.</p>
<p style="padding-left: 60px;">
<p><a href="http://blog.unixy.net/wp-content/uploads/2010/10/varnishsm.png"><img class="aligncenter size-full wp-image-853" title="State Diagram" src="http://blog.unixy.net/wp-content/uploads/2010/10/varnishsm.png" alt="State Diagram" width="616" height="394" /></a></p>
<p>The above diagram illustrates the &#8220;gear switching&#8221; logic of our engine. The pieces that we need to implement this logic are the following:</p>
<ol>
<li>The decision engine based on overall system vitals</li>
<li>The Varnish configuration loader</li>
<li>A daemon to tie it all together</li>
</ol>
<p>We picked Python as as tool to accomplish the above. We decided to leverage the <a title="Python Daemon" href="http://pypi.python.org/pypi/python-daemon/">python-daemon</a> package as well as the <a title="Python Varnish Manager" href="http://pypi.python.org/packages/source/p/python-varnish" target="_blank">python-varnish manager</a>. The former gives the daemon functionality as we intend to run the engine full time in the background. The latter is a simple wrapper around telnetlib and an interface to interact with Varnish&#8217;s admin port.</p>
<p style="text-align: center;"><a href="http://blog.unixy.net/wp-content/uploads/2010/11/3statetop.png"><img class="aligncenter size-full wp-image-939" title="3state Daemon" src="http://blog.unixy.net/wp-content/uploads/2010/11/3statetop.png" alt="" width="600" height="50" /></a></p>
<p>One of the tricky questions we needed answered revolves around the mechanism used to trigger a state transition. We have already decided on the load average being the metric we poll and base our decision upon. What remains to be determined is the value threshold that triggers the transition. A high load average does not always mean a stressed server nor does a low load average always mean an optimal server configuration.</p>
<p style="text-align: center;"><a href="http://blog.unixy.net/wp-content/uploads/2010/11/tstatecode.png"><img class="aligncenter size-full wp-image-947" title="3-state code" src="http://blog.unixy.net/wp-content/uploads/2010/11/tstatecode.png" alt="" width="550" height="400" /></a></p>
<p>As a rule of thumb, however, and based on experience, the load average is almost always reflective of resource capacity. We we are going to have to trust the kernel on this one. While we have covered the when, the how still needs some demonstration. As mentioned above, Varnish comes with a neat feature that allows it to load and use a new configuration file on the fly. It takes the new configuration, compiles it, and finally loads it up for execution. All of that without dropping a packet. Think of it as importing a python module at run-time. Here is a quick demo:</p>
<p><a href="http://blog.unixy.net/wp-content/uploads/2010/11/helpvarnish.png"><img class="aligncenter size-full wp-image-949" title="helpvarnish" src="http://blog.unixy.net/wp-content/uploads/2010/11/helpvarnish.png" alt="" width="600" height="250" /></a></p>
<p>Here is now where the on-the-fly loading of our config happens. Of course, with our Python daemon program the state transitions are triggered depending on the load:</p>
<p><a href="http://blog.unixy.net/wp-content/uploads/2010/11/loadvarnish.png"><img class="aligncenter size-full wp-image-950" title="Load the configs" src="http://blog.unixy.net/wp-content/uploads/2010/11/loadvarnish.png" alt="" width="600" height="350" /></a></p>
<p>To recap, we wrote a program, python daemon, that monitors the vitals of a dedicated server and then determines the next step to take. In this case, we have preloaded our caching engine with three configurations: light, moderate, and heavy. These configurations anticipate and handle different levels of traffic and load. Our python program makes use of any of the three configurations by loading them into Varnish.</p>
<p>That&#8217;s all folks! We hope you enjoyed this article.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.unixy.net/2010/11/3-state-throttle-web-server/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Nginx + Drupal + imagecache + Apache + proxy_pass + 404</title>
		<link>http://blog.unixy.net/2010/09/nginx-drupal-imagecache-apache-proxy_pass-404/</link>
		<comments>http://blog.unixy.net/2010/09/nginx-drupal-imagecache-apache-proxy_pass-404/#comments</comments>
		<pubDate>Fri, 10 Sep 2010 18:58:53 +0000</pubDate>
		<dc:creator>UNIXy</dc:creator>
				<category><![CDATA[Break-Fix]]></category>
		<category><![CDATA[404]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[apache backend]]></category>
		<category><![CDATA[Drupal]]></category>
		<category><![CDATA[error_page]]></category>
		<category><![CDATA[imagecache]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[nginx.conf]]></category>
		<category><![CDATA[reverse proxy]]></category>

		<guid isPermaLink="false">http://blog.unixy.net/?p=565</guid>
		<description><![CDATA[Here is a workaround to the Drupal imagecache issue with Nginx running as a reverse proxy to Apache.]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.unixy.net%2F2010%2F09%2Fnginx-drupal-imagecache-apache-proxy_pass-404%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.unixy.net%2F2010%2F09%2Fnginx-drupal-imagecache-apache-proxy_pass-404%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Here is a <em>workaround</em> to the Drupal imagecache issue with <a title="Nginx High Performance Web Server" href="http://nginx.org" target="_blank">Nginx</a> running as a reverse proxy to <a title="Apache Web Server" href="http://apache.org" target="_blank">Apache</a>. From <a title="Drupal" href="http://drupal.org" target="_blank">Drupal</a>, ImageCache is:</p>
<blockquote><p>ImageCache allows you to setup presets for image processing. If an ImageCache derivative doesn&#8217;t exist the web server&#8217;s rewrite rules will pass the request to Drupal which in turn hands it off to ImageCache to dynamically generate the file.</p></blockquote>
<p>So Nginx shouldn&#8217;t try to serve static files from this directory unless they exist. Otherwise, it will generate a 404 and images will break. With this fix, we are catching the 404 generated by Nginx on static files. We are then forwarding the request to Apache (proxy_pass) so it processes it correctly. We are also caching all 404s for 1 minute to avoid slamming Apache. Be sure to &#8220;fix&#8221; all the other 404 errors so Apache does the least amount work. Most of the time, these 404 errors come from missing favicon.ico or non-manipulated images.</p>
<blockquote>
<div id="_mcePaste">server {</div>
<div id="_mcePaste">access_log off;</div>
<div id="_mcePaste">error_log  logs/vhost-error_log warn;</div>
<div id="_mcePaste">listen    80;</div>
<div id="_mcePaste">server_name  www.unixy.net;</div>
<div id="_mcePaste">location @imagecache {</div>
<div id="_mcePaste">client_max_body_size    10m;</div>
<div id="_mcePaste">client_body_buffer_size 128k;</div>
<div id="_mcePaste">proxy_send_timeout   90;</div>
<div id="_mcePaste">proxy_read_timeout   90;</div>
<div id="_mcePaste">proxy_buffer_size    4k;</div>
<div id="_mcePaste">proxy_buffers     16 32k;</div>
<div id="_mcePaste">proxy_busy_buffers_size 64k;</div>
<div id="_mcePaste">proxy_temp_file_write_size 64k;</div>
<div id="_mcePaste">proxy_connect_timeout 30s;</div>
<div id="_mcePaste">proxy_redirect  http://www.unixy.net:81   http://www.unixy.net;</div>
<div id="_mcePaste">proxy_pass   http://1.1.1.1:81;</div>
<div id="_mcePaste">proxy_set_header   Host   $host;</div>
<div id="_mcePaste">proxy_set_header   X-Real-IP  $remote_addr;</div>
<div id="_mcePaste">proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;</div>
<div id="_mcePaste">}</div>
<p>location ~* \.(gif|jpg|jpeg|png|wmv|avi|mpg|mpeg|mp4|js|css|mp3|swf|ico|flv)$ {</p>
<p>root   /home/user/public_html;</p>
<p><strong> error_page    404 = @imagecache;</strong></p>
<p>proxy_cache my-cache;</p>
<p>proxy_cache_valid  200 302  10m;</p>
<p><strong> proxy_cache_valid  404  1m;</strong></p>
<p>}</p>
<p>location / {</p>
<p>client_max_body_size    10m;</p>
<p>client_body_buffer_size 128k;</p>
<p>proxy_send_timeout   90;</p>
<p>proxy_read_timeout   90;</p>
<p>proxy_buffer_size    4k;</p>
<p>proxy_buffers     16 32k;</p>
<p>proxy_busy_buffers_size 64k;</p>
<p>proxy_temp_file_write_size 64k;</p>
<p>proxy_connect_timeout 30s;</p>
<p>proxy_redirect  http://www.unixy.net:81   http://www.unixy.net;</p>
<p>proxy_pass   http://1.1.1.1:81/;</p>
<p>proxy_set_header   Host   $host;</p>
<p>proxy_set_header   X-Real-IP  $remote_addr;</p>
<p>proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;</p>
<p>}</p>
<p>}</p></blockquote>
<p>That&#8217;s all folks. We hope this is useful to someone.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.unixy.net/2010/09/nginx-drupal-imagecache-apache-proxy_pass-404/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The penultimate guide to stopping a DDoS attack &#8211; A new approach</title>
		<link>http://blog.unixy.net/2010/08/the-penultimate-guide-to-stopping-a-ddos-attack-a-new-approach/</link>
		<comments>http://blog.unixy.net/2010/08/the-penultimate-guide-to-stopping-a-ddos-attack-a-new-approach/#comments</comments>
		<pubDate>Wed, 25 Aug 2010 13:47:15 +0000</pubDate>
		<dc:creator>UNIXy</dc:creator>
				<category><![CDATA[Challenge]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[DDoS]]></category>
		<category><![CDATA[DoS]]></category>
		<category><![CDATA[large attack]]></category>
		<category><![CDATA[large DDoS attack]]></category>
		<category><![CDATA[mitigate DDoS]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[reverse proxy]]></category>
		<category><![CDATA[stop DDoS attack]]></category>

		<guid isPermaLink="false">http://blog.unixy.net/?p=479</guid>
		<description><![CDATA[Update (2011-03-24): In this article. we&#8217;re discussing how we leveraged the smart Russian-built Web server Nginx to stop a DDoS attack. We&#8217;ve also experimented quite a bit with Varnish, another fine half-Danish half-Norwegian open source software, as a DDoS mitigation tool. It can be made to form the same constellation that we used for Nginx [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.unixy.net%2F2010%2F08%2Fthe-penultimate-guide-to-stopping-a-ddos-attack-a-new-approach%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.unixy.net%2F2010%2F08%2Fthe-penultimate-guide-to-stopping-a-ddos-attack-a-new-approach%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p><strong>Update (2011-03-24)</strong>: In this article. we&#8217;re discussing how we leveraged the smart Russian-built Web server Nginx to stop a DDoS attack. We&#8217;ve also experimented quite a bit with Varnish, another fine half-Danish half-Norwegian open source software, as a DDoS mitigation tool. It can be made to form the same constellation that we used for Nginx but can perform much better in the face of a large DDoS. So it&#8217;s worth pursuing should you be interested (read: desperate). Shameful plug: check out our cPanel Varnish plugin: <a title="Varnish cPanel" href="http://www.unixy.net/varnish">http://www.unixy.net/varnish</a></p>
<p>In this post we (<a title="Fully Managed Dedicated Servers and Clusters" href="http://www.unixy.net" target="_blank">UNIXY</a>) are going to share our experience fending off a large <a title="Wikipedia Distributed Denial of Service Attack" href="http://en.wikipedia.org/wiki/Denial-of-service_attack" target="_blank">Distributed Denial of Service</a> (DDoS) attack for a client. Generally, Website owners deal with DDoS attacks on their own. There are equipment and solutions vendors cater to these owners and guarantee protection against these kind of attacks up to a certain threshold. The cost of hiring these vendors can range from thousands to hundreds of thousand or millions of dollars depending on the severity of the attack.</p>
<p>Our goal was to build a solution with the least amount of funds possible. This solution is scalable and can handle the worst attacks. The client&#8217;s dedicated server is not a special server but a simple quad core Xeon <strong><a title="UNIXY Managed Dedicated Server" href="http://www.unixy.net/dedicated-servers" target="_blank">managed server</a><span style="font-weight: normal;"> running the LAMP stack</span></strong>. The DDoS riposte described in this article can scale to stop a 10Gbps attack or more. The good news is this solution does not require changing anything on the <a title="UNIXY Dedicated Servers" href="http://www.unixy.net/dedicated-servers" target="_blank"><strong>dedicated server</strong></a> itself. The server could be running just about any software stack. This configuration will work just fine with almost all cases effortlessly.</p>
<ul>
<li><strong>Distributed Denial of Service &#8211; The Social</strong></li>
</ul>
<p>Before we delve into the glorious technical details, there is an important aspect of DDoS attacks that one should know about; that is the social dynamics that lead to the attack. The more one understands about the the social aspect of a DDoS attack the easier it becomes to prevent or stop it. Because once a DDoS has started, priorities shift quite dramatically and rational for making wise decisions becomes flawed.</p>
<div id="attachment_533" class="wp-caption aligncenter" style="width: 330px"><a href="http://blog.unixy.net/wp-content/uploads/2010/08/JimmyDDoS.png"><img class="size-full wp-image-533" title="DDoS comic" src="http://blog.unixy.net/wp-content/uploads/2010/08/JimmyDDoS.png" alt="DDoS comic" width="320" height="274" /></a><p class="wp-caption-text">DDoS comic</p></div>
<p>DDoS attacks do not occur randomly. They are targeted and come with a motive. The motive could be revenge but most of the time the motive is financial. The individual or groups that conduct the DDoS attacks are most of the time hired to complete the job. They have the resources and know-how to orchestrate the attack while hoping to avoid getting caught by the authorities. They have no emotional attachment to the DDoS attack itself; they have no hard feelings towards the victim. They just get paid for what they do and nonchalantly, but meticulously, execute.</p>
<p>As explained, DDoS attacks are preceded by an email, post, or phone call, from the individual or group with interest, to the victim. It is always recommended to treat strangers you meet online or offline professionally and politely. The smallest altercation can lead to a negative reaction, which can escalate actions. In the face of anonymous threats against your business or organization, remain calm and composed.</p>
<div id="attachment_517" class="wp-caption aligncenter" style="width: 410px"><a href="http://blog.unixy.net/wp-content/uploads/2010/08/DDoS_Offer_forum.png"><img class="size-medium wp-image-517 " title="DDoS Offer in Forum" src="http://blog.unixy.net/wp-content/uploads/2010/08/DDoS_Offer_forum-300x78.png" alt="DDoS Offer in Forum" width="400" height="100" /></a><p class="wp-caption-text">DDoS Offer in Forum</p></div>
<p>There are public markets online (please don&#8217;t ask for links) where wannabe DDoS perpetrators get to hire the attackers. Pricing varies from $5/hr to $10 for a simple non-distributed DoS attack. A DDoS, however, tends to be more expensive depending on the sheer amount of data or packets that needs to be delivered at the target. It can range from $20/hr to $100/hr. The word used to in the circles in lieu of DDoS is to &#8220;drop;&#8221; meaning to drop a certain Web site or network off the Internet. It really means to either overwhelm the target with enough traffic that the equipment fails or to force upstream providers to &#8220;null route&#8221; the destination IP at the network level. The end result is that the IP gets dropped from the routing tables and the server to stop responding to all requests.</p>
<p>The fact that DDoS is not cheap has got to be comforting to an extent. It means that it is only a matter of time before the DDoS &#8220;client&#8221; runs out of cash. This in itself is encouraging. Keep that in mind should you begin to lose patience. Perseverance is omnipotent. Denial of service attacks are considered a crime and are punishable by Federal law in the US and by the police in the UK. As we will explain in the technical part of this article, DDoS attacks are almost impossible to trace to back to the individual or group that are orchestrating the attack. Because of the distributed nature, it requires cooperation from several network engineers that work for upstream providers.</p>
<p><strong>Distributed Denial of Service &#8211; The Technicals</strong></p>
<p>First things first, What is a DoS? what is the difference between a DoS and DDoS? A Denial of Service (DoS) is an attack originating from one source or one system that results in the service in question being unavailable to its legitimate users. It denies its very users access either because the service runs out of available resources or has been tricked to deny access to legitimate users. For example, a DoS attack on a Web server can cause it to run out of resources and stop responding to requests. A DDoS, on the other hand, is a more sophisticated attack since the attack originates from hundreds or thousands or nodes.</p>
<p>A DDoS attack is almost impossible to trace back to the source due to its distributed nature. DDoS orchestrators call the nodes and controller system a &#8220;bot.&#8221; With a few commands, the bot owner can instruct infected nodes from around the world to attack a target. The bot systems are hosted and controlled via <a title="Wikipedia: Internet Relay Chat" href="http://en.wikipedia.org/wiki/Internet_Relay_Chat" target="_blank">the Internet Relay Chat</a> (IRC) system or via a direct connection port connection. The nodes used to attack the target are made of compromised Windows and Linux nodes from around the world.</p>
<p>Before we present our solution, we need to discuss the two types of DDoS attacks that exist. On one hand you have attacks are bandwidth-based and seek to saturate the connectivity link. On the other hand, you have attacks that are packet-based and seek to saturate the processing capability of the equipment. In other words, they seek to overwhelm the processing power of the CPU and memory  or <em>fabric</em> of the routers or switches. All equipment has hard limits when it comes to their ability to handle a certain number of packets per second. Routers and switches are no exception.</p>
<div id="attachment_529" class="wp-caption aligncenter" style="width: 440px"><a href="http://blog.unixy.net/wp-content/uploads/2010/08/MbpsVspps2.png"><img class="size-full wp-image-529 " title="Capacity of networking equipment - Mbps vs pps" src="http://blog.unixy.net/wp-content/uploads/2010/08/MbpsVspps2.png" alt="Capacity of networking equipment - Mbps vs pps" width="430" height="184" /></a><p class="wp-caption-text">Capacity of networking equipment - Mbps vs pps</p></div>
<p>For example, take the above specification for a Cisco 6500 firewall. Each module is able to handle 5Gbps <em>or </em>2.8 million pps. This firewall sure looks like it can handle a 5Gbps attack. Great! However, should there be a packet-based DDoS attack, one would only need a 1.5Gbps payload to saturate it. That&#8217;s 2.8 million pps * 64 Bytes = 1.5Gbps. So bandwidth capacity means nothing by itself and small packets can cause havoc.</p>
<p>Our client was facing a 2Gbps DDoS attack that is packet based. It sought to force routing equipment along the way to start dropping legitimate packets. This caused the upstream to null route the IP to alleviate the burden on other customers that are behind the link. This is the typical reaction from all upstreams as they seek to protect their many other customers from feeling the pinch of the attack. We were given one last chance to &#8220;fix&#8221; things before the IP could be routed back in. Here is how we were able to fend off the attack and keep the server running.</p>
<p>We have deployed what we call a &#8220;constellation&#8221; of reverse proxy VM or <a title="UNIXY Fully Managed VPS" href="http://www.unixy.net/vps-hosting" target="_blank">VPS</a> nodes running the high performance Web server Nginx. The VM nodes were purchased from several providers given they are located at separate facilities. Essentially, we are off-loading and &#8220;splitting&#8221; both packet processing and bandwidth consumption across several data center facilities (physical routers &amp; carriers).</p>
<div id="attachment_540" class="wp-caption aligncenter" style="width: 314px"><a href="http://blog.unixy.net/wp-content/uploads/2010/08/nginx_constellation.png"><img class="size-full wp-image-540" title="Nginx constellation" src="http://blog.unixy.net/wp-content/uploads/2010/08/nginx_constellation.png" alt="Nginx constellation" width="304" height="463" /></a><p class="wp-caption-text">Nginx constellation</p></div>
<p>The configuration of the Nginx nodes is a typical reverse proxy configuration with the usual extra kernel security configuration. So for a 2Gbps attack and with 20 VM nodes, the bandwidth consumption per node is a maximum of 2GBps / 20 = 100Mbps. That&#8217;s a 100Mbps load per <a title="Managed VPS" href="http://www.unixy.net/vps-hosting" target="_blank">VM</a> node, which is reasonable enough and is below the threshold for getting one&#8217;s IP null routed by the provider. One could add more and more Nginx nodes to the constellation without issues.</p>
<p>So how is 20 VM nodes going to be affordable? VM prices have dropped dramatically over the last year. For the above configuration, a VM can cost between $5/mo and $10/mo. That&#8217;s an average of $8*20 = $160/Mo. Knowing that most DDoS attackers have the attention span of a gold fish, the $160 is all you need to send your attacker and his accomplice packing.</p>
<p style="text-align: center;"><a href="http://blog.unixy.net/wp-content/uploads/2010/08/ddos_cost.png"><img class="size-full wp-image-545 aligncenter" title="Total cost for averting a 2Gbps attack" src="http://blog.unixy.net/wp-content/uploads/2010/08/ddos_cost.png" alt="Total cost for averting a 2Gbps attack" width="240" height="196" /></a></p>
<p style="text-align: center;">&nbsp;</p>
<p style="text-align: left;">Let&#8217;s talk more about the Nginx constellation configuration. The Nginx front-end nodes will run in proxy mode caching static files and requests. The more aggressive the DDoS the higher the time-to-live for cache objects should be. This prevents the Nginx nodes from proxy-passing requests to the quad core node. Although, if the main node has idle CPU and plenty of memory it wouldn&#8217;t hurt to put it to good use to alleviate the burden on the Nginx front nodes. Your domain&#8217;s A records is going to be the IP of the Nginx front nodes configured in round robin fashion. DNS round robin has its shortcomings in terms of not having control over how long (bad) records get cached by resolvers around the world. But in this case, it does not matter much. Just be sure to set high TTL for the records so your DNS server does not collapse under the enormous volume.</p>
<p style="text-align: left;">&nbsp;</p>
<div id="attachment_559" class="wp-caption aligncenter" style="width: 625px"><a href="http://blog.unixy.net/wp-content/uploads/2010/08/nginx_constellation3.png"><img class="size-full wp-image-559" title="Nginx DDoS Constellation" src="http://blog.unixy.net/wp-content/uploads/2010/08/nginx_constellation3.png" alt="Nginx DDoS Constellation" width="615" height="613" /></a><p class="wp-caption-text">Nginx DDoS Constellation</p></div>
<p>There are tons of online tutorials that go over the installation of Nginx as a reverse proxy so be sure to read up on it. But we will list some of the peculiar settings that are needed to handle a large scale DDoS. Of importance is the number of Nginx worker processes and worker connections. Those values will need to adjusted gradually and higher to handle different kind of attacks depending the VM resource allocation. But you should set them at least as high as the following:</p>
<blockquote><p>worker_processes 8;<br />
events {<br />
.<br />
.<br />
worker_connections 4096; # Be sure to set ulimit -n 4096 or more<br />
.<br />
.<br />
}</p></blockquote>
<p>Keep in mind that one still needs to gear up for the event by setting kernel and system variables on the Nginx nodes. Simple things like per-IP rate limiting, flooding rate limits, and syn cookies should be enabled without a question. Here are some measures you can implement:</p>
<blockquote><p>net.ipv4.tcp_syncookies = 1<br />
# source validation / reversed path<br />
net.ipv4.conf.all.rp_filter = 1<br />
net.ipv4.conf.default.rp_filter = 1<br />
kernel.pid_max = 65536<br />
net.ipv4.ip_local_port_range = 9000 65000</p></blockquote>
<p><strong>Recap</strong></p>
<p>In brief, here are the elements that constitute our solution:</p>
<ul>
<li><strong>Nginx reverse proxy constellation</strong></li>
<li><strong>DNS round robin records</strong></li>
<li><strong>Security at the Nginx front end level</strong></li>
<li><strong>Know the social and technical dynamics behind DDoS attacks</strong></li>
</ul>
<p>That&#8217;s all folks. We hope you enjoyed this article. Should you have any question or comment, don&#8217;t hesitate to get in touch! No question is minor and we are always looking for feedback.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.unixy.net/2010/08/the-penultimate-guide-to-stopping-a-ddos-attack-a-new-approach/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

