From owner-freebsd-hackers@FreeBSD.ORG Mon Dec 15 09:42:34 2003 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 7C70916A4CE for ; Mon, 15 Dec 2003 09:42:34 -0800 (PST) Received: from fledge.watson.org (fledge.watson.org [204.156.12.50]) by mx1.FreeBSD.org (Postfix) with ESMTP id DC2C343D1F for ; Mon, 15 Dec 2003 09:42:23 -0800 (PST) (envelope-from robert@fledge.watson.org) Received: from fledge.watson.org (localhost [127.0.0.1]) by fledge.watson.org (8.12.10/8.12.10) with ESMTP id hBFHg3Ud092887; Mon, 15 Dec 2003 12:42:03 -0500 (EST) (envelope-from robert@fledge.watson.org) Received: from localhost (robert@localhost)hBFHg2KH092884; Mon, 15 Dec 2003 12:42:03 -0500 (EST) (envelope-from robert@fledge.watson.org) Date: Mon, 15 Dec 2003 12:42:02 -0500 (EST) From: Robert Watson X-Sender: robert@fledge.watson.org To: Matthew Seaman In-Reply-To: <20031215124203.GA19265@happy-idiot-talk.infracaninophile.co.uk> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII cc: freebsd-hackers@freebsd.org Subject: Re: general load balancing issues X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 15 Dec 2003 17:42:34 -0000 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@... 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@fledge.watson.org Senior Research Scientist, McAfee Research