Load balancing

From Resin 3.0

(Difference between revisions)
Jump to: navigation, search
(renamed tag to directive)
Line 1: Line 1:
 
[[Category:Configuration]] [[Category:Cluster]]
 
[[Category:Configuration]] [[Category:Cluster]]
  
Resin documentation is at http://www.caucho.com/resin-3.0/config/balance.xtp
+
Resin documentation is at http://www.caucho.com/resin/doc/balance.xtp
  
 
Load balancing spreads the load among multiple backend Resin servers in a [[cluster|Cluster]].  A frontend Resin server proxies requests to the backend servers and sends the results to the clients.
 
Load balancing spreads the load among multiple backend Resin servers in a [[cluster|Cluster]].  A frontend Resin server proxies requests to the backend servers and sends the results to the clients.
Line 27: Line 27:
 
# A LoadBalanceServlet to dispatch requests to the backend
 
# A LoadBalanceServlet to dispatch requests to the backend
  
==== frontend.conf ====
+
==== resin.xml ====
 
  <resin xmlns="http://caucho.com/ns/resin"
 
  <resin xmlns="http://caucho.com/ns/resin"
 
         xmlns:resin="http://caucho.com/ns/resin/core">
 
         xmlns:resin="http://caucho.com/ns/resin/core">
   <server>
+
   <cluster id="load-balance">
    <http host="*" port="80"/>
+
      <server-default>
 +
        <http host="*" port="80"/>
 +
      </server-default>
 
   
 
   
    <cluster-definition id="backend">
+
      <server id="web-a" address="192.168.0.10" port="6800"/>
      <client-live-time>15s</client-live-time>
+
 
   
 
   
       <srun id="a" host="192.168.0.20" port="6802"/>
+
       <host id="">
      <srun id="b" host="192.168.0.21" port="6802"/>
+
          <web-app id="">
    </cluster-definition>
+
              <rewrite-dispatch>
 +
                  <load-balance regexp="" cluster="app-tier"/>
 +
              </rewrite-dispatch>
 +
          </web-app>
 +
        </host>
 +
    </cluster>
 
   
 
   
     <cache memory-size="32M"/>
+
     <cluster id="app-tier">
 +
          <root-directory>/var/www/</root-directory>
 
   
 
   
    <host id="">
+
          <server id="app-a" address="192.168.0.20" port="6800"/>
      <web-app id="">
+
          <server id="app-b" address="192.168.0.21" port="6800"/>
        <servlet servlet-name="balance"
+
          <server id="app-c" address="192.168.0.22" port="6800"/>
                  servlet-class="com.caucho.servlets.LoadBalanceServlet">
+
          <init>
+
            <cluster>backend</cluster>
+
          </init>
+
        </servlet>
+
 
   
 
   
        <servlet-mapping url-pattern="/*" servlet-name="balance"/>
+
          <host id="">
      </web-app>
+
              <web-app-deploy path="webapps"/>
    </host>
+
          </host>  
  </server>
+
        </cluster>
</resin>
+
  </resin>
 
+
= Sharing Cluster configuration: cluster.xml and <[[resin:import]]> =
+
 
+
Many sites will create a separate cluster.xml using resin's resin:import directive to share information between the frontend and backend:
+
 
+
==== cluster.xml ====
+
<cluster>
+
  <client-live-time>30s</client-live-time>
+
+
  <srun id="a" host="192.168.0.20" port="6802"/>
+
  <srun id="b" host="192.168.0.21" port="6802"/>
+
</cluster>
+
 
+
In the frontend.conf, you'll replace the <[[cluster-definition]]> content with a <[[resin:import]]>
+
 
+
==== frontend.xml ====
+
<server>
+
  ...
+
  <cluster-definition id="backend">
+
    <resin:import path="${resin.rootDir}/conf/cluster.xml"/>
+
  </cluster-definition>
+
  ...
+
</server>
+

Revision as of 07:13, 14 January 2009


Resin documentation is at http://www.caucho.com/resin/doc/balance.xtp

Load balancing spreads the load among multiple backend Resin servers in a Cluster. A frontend Resin server proxies requests to the backend servers and sends the results to the clients.

We'll use 192.168.0.10 as the frontend machine and 192.168.0.20 through 192.168.0.28 as the backend machines.

The frontend server and the backend cluster have different configurations since they perform different roles.

The Frontend Server

  1. dispatches requests to the backend servers, generally using sticky sessions
  2. acts as a Proxy Cache for the backend cluster
  3. pools the proxy sockets for efficiency

== The Backend Cluster

  1. does the actual work: the database querying and form processing
  2. manages persistent sessions

Frontend Configuration

The frontend needs to configure:

  1. The external HTTP and HTTPS ports its listening to
  2. The cluster-definition of the backend cluster
  3. A LoadBalanceServlet to dispatch requests to the backend

resin.xml

<resin xmlns="http://caucho.com/ns/resin"
       xmlns:resin="http://caucho.com/ns/resin/core">
  <cluster id="load-balance">
      <server-default>
        <http host="*" port="80"/>
      </server-default>

      <server id="web-a" address="192.168.0.10" port="6800"/>

      <host id="">
          <web-app id="">
             <rewrite-dispatch>
                 <load-balance regexp="" cluster="app-tier"/>
             </rewrite-dispatch>
          </web-app>
       </host>
   </cluster>

    <cluster id="app-tier">
         <root-directory>/var/www/</root-directory>

         <server id="app-a" address="192.168.0.20" port="6800"/>
         <server id="app-b" address="192.168.0.21" port="6800"/>
         <server id="app-c" address="192.168.0.22" port="6800"/>

          <host id="">
              <web-app-deploy path="webapps"/>
          </host> 
       </cluster>
 </resin>
Personal tools