Load balancing
时间:2006-06-23 来源:softiger
Load balancing
From ResinWiki
Resin documentation is at http://www.caucho.com/resin-3.0/config/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.
Contents
|
The Frontend Server
- dispatches requests to the backend servers, generally using sticky sessions
- acts as a Proxy Cache for the backend cluster
- pools the proxy sockets for efficiency
== The Backend Cluster
- does the actual work: the database querying and form processing
- manages persistent sessions
Frontend Configuration
The frontend needs to configure:
- The external HTTP and HTTPS ports its listening to
- The cluster-definition of the backend cluster
- A LoadBalanceServlet to dispatch requests to the backend
frontend.conf
<resin xmlns="http://caucho.com/ns/resin" xmlns:resin="http://caucho.com/ns/resin/core"> <server> <http host="*" port="80"/> <cluster-definition id="backend"> <client-live-time>15s</client-live-time> <srun id="a" host="192.168.0.20" port="6802"/> <srun id="b" host="192.168.0.21" port="6802"/> </cluster-definition> <cache memory-size="32M"/> <host id=""> <web-app id=""> <servlet servlet-name="balance" servlet-class="com.caucho.servlets.LoadBalanceServlet"> <init> <cluster>backend</cluster> </init> </servlet> <servlet-mapping url-pattern="/*" servlet-name="balance"/> </web-app> </host> </server> </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>