general load balancing issues

Robert Watson rwatson at freebsd.org
Mon Dec 15 09:42:34 PST 2003


On Mon, 15 Dec 2003, Matthew Seaman wrote:

> On Mon, Dec 15, 2003 at 12:46:52PM +0100, Bogdan TARU wrote:
> >  Right now I am considering a setup with one common NFS repository for
> >  the configuration files, Apache binaries, Web content and temp
> >  directory for PHP, NFS resource which will be mounted on all the
> >  'front' webservers. I am wondering, though, if I will be able (by
> >  having one common temp directory for PHP) to load-balance the domains
> >  involving sessions: will the sessions be lost when connsecutive hits
> >  go to different webservers, or not? 
> 
> The canonical answer to this is to store the session data in the
> back-end database, so that it's accessible to all of your servers. 
> 
> See the PHP docs for session_set_save_handler(). There's an example of
> how to do this in the O'Reilly Platypus book "Web Database Applications
> with PHP and MySQL", or contact me off list and I can send you some
> sample code.  Probably a good idea to take this off-list anyhow, as it's
> not really hackers at ... material. 

Another approach I've seen is to avoid the use of state as much as
possible, but when the user starts accessing a stateful service, to
redirect them from the load balancer to one of the back end servers
directly.  This assumes that the majority of content generating load is
static, of course (which may well not be the case because dynamic content
generates much more load than static content in many installations).

Another approach is, if there is little state being used, to store the
state in the client via URL lines or cookies.  This can be especially
effective if you use a keyed hash with expiry as part of the cookie or URL
data so that you can trust the state.

When setting up load balancing with state, one of the hardest things is
making sure the solution isn't slower than the original, and the details
of the local installation are often relevant.  If there are frequent state
queries, going to a backend database can make things slower.  If they're
infrequent, and enough of the work can happen on the web server, it can
make things a lot faster (and it's much easier to manage than many other
solutions, since it "just works"). 

Robert N M Watson             FreeBSD Core Team, TrustedBSD Projects
robert at fledge.watson.org      Senior Research Scientist, McAfee Research




More information about the freebsd-hackers mailing list