On Fri, 2010-01-22 at 19:31 +0200, Timo Sirainen wrote: > Better would be to have some kind of a database that externally monitors > what servers are up and where users currently have connections, and > based on that decide where to redirect a new connection. Although that's > also slightly racy unless done carefully.
Wonder if something like this would work: servers ( id integer, host varchar, ip varchar, last_time_healty timestamp, connection_count integer, new_connections_ok boolean ); user_connections ( user_id integer primary key, server_id integer, last_lookup timestamp, imap_connections integer ); Then some kind of logic that: - if user already exists in user_connections table AND (imap_connections > 0 OR last_lookup>now() - 1 hour) use the old server_id - otherwise figure out a new server for it based on servers' connection_count and new_connections_ok. - when inserting, handle on duplicate key error - when updating, use update user_connections .. where user_id = $userid and server_id = $old_server_id, and be prepared to handle when this returns 0 rows updated. Once in a while maybe clean up stale rows from user_connections. And properly keeping track of imap_connections count might also be problematic, so maybe once in a while somehow check from all servers if the user actually still has any connections.
signature.asc
Description: This is a digitally signed message part