On Thu, Nov 11, 2004 at 04:28:46PM +0000, Paul Makepeace wrote:
Je 2004-11-11 16:23:43 +0000, Kake L Pugh skribis:
I'm also trying to offer a solution that isn't heavy on your time so the service could come back up asap - queuing searches during load.
Do you know of some already-working thing that does this? There's been discussion on IRC but we haven't come up with a good way to do it yet.
I'm a frayed knot. London.pm?
Quick n' dirty solution ... on every search request, do this:
send "please wait" page if lockfile doesn't exist in /tmp create it endif flock the lockfile (use a blocking exclusive lock) [expensive bit goes here - searching and (perhaps) sorting] unflock send results
This will prevent parallel searching, the only race condition is if two processes both create the lockfile, but you need not care about that.
Expanding it to support up to N concurrent searches is fairly easy - just have N lockfiles and use non-blocking flocks to try them all, and if none are available sleep for a bit before trying again. Making N dynamic based on system load is also pretty trivial.