<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>lighty's life: Hash Balancing with mod_proxy_core</title>
    <link>http://blog.lighttpd.net/articles/2006/07/19/hash-balancing-with-mod_proxy_core</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description></description>
    <item>
      <title>Hash Balancing with mod_proxy_core</title>
      <description>&lt;p&gt;mod_proxy and mod_proxy_core support 3 balancers to spread the load over multiple backends. One of them is Hash balancing which is very good for balancing the load of caching proxies like Squid.&lt;/p&gt;


	&lt;p&gt;If you compare the performance of Hash-Balancing to the classic round-robin balancing you should see a increase of the performance as the backends can use their caches a lot better. With RR each backend has to handle the full &lt;span class="caps"&gt;URL&lt;/span&gt; namespace, with Hash-Balancing only a part. This increases the cache-locality and the overall performance.&lt;/p&gt;
&lt;p&gt;I&amp;#8217;ve taken &lt;a href="http://wikipedia.org/"&gt;wikipedia&lt;/a&gt; as testbed for the hash-balancing:&lt;/p&gt;


&lt;pre&gt;
$SERVER["socket"] == ":1445" {
  proxy-core.balancer = "hash" 
  proxy-core.protocol = "http" 
  proxy-core.backends = ( "wikipedia.org" )
  proxy-core.rewrite-response = (
    "Location" =&amp;gt; ( "^http://en.wikipedia.org/(.*)" =&amp;gt; "http://127.0.0.1:1445/$1" ),
  )
  proxy-core.rewrite-request = (
    "Host" =&amp;gt; ( ".*" =&amp;gt; "en.wikipedia.org" ),
 )
}
&lt;/pre&gt;

	&lt;p&gt;The domain &lt;kbd&gt;wikipedia.org&lt;/kbd&gt; resolves to several IP-addresses:&lt;/p&gt;


&lt;pre&gt;
(trace) resolving wikipedia.org on port 80
(trace) adding 207.142.131.204:80 to the address-pool
(trace) adding 207.142.131.205:80 to the address-pool
(trace) adding 207.142.131.206:80 to the address-pool
(trace) adding 207.142.131.210:80 to the address-pool
(trace) adding 207.142.131.213:80 to the address-pool
(trace) adding 207.142.131.214:80 to the address-pool
(trace) adding 207.142.131.235:80 to the address-pool
(trace) adding 207.142.131.236:80 to the address-pool
(trace) adding 207.142.131.245:80 to the address-pool
(trace) adding 207.142.131.246:80 to the address-pool
(trace) adding 207.142.131.247:80 to the address-pool
(trace) adding 207.142.131.248:80 to the address-pool
(trace) adding 207.142.131.202:80 to the address-pool
(trace) adding 207.142.131.203:80 to the address-pool
&lt;/pre&gt;

	&lt;p&gt;When I request &lt;kbd&gt;http://127.0.0.1:1445/&lt;/kbd&gt; the load-balancer takes the &lt;span class="caps"&gt;URL&lt;/span&gt; hashes it and sends it the one of the backends.&lt;/p&gt;


&lt;pre&gt;
(trace) using hash-balancing: /wiki/Main_Page -&amp;gt; 207.142.131.204:80
(trace) using hash-balancing: /skins-1.5/monobook/main.css -&amp;gt; 207.142.131.204:80
(trace) using hash-balancing: /skins-1.5/common/commonPrint.css -&amp;gt; 207.142.131.213:80
(trace) using hash-balancing: /skins-1.5/common/wikibits.js -&amp;gt; 207.142.131.245:80
(trace) using hash-balancing: /w/index.php -&amp;gt; 207.142.131.206:80
(trace) using hash-balancing: /w/index.php -&amp;gt; 207.142.131.206:80
(trace) using hash-balancing: /w/index.php -&amp;gt; 207.142.131.206:80
(trace) using hash-balancing: /w/index.php -&amp;gt; 207.142.131.206:80
(trace) using hash-balancing: /skins-1.5/monobook/headbg.jpg -&amp;gt; 207.142.131.202:80
(trace) using hash-balancing: /skins-1.5/monobook/bullet.gif -&amp;gt; 207.142.131.245:80
(trace) using hash-balancing: /skins-1.5/common/images/poweredby_mediawiki_88x31.png -&amp;gt; 207.142.131.236:80
(trace) using hash-balancing: /images/wikimedia-button.png -&amp;gt; 207.142.131.203:80
(trace) using hash-balancing: /skins-1.5/monobook/bullet.gif -&amp;gt; 207.142.131.245:80
(trace) using hash-balancing: /skins-1.5/monobook/user.gif -&amp;gt; 207.142.131.202:80
(trace) using hash-balancing: /images/wiki-en.png -&amp;gt; 207.142.131.204:80
&lt;/pre&gt;

	&lt;p&gt;You see that the same &lt;span class="caps"&gt;URL&lt;/span&gt; results in the same address that is connected.&lt;/p&gt;


	&lt;p&gt;If one of the backends goes down, all requests that were meant for that backend are spread over the other backends. If you had 10 backends and 1 goes down, each backend has to server 1/9 URLs of the dead backend.&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;you have &lt;kbd&gt;100 URLs, 10 backends&lt;/kbd&gt;&lt;/li&gt;
		&lt;li&gt;each backend handles &lt;kbd&gt;(100/10) = 10 URLs&lt;/kbd&gt;&lt;/li&gt;
		&lt;li&gt;one backend goes down and its &lt;kbd&gt;10 URLs&lt;/kbd&gt; are spread over the other 9 backends&lt;/li&gt;
		&lt;li&gt;each backend handles now its &lt;kbd&gt;10 URLs as before + (10/9) URLs&lt;/kbd&gt; of the dead backend&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;Hash balancing is following the ideas from &lt;a href="http://icp.ircache.net/carp.txt"&gt;http://icp.ircache.net/carp.txt&lt;/a&gt;&lt;/p&gt;</description>
      <pubDate>Wed, 19 Jul 2006 13:38:52 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:c7479c7b-8743-44e7-8a31-219ec0c623dd</guid>
      <author>jan</author>
      <link>http://blog.lighttpd.net/articles/2006/07/19/hash-balancing-with-mod_proxy_core</link>
      <category>mod_proxy_core</category>
      <category>hash</category>
      <category>load</category>
      <category>balancing</category>
      <trackback:ping>http://blog.lighttpd.net/articles/trackback/1786</trackback:ping>
    </item>
    <item>
      <title>"Hash Balancing with mod_proxy_core" by Jan Kneschke</title>
      <description>The hash is built over the path and the hostname.</description>
      <pubDate>Sat, 22 Jul 2006 06:22:47 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:d3270b1c-9dd3-4db3-988e-e86b16ac9fcf</guid>
      <link>http://blog.lighttpd.net/articles/2006/07/19/hash-balancing-with-mod_proxy_core#comment-1817</link>
    </item>
    <item>
      <title>"Hash Balancing with mod_proxy_core" by Tobias Luetke</title>
      <description>With the modern crop of web applications using the host name as account key ( turtles.myshopify.com, tobi.backpackit.com etc ) will the hash based load balancing take the host name into account or is only the actual path part of the decision making? 
</description>
      <pubDate>Sat, 22 Jul 2006 01:17:13 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:01babde4-7001-444f-9058-3d82031c4671</guid>
      <link>http://blog.lighttpd.net/articles/2006/07/19/hash-balancing-with-mod_proxy_core#comment-1813</link>
    </item>
    <item>
      <title>"Hash Balancing with mod_proxy_core" by Malte Geierhos</title>
      <description>If you're on the way to let lighty access session variables in POST,GET,COOKIE values, would you please think of all the people out there waiting for access to session in CML ? 

memcached integration could be a point (push the values on demand into memcache) and make them available via CML or as lighty variable... so that we can access it and use it for session/server stickyness etc. </description>
      <pubDate>Thu, 20 Jul 2006 11:11:24 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:17a6b172-5d61-4d21-ae86-2606f9eb350c</guid>
      <link>http://blog.lighttpd.net/articles/2006/07/19/hash-balancing-with-mod_proxy_core#comment-1801</link>
    </item>
    <item>
      <title>"Hash Balancing with mod_proxy_core" by Jan Kneschke</title>
      <description>client-ip handling wouldn't work for the same reason why you don't use the client-ip as part of the session id: 
Due to proxy-farms the same client might have another IP on each request.

BUT ... if you specify the name of the session-paramter (POST, GET or COOKIE) lighty could balance on it. This is not implemented yet. A shared session-storage like memcached is prefered as it allows real load-balancing and failover.</description>
      <pubDate>Thu, 20 Jul 2006 07:30:39 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:db951710-7474-4e5b-9598-78694c41142a</guid>
      <link>http://blog.lighttpd.net/articles/2006/07/19/hash-balancing-with-mod_proxy_core#comment-1799</link>
    </item>
    <item>
      <title>"Hash Balancing with mod_proxy_core" by Jan Kneschke</title>
      <description>The HTTP/1.1 upgrade was for testing only. We were handling the HTTP version correctly as we recoded the response for the backend, but you never know. Upgrade is gone.</description>
      <pubDate>Thu, 20 Jul 2006 07:27:35 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:c1b384fd-f32d-4fff-b3bf-29f341ca9b0e</guid>
      <link>http://blog.lighttpd.net/articles/2006/07/19/hash-balancing-with-mod_proxy_core#comment-1798</link>
    </item>
    <item>
      <title>"Hash Balancing with mod_proxy_core" by qhy</title>
      <description>mod_proxy_core may upgrade backend's HTTP 1.0 response to HTTP 1.1 response because mod_proxy_core don't check backend response's HTTP version. From HTTP 1.1 RFC 2616 sec 3.1 we learn that "Due to interoperability problems with HTTP/1.0 proxies discovered since the publication of RFC 2068[33], caching
proxies MUST, gateways MAY, and tunnels MUST NOT upgrade the request to the highest version they support.
The proxy/gateway’s response to that request MUST be in the same major version as the request." I don't know whether mod_proxy_core belongs to tunnel or not.</description>
      <pubDate>Thu, 20 Jul 2006 06:51:10 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:ee03ec7a-b6c6-4a82-a185-41efb11b2fb1</guid>
      <link>http://blog.lighttpd.net/articles/2006/07/19/hash-balancing-with-mod_proxy_core#comment-1796</link>
    </item>
    <item>
      <title>"Hash Balancing with mod_proxy_core" by qhy</title>
      <description>how about implemented client-ip hash balancing, which means to use host based on client ip.

client-ip hash balancing is useful for application using local session to store user data</description>
      <pubDate>Thu, 20 Jul 2006 06:36:12 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:89ed2bdf-ceaf-4435-a1c5-90ada4b0730a</guid>
      <link>http://blog.lighttpd.net/articles/2006/07/19/hash-balancing-with-mod_proxy_core#comment-1795</link>
    </item>
    <item>
      <title>"Hash Balancing with mod_proxy_core" by Jan Kneschke</title>
      <description>It is assumed that all proxies have all the same data or at least can get all the cached data. They have to to be able to handle a failure of all but one backend.

The difference is the utilization of the FS-cache in the backends. With RR all backends get requests for all URLs, with Hash each backend only gets requests for a part of the URLs.

This a basicly like Partitioning in databases.</description>
      <pubDate>Wed, 19 Jul 2006 15:57:47 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:d6fde986-e484-4e86-bd04-fbbfab110118</guid>
      <link>http://blog.lighttpd.net/articles/2006/07/19/hash-balancing-with-mod_proxy_core#comment-1788</link>
    </item>
    <item>
      <title>"Hash Balancing with mod_proxy_core" by runa</title>
      <description>As I understand, this will make no difference if all the caching proxies have all the urls cached, or Im missing something?</description>
      <pubDate>Wed, 19 Jul 2006 15:47:28 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:519610fd-b77a-4862-8ec3-2c1e119381d4</guid>
      <link>http://blog.lighttpd.net/articles/2006/07/19/hash-balancing-with-mod_proxy_core#comment-1787</link>
    </item>
  </channel>
</rss>
