Resin 1.1
FAQ
Reference
JavaDoc
Demo
Java Tutorial
Getting Started
Configuration
Topics
JSP
XTP/XSL
JavaScript
JS Library
Servlet
Virtual Hosts
Caching
Balancing
Reliability and Load Balancing
Sites can increase reliability using the web server to distribute the load to more than one JVM. If something happens to the first JVM, Resin will send the request to the backup without the browser even being aware of the redirection.
Single Machine
The cheapest backup strategy just uses a single machine for the web server and two JVMs. One JVM is designated as primary and the other is a backup. If the first fails for some reason, the second will take over. Because the backup is normally not used, it doesn't really take up much system resources.
<caucho.com> <http-server> <srun host='localhost' port='6802'/> <srun-backup host='localhost' port='6803'/> ... </http-server> </caucho.com>
You will, of course, start the two srun processes separately. Here's how on unix:
unix> srun.sh -pid srun1.pid start -srun 1 unix> srun.sh -pid srun2.pid start -srun 2
-pid srun1.pid selects names a pid file so srun.sh -pid srun1.pid stop can tell which srun to stop. -srun select which srun to start. Alternately, you can specify the port directly like:
unix> srun.sh -pid srun1.pid start -srun-port 6802 unix> srun.sh -pid srun2.pid start -srun-port 6803
To make sure that your web server understands the configuration, look at http://host/caucho-status. caucho-status will show the current state of all the JVMs.
Single Web Server Load Balancing
Once you start using multiple servers, you can start distributing the load between a single web server and multiple JVMs. This is a cheap alternative to a router-based load balancer. Also, by using Resin's load balancing, you can make sure that sessions stay on the same machine.
<caucho.com> <http-server> <srun host='host1' port='6802'/> <srun host='host2' port='6802'/> <srun host='host3' port='6802'/> ... </http-server> </caucho.com>
Each host will have an identical configuration.
What about sessions?
A 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:
host1 | aaaxxx
host2 | baaxxx
host3 | caaxxx
On the web server, mod_caucho will decode the cookie and send it to the appropriate host. So baaX8Zwoo would go to host2. In the infrequent case that host2 fails, Resin will send the request to host3. The user will lose the session but that's a minor problem compared to showing a connection failure error.
Multiple Web Servers
Many larger sites like to use multiple web servers with a JVM and a web server on each machine. A router will distribute the load between the machines. A central database handles session state In this configuration, the site needs to take control of its own sessions. Because the router will distribute the load randomly, any persistent session state needs to be handled by a centralized server like a database. Even in this configuration, you can use Resin's load balancing to increase reliability. Each web server should choose its own JVM first, but use another machine as a backup. In this case, you can use the trick that localhost refers to the preferred host. The configuration would look like:
<caucho.com> <http-server> <srun host='localhost' port='6802'/> <srun-backup host='host1' port='6802'/> <srun-backup host='host2' port='6802'/> <srun-backup host='host3' port='6802'/> ... </http-server> </caucho.com>
Alternately, if you're using Apache, you could configure the sruns in the httpd.conf.
host1 httpd.conf
CauchoConfigFile /home/www/resin/conf/resin.conf CauchoHost host1 6802 CauchoBackup host2 6802
host2 httpd.conf
CauchoConfigFile /home/www/resin/conf/resin.conf CauchoBackup host1 6802 CauchoHost host2 6802
I've made the order consistent so sessions will always go to the correct machine. baaXXX will always go to host2. Normally, of course, sites using this configuration will handle their own cookies.
Multiple Web Servers, Single JVM
Multiple web servers can use the same JVM. For example, a fast plain webserver and an SSL web server may only need a single JVM. (Although a backup would be good.) Since the JVM doesn't care where the request comes from, it can treat each request identically. This simplifies SSL development. A servlet just needs to check the request.isSecure() method to see if the request is SSL or not. Other than that, all requests are handled identically.
When everything fails
By default, if mod_caucho can't connect to any of the JVMs, it will return a basic "can't connect" page to the user. Sites which want a more professional response can redirect the user to an error page. In the resin.conf, you'll use:
<caucho.com> <http-server> <error-page exception='connection' location='/error.html'/> </http-server> </caucho.com>
The error page must be an absolute path because it could be called from any url. Of course, it can't refer to a servlet or to a JSP file.
Caching |  | JSP
Copyright © 1998-2000 Caucho Technology. All rights reserved. Last modified: Tue, 30 May 2000 15:49:14 -0700 (PDT)