<?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>Hello, I am Sean Murphy &#187; haproxy</title>
	<atom:link href="http://iamseanmurphy.com/tag/haproxy/feed/" rel="self" type="application/rss+xml" />
	<link>http://iamseanmurphy.com</link>
	<description>Thoughts, news, code by Sean Murphy</description>
	<lastBuildDate>Thu, 26 Jan 2012 02:37:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>A Better HAProxy Health Check For Dynamic Websites</title>
		<link>http://iamseanmurphy.com/2009/04/22/a-better-haproxy-health-check-for-dynamic-websites/</link>
		<comments>http://iamseanmurphy.com/2009/04/22/a-better-haproxy-health-check-for-dynamic-websites/#comments</comments>
		<pubDate>Wed, 22 Apr 2009 16:14:50 +0000</pubDate>
		<dc:creator>Sean Murphy</dc:creator>
				<category><![CDATA[Scalability]]></category>
		<category><![CDATA[Work]]></category>
		<category><![CDATA[fastcgi]]></category>
		<category><![CDATA[fcgi]]></category>
		<category><![CDATA[haproxy]]></category>
		<category><![CDATA[high availablity]]></category>
		<category><![CDATA[load balancing]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[web server]]></category>

		<guid isPermaLink="false">http://iamseanmurphy.com/2009/04/22/a-better-haproxy-health-check-for-dynamic-websites/</guid>
		<description><![CDATA[Nobody wants their website to go down, or worse, for users to notice the site is down. Because of this most larger websites will run on multiple servers to provide some level of high availability. In a multi-server architecture there is typically a load balancer (or cluster of load balancers) to distribute the load among [...]]]></description>
			<content:encoded><![CDATA[<p>Nobody wants their website to go down, or worse, for users to <em>notice</em> the site is down. Because of this most larger websites will run on multiple servers to provide some level of high availability. In a multi-server architecture there is typically a load balancer (or cluster of load balancers) to distribute the load among a pool of web servers. When a server goes down it&#8217;s taken out of the pool until it is once again ready to handle requests. HAProxy (a software load balancer) has the ability to perform this task by doing periodic health checks on all the servers in a cluster. The default settings, though, could give false positives in some cases, and thus create a bad user experience by allowing ill application servers to continue receiving requests.</p>
<p><span id="more-33"></span><br />
When in HTTP mode HAProxy&#8217;s default health check is a simple OPTIONS request. This has the advantage of being a very lightweight request, and is easy to identify and filter from server logs. Consider this scenario though: HAProxy balances the load between several web servers running nginx and PHP-FastCGI. If nginx is up but PHP-FastCGI goes down, nginx will still properly handle the OPTIONS request from HAProxy, giving the impression that all is well. HAProxy continues sending requests to the ill server which in turn get a 504 Gateway Timeout (or similar) response. Not a very good situation.</p>
<p>A solution would be to use a deeper health check, one that goes beyond nginx to the PHP-FastCGI process. That way if PHP-FastCGI goes down, the whole server is presumed &#8216;down&#8217;.</p>
<pre>
backend appservers

 mode http

 option httpchk HEAD /health_check.php HTTP/1.1\r\nHost:\ example.com

 server web1 x.x.x.x:80 weight 5 check inter 2000

 server web2 x.x.x.x:80 weight 5 check inter 2000

 server web3 x.x.x.x:80 weight 5 check inter 2000</pre>
<p>In the above example I&#8217;m using a custom health check request which will be processed by PHP-FastCGI. health_check.php is a lightweight script that contains simply <code>&lt;?php echo "I'm healthy"; ?&gt;</code>. I also added a host header so that the health check will be handled by a specific nginx virtual host. The nginx vhost config has this in it:</p>
<pre>
location = /health_check.php {

 access_log		off;

 fastcgi_pass	127.0.0.1:9000;

 fastcgi_index	index.php;

 include	/etc/nginx/fastcgi_params;

}</pre>
<p>And there you have it&#8211;a better HAProxy health check for dynamic websites.</p>
]]></content:encoded>
			<wfw:commentRss>http://iamseanmurphy.com/2009/04/22/a-better-haproxy-health-check-for-dynamic-websites/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>High Performance Comet on a Shoestring</title>
		<link>http://iamseanmurphy.com/2009/03/02/high-performance-comet-on-a-shoestring/</link>
		<comments>http://iamseanmurphy.com/2009/03/02/high-performance-comet-on-a-shoestring/#comments</comments>
		<pubDate>Tue, 03 Mar 2009 03:34:33 +0000</pubDate>
		<dc:creator>Sean Murphy</dc:creator>
				<category><![CDATA[Performance]]></category>
		<category><![CDATA[Scalability]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[comet]]></category>
		<category><![CDATA[haproxy]]></category>
		<category><![CDATA[ip addresses]]></category>
		<category><![CDATA[meteor]]></category>
		<category><![CDATA[network load balancing]]></category>
		<category><![CDATA[ports]]></category>
		<category><![CDATA[servers]]></category>

		<guid isPermaLink="false">http://iamseanmurphy.com/2009/03/02/high-performance-comet-on-a-shoestring/</guid>
		<description><![CDATA[I&#8217;ve had my eye on the advances that are being made in the Comet arena for a while now, but it was only this past weekend that I finally sat down and used it for a project. In doing so, there was a particular configuration problem I needed to address, and that was&#8230;uh, addressing. Introducing [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve had my eye on the advances that are being made in the Comet arena for a while now, but it was only this past weekend that I finally sat down and used it for a project. In doing so, there was a particular configuration problem I needed to address, and that was&#8230;uh, addressing.</p>
<p>Introducing Comet to an existing architecture assumes there is already a web server in the neighborhood, and that it is, in one way or another, receiving traffic from port 80. Due to the fact that many site visitors will likely be positioned behind a firewall unwilling to accept connections on ports other than 80 or 443, we also need to get our Comet server running on port 80 as well. This normally wouldn&#8217;t be much of a problem at all, unless you don&#8217;t want to fork over the money for an extra IP address. I don&#8217;t &amp; I didn&#8217;t. So let me show you how I did so.</p>
<p><span id="more-28"></span><br />
As I eluded to above, to solve this problem of running two services on the same port in the same server environment you would normally have two different IP addresses assigned to the same front-end server. This is typically a load balancer or firewall, but these could also be running on the same machine as a web server and Comet server. The load balancer would then accept requests for x.x.x.1:80 and send them to the web server, and requests for x.x.x.2:80 would go to the Comet server. However if we only have one IP address that means we have to route requests based on a higher network layer, the Application Layer (7). Now we route by domain name.</p>
<p>In fact, that is something most web servers can handle using name-based virtual hosts. &#8220;So why not set-up Apache to reverse-proxy requests to the Comet server?&#8221;, you ask. Well, that would work. The reason Comet servers even exists though, is because web server connection threads are too heavy to support the level of concurrency Comet requires (for a decent number of users). This is where the &#8220;high performance&#8221; part comes in. HAProxy is a fantastic high performance layer 7 load balancer. Using HAProxy&#8217;s ACL feature we can basically mimic Apache virtual hosts. Consider this example snippet from haproxy.cfg:</p>
<pre name="code">
frontend www *:80
    mode http
    acl comet hdr_beg(host) comet.
    use_backend meteor if comet

default_backend apachebackend meteor
    mode http
    server server1 127.0.0.1:4670

backend apache
    mode http
    server server2 127.0.0.1:8080</pre>
<p>As you can see, I set up a front-end to accept all connections on port 80. Then I use an ACL to examine the HOST header and see if it begins with comet. (e.g. http://comet.example.com). If it does, the request is sent to the comet server on port 4670, and if not, requests go to Apache on port 8080. And there you have it, a high performance Comet installation with no money out-of-pocket.</p>
]]></content:encoded>
			<wfw:commentRss>http://iamseanmurphy.com/2009/03/02/high-performance-comet-on-a-shoestring/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

