![]() | ![]() | ![]() |
| |||||||||||||||
![]() | ||||||||||||||||||
![]() | ![]() | |||||||||||||||||
Resin 3.1 Documentation Examples Changes Overview Installation Configuration Quercus SOA/IoC JSP Servlets and Filters Admin (JMX) EJB Amber Security Performance Hessian XML and XSLT Third-party Troubleshooting/FAQ tags Common Tasks Relax Schema howto Config FAQ Scrapbook DB Scrapbook Virtual Hosting Database Load Balancing Sessions Clustered Sessions Tuning ISP WebApp Deploy |
Resin's HTTP Web Server includes load balancing for scalability and reliability. Using Resin as the Load BalancerResin Professional includes a LoadBalanceServlet that can balance requests to backend servers. Because it is implemented as a servlet, this configuration is the most flexible. A site might use 192.168.0.1 as the frontend load balancer, and send all requests for /foo to the backend host 192.168.0.10 and all requests to /bar to the backend host 192.168.0.11. Since Resin has an integrated HTTP proxy cache, the web-tier machine can cache results for the backend servers. Using Resin as the load balancing web server requires a minimum of two configuration files: one for the load balancing server, and one for the backend servers. The front configuration will dispatch to the backend servers, while the backend will actually serve the requests. The web-tier server does the load balancingIn the following example, there are three servers and two conf files. The first server (192.168.0.1), which uses web-tier.conf, is the load balancer. It has an <http> listener, it receives requests from browsers, and dispatches them to the backend servers (192.168.0.10 and 192.168.0.11). <resin xmlns="http://caucho.com/ns/resin"> <cluster id="web-tier"> <server-default> <http port="80"/> </serve-default> <server id="web-a" address="192.168.0.1"/> <server id="web-b" address="192.168.0.1"/> <cache disk-size="1024M" memory-size="256M"/> <host id=""> <web-app id="/"> <!-- balance all requests to cluster app-tier --> <rewrite-dispatch> <load-balance regexp="" cluster="app-tier"/> </rewrite-dispatch> </web-app> </host> </cluster> <cluster id="app-tier"> <server id="app-a" address="192.168.0.10" port="6800"/> <server id="app-b" address="192.168.0.11" port="6800"/> <persistent-store type="cluster"> <init path="cluster"/> </persistent-store> <web-app-default> <session-config> <use-persistent-store/> </session-config> </web-app-default> <host id="www.foo.com"> ... </host> </cluster> </resin> The LoadBalanceServlet selects a backend server using a round-robin policy. Although the round-robin policy is simple, in practice it is as effective as complicated balancing policies. In addition, because it's simple, round-robin is more robust and faster than adaptive policies. The backend server respond to the requestsA seperate conf file is used to configure all of the backend servers.
In this case, there are two backend servers, both configured in the conf file
Sites using sessions will configure distributed sessions to make sure the users see the same session values. Starting the servers192.168.0.1> java lib/resin.jar -server web-a start 192.168.0.2> java lib/resin.jar -server web-b start 192.168.0.10> java lib/resin.jar -server app-a start 192.168.0.11> java lib/resin.jar -server app-b start DispatchingIn most cases, the web-tier will dispatch everything to the app-tier servers. Because of Resin's proxy cache, the web-tier servers will serve static pages as fast as if they were local pages. In some cases, though, it may be important to send different requests to different backend clusters. The <load-balance> tag can choose clusters based on URL patterns. The following <rewrite-dispatch> keeps all *.png, *.gif, and *.jpg files on the web-tier, sends everything in /foo/* to the foo-tier cluster, everything in /bar/* to the bar-tier cluster, and keeps anything else on the web-tier. <resin xmlns="http://caucho.com/ns/resin"> <cluster id="web-tier"> <server id="web-a"> <http port="80"/> </server> <cache memory-size="64m"/> <host id=""> <web-app id="/"> <rewrite-dispatch> <dispatch regexp="(\.png|\.gif|\.jpg)"/> <load-balance regexp="^/foo" cluster="foo-tier"/> <load-balance regexp="^/bar" cluster="bar-tier"/> </rewrite-dispatch> </web-app> </host> </cluster> <cluster id="foo-tier"> ... </cluster> <cluster id="bar-tier"> ... </cluster> </resin> Distributed SessionsA session needs to stay on the same JVM that started it. Otherwise, each JVM would only see every second or third request and get confused. To make sure that sessions stay on the same JVM, Resin encodes the cookie with the host number. In the previous example, the hosts would generate cookies like:
On the web-tier, Resin will decode the cookie and send it to the appropriate host. So would go to app-b.In the infrequent case that app-b fails, Resin will send the request to app-a. The user might lose the session but that's a minor problem compared to showing a connection failure error. To save sessions, you'll need to use distributed sessions. Also take a look at tcp sessions. The following example is a typical configuration for a distributed server using an external hardware load-balancer, i.e. where each Resin is acting as the HTTP server. Each server will be started as or to grab its specific configuration.In this example, sessions will only be stored when the server shuts down, either for maintenance or with a new version of the server. This is the most lightweight configuration, and doesn't affect performance significantly. If the hardware or the JVM crashes, however, the sessions will be lost. (If you want to save sessions for hardware or JVM crashes, remove the <save-only-on-shutdown/> flag.) <resin xmlns="http://caucho.com/ns/resin"> <cluster id="app-tier"> <server-default> <http port='80'/> </server-default> <server id='app-a' address='192.168.0.1'/> <server id='app-b' address='192.168.0.2'/> <server id='app-c' address='192.168.0.3'/> <persistent-store type="cluster"> <init path="cluster"/> </persistent-store> <web-app-default> <!-- enable tcp-store for all hosts/web-apps --> <session-config> <use-persistent-store/> <save-only-on-shutdown/> </session-config> </web-app-default> ... </cluster> </resin> Choosing a backend serverRequests can be made to specific servers in the app-tier. The web-tier uses the value of the jsessionid to maintain sticky sessions. You can include an explicit jsessionid to force the web-tier to use a particular server in the app-tier. Resin uses the first character of the jsessionid to identify the backend server to use, starting with `a' as the first backend server. If wwww.example.com resolves to your web-tier, then you can use:
See Also
|