<?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>MDLog:/sysadmin &#187; Scaling</title> <atom:link href="http://www.ducea.com/category/scaling/feed/" rel="self" type="application/rss+xml" /><link>http://www.ducea.com</link> <description>The Journal Of A Linux Sysadmin</description> <lastBuildDate>Tue, 13 Jul 2010 02:03:18 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.0</generator> <item><title>Using Varnish in front of your Amazon S3 static content</title><link>http://www.ducea.com/2009/08/04/using-varnish-in-front-of-your-amazon-s3-static-content/</link> <comments>http://www.ducea.com/2009/08/04/using-varnish-in-front-of-your-amazon-s3-static-content/#comments</comments> <pubDate>Tue, 04 Aug 2009 14:45:21 +0000</pubDate> <dc:creator>- Marius -</dc:creator> <category><![CDATA[Linux]]></category> <category><![CDATA[Scaling]]></category> <category><![CDATA[caching]]></category> <category><![CDATA[proxy]]></category> <category><![CDATA[varnish]]></category><guid
isPermaLink="false">http://www.ducea.com/?p=959</guid> <description><![CDATA[Many startups these days are using Amazon S3 to serve directly their static assets. S3 is being used as a simple CDN instead of more professional (and expensive) solutions (including Amazon&#8217;s own CloudFront) because it is very simple and cheap to use. Still if you have a high traffic site, this will no longer be [...]]]></description> <content:encoded><![CDATA[<p>Many startups these days are using <a
href="http://aws.amazon.com/s3" target="_blank"><strong>Amazon S3</strong></a> to serve directly their <strong>static assets</strong>. S3 is being used as a <em>simple CDN</em> instead of more professional (and expensive) solutions (including Amazon&#8217;s own CloudFront) because it is very simple and cheap to use. Still if you have a high traffic site, this will no longer be so cheap since you will be paying for all those requests and the bandwidth. In such cases if you still want to use <strong>S3 for the storage</strong> advantage (like storing millions of files and see it as an unlimited storage space) but not have your bill go up like crazy, you can use a <strong>reverse proxy</strong> or <strong>web accelerator</strong> to cache your assets locally and reduce the number of direct hits on S3. We could use Squid or Varnish for this, and in this article I will show <em>how we can configure <strong>Varnish</strong> for this</em>. We are using varnish with S3 on various projects and it works very well, simplifying the setup and <em>saving a lot of money in the Amazon S3 bill</em>.</p><p><em><a
href="http://varnish.projects.linpro.no/" target="_blank"><strong>Varnish</strong></a> is a state-of-the-art, high-performance HTTP accelerator. It uses the advanced features in Linux 2.6, FreeBSD 6/7 and Solaris 10 to achieve its high performance.</em> I will not go over the installation of varnish here, but I would highly recommend to use the latest version available at this time <strong>2.0.4</strong> as older versions have various issues.</p><p>We could try to use something simple like this in a <a
href="http://varnish.projects.linpro.no/wiki/VCL" target="_blank"><strong>varnish vcl</strong></a>:</p><pre><code>backend s3 {
   set backend.host = "my_bucket.s3.amazonaws.com";
   set backend.port = "80";
}

sub vcl_recv {
   if (req.url ~ "\.(css|gif|ico|jpg|jpeg|js|png|swf|txt)$") {
     set req.backend = s3;
     lookup;
   }
}</code></pre><p><span
id="more-959"></span>but unfortunately this will not work. The Amazon S3 servers will look into<em> the <strong>hostname</strong> passed by the request</em> and this will most likely be different than the amazon bucket (something like static.mydomain.com) and hence will return 403 on any such request.</p><p>There are <em>several solutions</em> to make this work correctly, and the first one I will present is going to <strong>insert the bucket name</strong> in the actual url passed to the S3 backed. This looks like:</p><pre><code>backend s3 {
   set backend.host = "s3.amazonaws.com";
   set backend.port = "80";
}

sub vcl_recv {
   if (req.url ~ "\.(css|gif|ico|jpg|jpeg|js|png|swf|txt)$") {
     <strong>set req.url = regsub(req.url, "^", "/my_bucket");</strong>
     set req.http.host = "localhost";
     set req.backend = s3;
     lookup;
   }
}</code></pre><p>this will work fine, inserting the bucket name in the actual url passed to the backend. Still I don&#8217;t like this solution very much as it changes the consistency between the urls (direct one and the forwarded one) so here is a much better solution:</p><pre><code>backend s3 {
   set backend.host = "s3.amazonaws.com";
   set backend.port = "80";
}

sub vcl_recv {
   if (req.url ~ "\.(css|gif|ico|jpg|jpeg|js|png|swf|txt)$") {
     <strong>set req.http.host = "my_bucket.s3.amazonaws.com";</strong>
     set req.backend = s3;
     lookup;
   }
}</code></pre><p>As we can see, we are <strong>setting the http host</strong> the the one Amazon S3 servers would expect for <strong>our bucket</strong>. So we can keep the same url and don&#8217;t mess with the actual link we are passing.</p><p>A complete varnish vcl configuration to use with the Amazon S3 backend might look like this:</p><pre><code>backend s3 {
.host = "s3.amazonaws.com";
.port = "80";
}

sub vcl_recv {
    if (req.url ~ "\.(css|gif|ico|jpg|jpeg|js|png|swf|txt)$") {
        unset req.http.cookie;
        unset req.http.cache-control;
        unset req.http.pragma;
        unset req.http.expires;
        unset req.http.etag;
        unset req.http.X-Forwarded-For;

        set req.backend = s3;
        set req.http.host = "my_bucket.s3.amazonaws.com";

        lookup;
    }
}

sub vcl_fetch {
    unset obj.http.X-Amz-Id-2;
    unset obj.http.X-Amz-Meta-Group;
    unset obj.http.X-Amz-Meta-Owner;
    unset obj.http.X-Amz-Meta-Permissions;
    unset obj.http.X-Amz-Request-Id;

    set obj.ttl = 1w;
    set obj.grace = 30s;
} </code></pre><p>If you found this post interesting, stay tuned for future posts on varnish and how to use it in more complex setups <img
src='http://www.ducea.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> .</p>]]></content:encoded> <wfw:commentRss>http://www.ducea.com/2009/08/04/using-varnish-in-front-of-your-amazon-s3-static-content/feed/</wfw:commentRss> <slash:comments>5</slash:comments> </item> <item><title>PHP Sessions in Memcached</title><link>http://www.ducea.com/2009/06/02/php-sessions-in-memcached/</link> <comments>http://www.ducea.com/2009/06/02/php-sessions-in-memcached/#comments</comments> <pubDate>Tue, 02 Jun 2009 10:15:34 +0000</pubDate> <dc:creator>- Marius -</dc:creator> <category><![CDATA[Centos]]></category> <category><![CDATA[Debian]]></category> <category><![CDATA[Fedora]]></category> <category><![CDATA[Linux]]></category> <category><![CDATA[RHEL]]></category> <category><![CDATA[Scaling]]></category> <category><![CDATA[Ubuntu]]></category> <category><![CDATA[memcached]]></category> <category><![CDATA[pecl]]></category> <category><![CDATA[php5]]></category> <category><![CDATA[php_extensions]]></category> <category><![CDATA[php_modules]]></category><guid
isPermaLink="false">http://www.ducea.com/?p=903</guid> <description><![CDATA[The moment a PHP application grows to run on more servers, normally people will see problems caused by PHP sessions. If the application is not persistent you are lucky and don&#8217;t care about this, but if not you will quickly see this regardless of how good the load balancer you use is handling stickiness (sending [...]]]></description> <content:encoded><![CDATA[<p>The moment a <em>PHP application grows to run on more servers</em>, normally people will see problems caused by <strong>PHP sessions</strong>. If the application is not persistent you are lucky and don&#8217;t care about this, but if not you will quickly see this regardless of how good the load balancer you use is handling stickiness (sending the users to the same real server), this will slowly become a major issue. There are various solutions that can be used to store PHP sessions in a <strong>shared location</strong>, but I want to present today one solution that is very simple to implement, yet very efficient and on the long term better suited than using a database backend for this: using <a
href="http://danga.com/memcached" target="_blank"><strong>memcache</strong></a> to store the sessions.</p><p>The <a
href="http://pecl.php.net/package/memcache" target="_blank">pecl memcache php extension</a> has supported for a long time the memcache session.save_handler, but with the release <strong>3.0.x</strong> (still in beta at this time) this brings in a set of interesting <a
href="http://pecl.php.net/package/memcache/3.0.0" target="_blank">features</a> for us:<br
/> - UDP support<br
/> - Binary protocol support<br
/> - Non-blocking IO using select()<br
/> - Key and session redundancy (values are written to N mirrors)<br
/> - Improved error reporting and failover handling</p><p><span
id="more-903"></span>Installing the php memcache module is very simple and can be done either by using distribution repositories (the version we want to use 3.0.x will probably not be available) or by using pecl or manual compilation:</p><p>Using pecl:<br
/> <code>pecl install memcache-3.0.4</code></p><p>or manually:<br
/> <code>wget http://pecl.php.net/get/memcache-3.0.4.tgz<br
/> tar xvfz memcache-3.0.4.tgz<br
/> cd memcache-3.0.4<br
/> phpize<br
/> ./configure<br
/> make<br
/> make install</code></p><p>Finally, we need to <em>activate the module in php.ini</em>. I normally prefer to create a new file for this <strong>memcache.ini</strong> inside the include directory of the php build (for ex. in debian this is under <strong>/etc/php5/conf.d/memcache.ini</strong>) like this:<br
/> <code>extension=memcache.so<br
/> memcache.allow_failover = 1<br
/> memcache.redundancy = 1<br
/> memcache.session_redundancy = 2</code></p><p>To use memcached to store the <strong>php sessions</strong> we will have to edit php.ini and replace the default file handler settings with something like:<br
/> <code>; Use memcache as a session handler<br
/> session.save_handler = memcache<br
/> ; Use a comma separated list of server urls to use for storage:<br
/> session.save_path="udp://&lt;memcache_server&gt;:11211?persistent=1&amp;weight=1&amp;timeout=1&amp;retry_interval=15"</code></p><p>or if we don&#8217;t want to use this serverwide, we can just define it inside a php block like this:</p><pre><code>$session_save_path = "tcp://&lt;memcache_server1&gt;:11211?persistent=1&amp;weight=1&amp;timeout=1&amp;retry_interval=15, tcp://&lt;memcache_server2&gt;:11211";
ini_set('session.save_handler', 'memcache');
ini_set('session.save_path', $session_save_path);</code></pre><p>Note: as you can see I used in the above example tcp and udp also. Please be sure that your memcached server has udp support enabled if you want to use that. Also ensure that the web server can connect to the memcache server/port (use proper firewall rules to allow this) in order for this to work.</p><p>After restarting apache, it will start using memcache to store the php sessions. If redundancy is needed (why not?) we will probably want to use the internal php memcache support to save the sessions to more servers, or if you prefer you can use an external solution to replicate the memcached server data &#8211; <a
href="http://repcached.lab.klab.org/" target="_blank">repcached</a>.</p>]]></content:encoded> <wfw:commentRss>http://www.ducea.com/2009/06/02/php-sessions-in-memcached/feed/</wfw:commentRss> <slash:comments>3</slash:comments> </item> <item><title>InnoDB Plugin Version 1.0.3 released: enhances concurrency and scalability on multi-core systems</title><link>http://www.ducea.com/2009/03/13/innodb-plugin-version-103-released-enhances-concurrency-and-scalability-on-multi-core-systems/</link> <comments>http://www.ducea.com/2009/03/13/innodb-plugin-version-103-released-enhances-concurrency-and-scalability-on-multi-core-systems/#comments</comments> <pubDate>Fri, 13 Mar 2009 15:35:25 +0000</pubDate> <dc:creator>- Marius -</dc:creator> <category><![CDATA[Linux]]></category> <category><![CDATA[Scaling]]></category> <category><![CDATA[innodb]]></category> <category><![CDATA[mysql]]></category> <category><![CDATA[mysql-5.1]]></category><guid
isPermaLink="false">http://www.ducea.com/?p=767</guid> <description><![CDATA[The InnoDB Team just released the InnoDB Plugin version 1.0.3. From their announcement here are the main points of this release: Enhanced scalability: the Google SMP enhancement for synchronization More efficient memory allocation: ability to use platform allocator tuned for multi-core systems Improved out-of-the-box scalability: unlimited concurrent thread execution by default Dynamic tuning: at run-time, [...]]]></description> <content:encoded><![CDATA[<p>The InnoDB Team just released the <strong>InnoDB Plugin version 1.0.3</strong>. From their <a
href="http://www.innodb.com/wp/2009/03/11/innodb-plugin-version-103-for-mysql-5130-32-33-released/" target="_blank">announcement</a> here are the main points of this release:</p><ul><li>Enhanced scalability: the <strong>Google SMP enhancement</strong> for synchronization</li><li>More efficient memory allocation: ability to use platform allocator tuned for multi-core systems</li><li>Improved out-of-the-box scalability: unlimited concurrent thread execution by default</li><li>Dynamic tuning: at run-time, enable or disable insert buffering and adaptive hash indexing</li></ul><p>wow&#8230; now this is indeed some great news for innodb users&#8230; I am writting this, and still I can&#8217;t believe that they’ve included the <a
href="http://code.google.com/p/google-mysql-tools/wiki/SmpPerformance" target="_blank">Google SMP patch</a> in their official release. I can only assume that alternative projects as <a
href="http://www.percona.com/docs/wiki/percona-xtradb:start" target="_blank"><strong>XtraDB</strong></a>, <a
href="https://launchpad.net/drizzle" target="_blank">Drizzle</a>, <a
href="http://www.percona.com/" target="_blank">Percona</a> patches, <a
href="http://code.google.com/p/google-mysql-tools/wiki/Mysql5Patches" target="_blank">Google patches</a>, etc. made Oracle to look back and try to do something with innodb besides the regular bug fixes. Even if we already use several of the great <em>&#8216;unofficial alternatives&#8217;</em> this is good news for everyone.<br
/> <strong>Way to go Oracle!</strong> and looking forward for future performance improvements in the official innodb plugin; including existing patches that are out there already for sometime is a good start, but internal improvements from the innodb team would be also great <img
src='http://www.ducea.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> .</p><p>Here are some performance results based on their own tests:<br
/> <a
href="http://www.innodb.com/innodb_plugin/plugin-performance/" target="_blank">http://www.innodb.com/innodb_plugin/plugin-performance/</a></p>]]></content:encoded> <wfw:commentRss>http://www.ducea.com/2009/03/13/innodb-plugin-version-103-released-enhances-concurrency-and-scalability-on-multi-core-systems/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Amazon announces its own content delivery network: CloudFront</title><link>http://www.ducea.com/2008/11/18/amazon-announces-its-own-content-delivery-network-cloudfront/</link> <comments>http://www.ducea.com/2008/11/18/amazon-announces-its-own-content-delivery-network-cloudfront/#comments</comments> <pubDate>Tue, 18 Nov 2008 22:30:20 +0000</pubDate> <dc:creator>- Marius -</dc:creator> <category><![CDATA[Cloud Computing]]></category> <category><![CDATA[News from Outside]]></category> <category><![CDATA[Scaling]]></category> <category><![CDATA[Security]]></category> <category><![CDATA[amazon]]></category> <category><![CDATA[aws]]></category> <category><![CDATA[cdn]]></category> <category><![CDATA[CloudFront]]></category> <category><![CDATA[s3]]></category><guid
isPermaLink="false">http://www.ducea.com/?p=425</guid> <description><![CDATA[Today Amazon announced the public beta of Amazon CloudFront, their AWS service for content delivery. This is the service that many users of Amazon S3 (Simple Storage Service) have been waiting for a long time. Even if S3 was never a &#8216;real&#8217; CDN (content delivery network) it was used by many sites to serve static [...]]]></description> <content:encoded><![CDATA[<p>Today Amazon <a
href="http://aws.amazon.com/about-aws/whats-new/2008/11/18/whats-new-cloudfront/" target="_blank">announced</a> the public beta of <strong>Amazon CloudFront</strong>, their AWS service for content delivery. This is the service that many users of <strong>Amazon S3</strong> (<em>Simple Storage Service</em>) have been waiting for a long time. Even if S3 was never a &#8216;real&#8217; CDN (content delivery network) it was used by many sites to serve static content. The main limitation of this approach was that it had no geographical awareness as content delivery networks usually have; the fact that S3 is highly scalable and well priced made this solution acceptable on S3.</p><p><strong>CloudFront </strong>is the answer to all users’ requests about <strong>using S3 as a CDN</strong>, delivering the content using a global network of <strong>14 edge locations</strong>. <em>CloudFront uses S3 to store the original file</em>, and caches copies of the content close to end users locations, lowering latency when they download the objects.</p><p><span
id="more-425"></span>Amazon CloudFront uses the following edge locations:<br
/> <span
style="text-decoration: underline;"><em>United States</em></span><br
/> * Ashburn, VA<br
/> * Dallas/Fort Worth, TX<br
/> * Los Angeles, CA<br
/> * Miami, FL<br
/> * Newark, NJ<br
/> * Palo Alto, CA<br
/> * Seattle, WA<br
/> * St. Louis, MO<br
/> <span
style="text-decoration: underline;"><em>Europe</em></span><br
/> * Amsterdam<br
/> * Dublin<br
/> * Frankfurt<br
/> * London<br
/> <span
style="text-decoration: underline;"><em>Asia</em></span><br
/> * Hong Kong<br
/> * Tokyo</p><p><strong>CloudFront advantages:</strong></p><ul><li><strong>simple </strong>to implement; uses S3 as a &#8216;backend&#8217;;</li><li><strong>cost effective</strong> &#8211; pay only for what you use; <a
href="http://aws.amazon.com/cloudfront/" target="_blank">priced</a> very well just as S3 with prices starting at $0.170 per GB for content delivered in the US and Europe, and $0.210 per GB for content delivered in Asia;</li><li><strong>reliable </strong>- even though this is launched as <strong>beta </strong>and there is <strong>no SLA</strong>, we can expect to have a very reliable service from Amazon built on the experiences of s3 and ec2.</li></ul><p><strong>CloudFront disadvantages:</strong></p><ul><li>this is a <strong>http only</strong> service; if you will need https for ex. you will not be able to do that.</li><li><strong>no control </strong>over caching; CloudFront will cache the file from your S3 bucket and serve it based on the closest dns location; this cache can expire in case of infrequent used files.</li><li><strong>no stats</strong> (besides the aws bill of course <img
src='http://www.ducea.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> ).</li><li>this is not trying to compete with the big CDN solutions out there, as it will be hard to match their features, but to provide a simple and cost effective solution that everybody can use.</li></ul><p>In conclusion, this is great news from Amazon, and I am sure that even as I am writing this, many users that are serving their content from S3 have just finished switching over to CloudFront. For more details about <strong>CloudFront </strong>check out the <a
href="http://aws.amazon.com/cloudfront/ " target="_blank">AWS CloudFront page</a>.</p>]]></content:encoded> <wfw:commentRss>http://www.ducea.com/2008/11/18/amazon-announces-its-own-content-delivery-network-cloudfront/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>LVS persistence and AOL proxies</title><link>http://www.ducea.com/2008/06/23/lvs-persistence-and-aol-proxies/</link> <comments>http://www.ducea.com/2008/06/23/lvs-persistence-and-aol-proxies/#comments</comments> <pubDate>Mon, 23 Jun 2008 11:00:58 +0000</pubDate> <dc:creator>- Marius -</dc:creator> <category><![CDATA[Linux]]></category> <category><![CDATA[Scaling]]></category> <category><![CDATA[Tips & Tricks]]></category> <category><![CDATA[aol]]></category> <category><![CDATA[ipvs]]></category> <category><![CDATA[ldirectord]]></category> <category><![CDATA[load_balancing]]></category> <category><![CDATA[lvs]]></category><guid
isPermaLink="false">http://www.ducea.com/?p=248</guid> <description><![CDATA[LVS has a simple IP based persistence built-in that can be used to keep the users on the same real servers for a configurable amount of time. This has been explained in my previous post, and it works fine, but in real life users will come from various dynamic connections or even using some ISP [...]]]></description> <content:encoded><![CDATA[<p><a
href="http://www.linuxvirtualserver.org/" target="_blank"><strong>LVS</strong></a> has a simple <em>IP based persistence</em> built-in that can be used to keep the users on the same real servers for a configurable amount of time. This has been explained in <a
href="http://www.ducea.com/2008/06/16/lvs-persistence/">my previous post</a>, and it works fine, but in real life users will come from various dynamic connections or even using some ISP proxy servers to browse the internet. For such situations LVS supports the <em>configurable netmask for persistence</em>, allowing us to increase the network mask used in the persistence match (normally we will use /24 for this) sending a bigger range of ips to the same server. This approach works fine for most cases where users will have the same class C ips allocated or the isp proxies will be on the same network range. Unfortunately <strong>this doesn&#8217;t work for AOL,</strong> because the AOL clients will always be proxied  by the huge AOL proxy cluster that will send each request from a different real ip. These IPs are not even from the same range and tend to be completely different. <em>This post will show how we can keep these AOL users on the same real server in a LVS-DR setup.</em></p><p>Normally if this would have been a small ISP I am sure people would have ignored their users and the users would have complained back to the ISP that they can&#8217;t reach some big sites, and in the end the ISP would have found a friendlier solution for this. Since this is AOL and they have a huge base of clients, we can&#8217;t really ignore them and we have to find a solution ourselves.</p><p><span
id="more-248"></span>The best solution on the long term is to rewrite your application so it will no longer be persistent dependent (require that each user request to be processed by the same real server). Unfortunately this is not always possible, or it can take a long time to complete, meaning you need a work-around in the meantime.</p><p>As shown in my <a
href="http://www.ducea.com/2008/06/16/lvs-persistence/">previous post</a> we can <strong>increase the network mask</strong> in order to try to keep a bigger range of IPs on the same real server assuming that the remote user IPs will be at least on the same range. This might help for smaller proxy networks, but for AOL this will not be very useful as they will come from various completely different ips. Without being able to make decisions about the <strong>content of the packet </strong>LVS will not be able to solve this issue. The solution presented here is a <strong>work-around </strong>and to my knowledge it is the only possible solution <em>when using LVS</em>. <em>We will mark all AOL proxy IPs traffic with <strong>iptables </strong>and then create for them a separate VIP using <strong>FWMARK</strong></em><strong>. </strong>Obviously this will break any balancing and will send all the AOL users to a single server.<br
/> <em>Note: If your AOL traffic is too big to handle for one server, then this solution will not work for you and you will need a higher level proxy (L7) to make the persistence work for AOL users. </em></p><p>AOL publishes a list of their proxies ips: <a
href="http://webmaster.info.aol.com/proxyinfo.html" target="_blank">http://webmaster.info.aol.com/proxyinfo.html</a><br
/> Here is a sample bash script that will mark all the packets coming from AOL proxies and mark them to have them handled by one real server (I just aggregated a few ranges to keep the list shorter <img
src='http://www.ducea.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> ):</p><pre><code>#!/bin/bash

iptables -t mangle -F

AOLPROXYS="64.12.0.0/16 149.174.160.0/20 \
152.163.0.0/16 195.93.0.0/18 195.93.64.0/18 198.81.0.0/16 \
202.67.64.128/25 205.188.0.0/16 207.200.112.0/21"

for aolproxys in $AOLPROXYS
do
iptables -t mangle -A PREROUTING -p tcp -s $aolproxys -d VIP/32 \
--dport 80 -j MARK --set-mark 1
done</code></pre><p>And the ipvs FWMARK1 service definition:<br
/> <code>ipvsadm -A -f 1 -s wrr -p 3600<br
/> ipvsadm -a -f 1 -r RS1 -g</code></p><p>resulting in all AOL traffic going to RealServer1. If you are using <strong>ldirectord </strong>you will probably want to setup also another server <em>as a backup</em> in case RS1 goes down. You still have to mark the traffic using iptables as shown above; the ldirectord.cf service definition should look like this:<br
/> <code>virtual=1<br
/> real=RS1:80 gate<br
/> fallback=RS2:80 gate<br
/> persistent=3600<br
/> protocol=fwm<br
/> ...</code></p><p>I am aware that this is not the nicest solution, but it was the only work-around I found if you have to use LVS and deal with AOL users on a persistent web application. If you find this useful don&#8217;t forget to check on the <a
href="http://webmaster.info.aol.com/proxyinfo.html" target="_blank">AOL proxy IP list</a> and update your configs if needed in the future.</p><p>For more details you can check the <a
href="http://www.austintek.com/LVS/LVS-HOWTO/HOWTO/LVS-HOWTO.persistent_connection.html" target="_blank">LVS FAQ</a>.</p>]]></content:encoded> <wfw:commentRss>http://www.ducea.com/2008/06/23/lvs-persistence-and-aol-proxies/feed/</wfw:commentRss> <slash:comments>6</slash:comments> </item> <item><title>LVS persistence</title><link>http://www.ducea.com/2008/06/16/lvs-persistence/</link> <comments>http://www.ducea.com/2008/06/16/lvs-persistence/#comments</comments> <pubDate>Mon, 16 Jun 2008 16:30:45 +0000</pubDate> <dc:creator>- Marius -</dc:creator> <category><![CDATA[Linux]]></category> <category><![CDATA[Scaling]]></category> <category><![CDATA[ipvs]]></category> <category><![CDATA[ldirectord]]></category> <category><![CDATA[load_balancing]]></category> <category><![CDATA[lvs]]></category><guid
isPermaLink="false">http://www.ducea.com/?p=247</guid> <description><![CDATA[LVS has a built-in simple IP based persistence mechanism that can be used to keep users on the same real servers for a configurable amount of time. If your web application requires that each user request to be processed by the same real server then you will probably want to enable this mechanism and ensure [...]]]></description> <content:encoded><![CDATA[<p><strong><a
href="http://www.linuxvirtualserver.org/" target="_blank">LVS</a></strong> has a built-in simple <strong>IP based persistence</strong> mechanism that can be used to keep users on the same real servers for a configurable amount of time. If your web application requires that each user request to be processed by the same real server then you will probably want to enable this mechanism and ensure that requests coming from the same IP will be directed to the same real server. <em>This article will show how you can achieve this by using regular ipvsadm commands but also by using ldirectord configurations.</em></p><p><strong>IPVS </strong>is an <strong>advanced IP based load balancing </strong>application implemented inside the linux kernel. Working at IP level LVS <em>can&#8217;t make a decisions based on the content of the packet</em>. Still, it can perform a <strong>basic IP affinity</strong>, by keeping all connections from the same source IP directed to the same real server for a configurable amount of time. This is achieved with the <strong>-p</strong> ipvsadm command parameter and takes as a parameter the time in seconds to keep the connections in the persistence table. <span
id="more-247"></span>From the ipvsadm manual page:</p><ul><li><strong> -p, &#8211;persistent [timeout]</strong> = Specify that a virtual service is persistent. If this option is specified, multiple requests from a client are redirected to  the same real server selected for the first request.  Optionally, the timeout of persistent sessions may be specified given in seconds, otherwise the default of 300 seconds will be used. This option may be used in conjunction  with  protocols such as SSL or <acronym
class="uttAcronym" title="File Transfer Protocol">FTP</acronym> where it is important that clients consistently connect with the same real server.</li></ul><p>Here is a simple ipvsadm example in a setup with one web server load balanced on 2 real servers using LVS-DR:<br
/> <code>ipvsadm -A -t VIP:80 -p 3600 -s -wrr<br
/> ipvsadm -a -t VIP:80 -R RS1 -g -w 1<br
/> ipvsadm -a -t VIP:80 -R RS2 -g -w 1</code><br
/> by using <strong>-p 3600</strong> we request to keep the users coming from the same ip on the same real server as their first connection was handled, for a period of <em>60 minutes</em>. After this timeout expires any new connection from the same user ip will be routed based on the scheduling policy (Weighted Round-Robin in this case) and can be handled by any of the active servers.</p><p>The output of the ipvsadm command will show that the service is persistent:<br
/> <code>ipvsadm -L -n<br
/> ...<br
/> TCP  VIP:80 wrr persistent 3600<br
/> -&gt; RS2:80              Route   1      0          0<br
/> -&gt; RS1:80              Route   1      0          0</code></p><p>I am assuming that not many people are using plain ipvsadm commands and will probably use a frontend like <strong>ldirector </strong>that will handle health checks, automatic reconfiguration and many other features. The same effect is achieved by using the ldirectord persistent config keyword. The same sample in <strong>ldirectord.cf</strong> terms will look like:<br
/> <code>virtual=VIP:80<br
/> real=RS1:80 gate 1<br
/> real=RS2:80 gate 1<br
/> persistent=3600<br
/> ...</code></p><p>We can increase the <strong>network range</strong> used in the persistent match, using <strong>-M netmask</strong>. From the manual page:</p><ul><li><strong> -M, &#8211;netmask netmask</strong> = Specify the granularity with which clients are grouped for persistent  virtual  services.   The  source  address  of  the request  is  masked  with  this  netmask  to  direct  all  clients from a network to the same real server. The default is 255.255.255.255, that is, the persistence granularity is per client host. Less specific netmasks may be used  to  resolve problems with non-persistent cache clusters on the client side.</li></ul><p>In our sample setup this will look like:<br
/> <code>ipvsadm -A -t VIP:80 -p 3600 -s -wrr -M 255.255.255.0<br
/> ipvsadm -a -t VIP:80 -R RS1 -g -w 1<br
/> ipvsadm -a -t VIP:80 -R RS2 -g -w 1</code></p><p>While for ldirectord this will require the usage of the netmask keyword:<br
/> <code>virtual=VIP:80<br
/> real=RS1:80 gate 1<br
/> real=RS2:80 gate 1<br
/> netmask=255.255.255.0<br
/> persistent=3600<br
/> ...</code></p><p><em>Note</em>: obviously persistence will break the scheduling policy resulting in no longer having <strong>exact balancing</strong> on the real servers. The bigger the timeout and/or network masks for the LVS persistence, the bigger the effect.</p><p>For more details you check the <a
href="http://www.austintek.com/LVS/LVS-HOWTO/HOWTO/LVS-HOWTO.persistent_connection.html" target="_blank">LVS FAQ</a>.</p>]]></content:encoded> <wfw:commentRss>http://www.ducea.com/2008/06/16/lvs-persistence/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> </channel> </rss>
<!-- Served from: www.ducea.com @ 2010-07-31 16:53:22 by W3 Total Cache -->