<rdf:RDF
    xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'
    xmlns:s='http://snipsnap.org/rdf/snip-schema#'
    xml:base='http://bliki.rimuhosting.com/rdf'>
    <s:Snip rdf:about='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/miscapplications/typo+cluster'
         s:cUser='david'
         s:oUser=''
         s:mUser='domingos'>
        <s:name>knowledgebase/linux/miscapplications/typo cluster</s:name>
        <s:content>1 Configure your Rails environment:&#xD;&#xA;&#xD;&#xA;This Typo installation builds on the RimuHosting Ruby on Rails stack.  Instructions (and a script) to set this up can be found at:&#xD;&#xA; &#xD;&#xA;http://bliki.rimuhosting.com/space/knowledgebase/linux/miscapplications/ruby+on+rails&#xD;&#xA;&#xD;&#xA;In addition to the standard stack, I recommend installing the mongrel_cluster and daemons gems which you can do via the following command:&#xD;&#xA;&#xD;&#xA;{code}&#xD;&#xA;[root@test ~]# gem install mongrel_cluster daemons --include-dependencies&#xD;&#xA;{code}&#xD;&#xA;&#xD;&#xA;1 Download Typo&#xD;&#xA;&#xD;&#xA;Download the latest stable version of Typo from: http://rubyforge.org/frs/?group_id=555&amp;release_id=10286&#xD;&#xA;&#xD;&#xA;{code}&#xD;&#xA;cd /var/www/&#xD;&#xA;[root@test www]# wget http:\//rubyforge.org/frs/download.php/18342/typo-4.1.tgz&#xD;&#xA;[root@test www]# tar xvf typo-4.1.tgz&#xD;&#xA;{code}&#xD;&#xA;&#xD;&#xA;1 Configure Typo database&#xD;&#xA;&#xD;&#xA;I&apos;ll only setup a production database alias because this is for production use and I don&apos;t anticipate needing either the test nor development database definitions.&#xD;&#xA;&#xD;&#xA;{code}&#xD;&#xA;[root@test www]# vi /var/www/typo-4.1/config/database.yml&#xD;&#xA;production:&#xD;&#xA;        adapter: mysql&#xD;&#xA;        database: typo&#xD;&#xA;        username: DBUSER&#xD;&#xA;        password: PASSWORD&#xD;&#xA;        host: localhost&#xD;&#xA;{code}&#xD;&#xA;  &#xD;&#xA;Take the info from the above configuration file and create a Typo database in MySQL: (Make sure to use the same credentials you supplied in the configuration file)&#xD;&#xA;&#xD;&#xA;{code}&#xD;&#xA;[root@test www]# mysql -u root&#xD;&#xA;mysql&gt; create database typo;&#xD;&#xA;mysql&gt; GRANT ALL PRIVILEGES ON typo.* to &apos;DBUSER&apos;@&apos;localhost&apos; IDENTIFIED BY &apos;PASSWORD&apos;;&#xD;&#xA;{code}&#xD;&#xA;&#xD;&#xA;After you&apos;ve created the database with the proper credentials, you&apos;ll need to import the Typo schema (and initial data) into your database.  You&apos;ll use the built-in rake task to do this:&#xD;&#xA;&#xD;&#xA;{code}&#xD;&#xA;[root@test typo-4.1]# cd /var/www/typo-4.1/&#xD;&#xA;[root@test typo-4.1]# rake migrate&#xD;&#xA;{code}&#xD;&#xA;&#xD;&#xA;1 Configuring Mongrel Cluster&#xD;&#xA;&#xD;&#xA;Having Apache run in front of Mongrel is a great way to serve your application.  You get the benefit of being able to take advantage of the various Apache modules and the convenience of Mongrel serving your Rails bits.  :)&#xD;&#xA;&#xD;&#xA;One drawback to Mongrel is that it will only service a single request at time.  This is only a problem when you&apos;re servicing high loads with many concurrent requests.  You can help to mitigate this issue by running multiple instances of Mongrel and then passing incoming connections around your cluster.  For this reason, this configuration will reflect running  cluster, but it will only specify a single Mongrel instance initially.&#xD;&#xA;&#xD;&#xA;Each Mongrel process you run will consume additional memory (usually between 15MB and 45MB) and with that in mind, you&apos;ll want to instantiate only as many Mongrel instances as you need. (more on that at the end of this article)&#xD;&#xA;&#xD;&#xA;Generating your mongrel configuration file is dead simple with the mongrel_cluster gem we installed earlier.  To generate your config, issue the following command from the root of your Typo installation:&#xD;&#xA;&#xD;&#xA;{code}&#xD;&#xA;[root@test typo-4.1]# mongrel_rails cluster::configure -e production -p 8000 -a 127.0.0.1 -N 2 -c /var/www/typo-4.1&#xD;&#xA;{code}&#xD;&#xA;&#xD;&#xA;The above will run 2 Mongrel instances (-N 2) in production mode (-e production) on ports 8000 and above (-p 8000) and will only listen on the loopback address (-a 127.0.0.1).&#xD;&#xA;&#xD;&#xA;1 Setting up an init.d script:&#xD;&#xA;&#xD;&#xA;The mongrel_cluster gem comes with an init script for you to use.  We&apos;ll create a symbolic link to that and then modify it to be executable:&#xD;&#xA;&#xD;&#xA;{code}&#xD;&#xA;[root@test typo-4.1]# ln -s /usr/lib/ruby/gems/1.8/gems/mongrel_cluster-0.2.1/resources/mongrel_cluster /etc/init.d/mongrel_cluster&#xD;&#xA;[root@test typo-4.1]# chmod +x /etc/init.d/mongrel_cluster&#xD;&#xA;{code}&#xD;&#xA;&#xD;&#xA;The init script will load mongrel cluster configs found in /etc/mongrel_cluster.  We&apos;ll create that directory and then create a symbolic link for our typo mongrel config so that it will be loaded when the init script is run:&#xD;&#xA;&#xD;&#xA;{code}&#xD;&#xA;[root@test typo-4.1]# mkdir /etc/mongrel_cluster&#xD;&#xA;[root@test typo-4.1]# ln -s /var/www/typo-4.1/config/mongrel_cluster.yml /etc/mongrel_cluster/typo.yml&#xD;&#xA;{code}&#xD;&#xA;&#xD;&#xA;1 Apache configuration&#xD;&#xA;&#xD;&#xA;What good is a mongrel instance that only listens on the local port?  Well, we&apos;ll need to tell Apache how to handle incoming transactions.  First we&apos;ll create a mod_proxy_balancer configuration (note this is only available in Apache 2.2+).&#xD;&#xA;&#xD;&#xA;{code}&#xD;&#xA;[root@test typo-4.1]# vi /etc/httpd/conf.d/proxy_balancer.conf&#xD;&#xA;&lt;Proxy balancer://mongrel_cluster&gt;&#xD;&#xA;    BalancerMember http:\//127.0.0.1:8000&#xD;&#xA;    BalancerMember http:\//127.0.0.1:8001&#xD;&#xA;&lt;/Proxy&gt;&#xD;&#xA;{code}&#xD;&#xA;&#xD;&#xA;The BalancerMember definition should match your mongrel configuration (the port bit at the end).  If you have specified multiple mongrels, you&apos;ll need to add a BalancerMember for each mongrel.  If you&apos;re running 4, starting at port 8000, you&apos;ll need a member for 8001, 8002 and 8003.&#xD;&#xA;&#xD;&#xA;1 Apache virtual host definition&#xD;&#xA;&#xD;&#xA;The following virtual host definition will pass requests through to Mongrel where appropriate.  In the case of cached pages and other static content (images/stylesheets/javascript), it will service those requests directly through Apache (which should help performance).  &#xD;&#xA;&#xD;&#xA;{code}&#xD;&#xA;&lt;VirtualHost *:80&gt;&#xD;&#xA;        ServerName YOURDOMAIN&#xD;&#xA;        &#xD;&#xA;&#9;&#9;&lt;Directory &quot;/var/www/typo-4.1/public&quot;&gt;&#xD;&#xA;&#9;&#9;&#9;Options FollowSymLinks&#xD;&#xA;&#9;&#9;&#9;AllowOverride None&#xD;&#xA;&#9;&#9;&#9;Order allow,deny&#xD;&#xA;&#9;&#9;&#9;Allow from all&#xD;&#xA;&#9;&#9;&lt;/Directory&gt;&#xD;&#xA;        &#xD;&#xA;        RewriteEngine On&#xD;&#xA;        &#xD;&#xA;        # Rewrite index to check for static&#xD;&#xA;        RewriteRule ^/(stylesheets|images|javascripts|favicon.ico) /$1 [QSA]&#xD;&#xA;        RewriteRule ^/$ /index.html [QSA]&#xD;&#xA;        &#xD;&#xA;        # Rewrite to check for Rails cached page&#xD;&#xA;        RewriteRule ^([^.]+)$ $1.html [QSA]&#xD;&#xA;        &#xD;&#xA;        # Redirect all non-static requests to cluster&#xD;&#xA;        RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f&#xD;&#xA;        RewriteRule ^/(.*)$ balancer://mongrel_cluster%{REQUEST_URI} [P,QSA,L]&#xD;&#xA;        &#xD;&#xA;        # Logging&#xD;&#xA;        ErrorLog logs/yourdomain-error_log&#xD;&#xA;        CustomLog logs/yourdomain-access_log common&#xD;&#xA;&lt;/VirtualHost&gt;&#xD;&#xA;{code}&#xD;&#xA;&#xD;&#xA;1 Benchmarking&#xD;&#xA;&#xD;&#xA;Typo implementing some caching which keeps your server from regenerating content you serve over and over.  The first number below shows the speed of the above setup running on our MiroVPS2 (160MB) VPS:&#xD;&#xA;&#xD;&#xA;{code}&#xD;&#xA;Cache Enabled:&#xD;&#xA;[root@none ~]# httperf --server YOURDOMAIN --port 80 --uri / --num-conns 2000&#xD;&#xA;Reply rate [replies/s]: min 44.2 avg 48.4 max 50.6 stddev 2.4 (8 samples)&#xD;&#xA;&#xD;&#xA;Cache Disabled:&#xD;&#xA;[root@none ~]# httperf --server YOURDOMAIN --port 80 --uri / --num-conns 2000&#xD;&#xA;Reply rate [replies/s]: min 1.4 avg 1.8 max 2.0 stddev 0.1 (228 samples)&#xD;&#xA;{code}&#xD;&#xA;&#xD;&#xA;The above demonstrates the power of caching with this setup!  If 4x requests per second isn&apos;t fast enough for you, you can simply add more mongrel instances to your custer as described above and you should be able to handle even more.</s:content>
        <s:mTime>2007-08-28 20:37:58.0</s:mTime>
        <s:cTime>2007-05-04 06:02:14.0</s:cTime>
        <s:comments
             rdf:type='http://www.w3.org/1999/02/22-rdf-syntax-ns#Bag'/>
        <s:snipLinks>
            <rdf:Bag>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/miscapplications/configuring a mongrel cluser'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/miscapplications/ruby on rails'/>
                <rdf:li rdf:resource='#snipsnap-search'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux'/>
                <rdf:li rdf:resource='#knowledgebase'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/miscapplications'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/miscapplications/mysql notes'/>
                <rdf:li rdf:resource='#paolo'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/Setup eRuby'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/mail/postfix notes'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/networking/monitoring bandwidth usage with vnstat'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/webserver/apache/webdav'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#snipsnap-index/Access Control Lists'/>
            </rdf:Bag>
        </s:snipLinks>
        <s:attachments
             rdf:type='http://www.w3.org/1999/02/22-rdf-syntax-ns#Bag'/>
    </s:Snip>
</rdf:RDF>
