in reply to Ressource dispatcher

Is automatic reclamation of the session in the event of your perl script abnormally exiting an issue? I.e. if the script using the session dies, do you want the session automatically released?

If so, consider keeping track of the used sessions with locks on some OS resource - like a file. When the process holding the lock exits, the lock will automatically be released. Otherwise this is very similar to the database approach except that you would query the status of the sessions via the OS with commands like fuser and lsof instead of using SQL.

Another possibility is to use the advisory locking feature provided for by mysql. It allows you to 'lock' an arbitrary string, and the lock will be released when the database connection is closed.

I would first explore solutions where you don't have to write your own daemon. This will mean that mean that you'll be putting the session acquisition code in your perl scripts, and scripts which are waiting to run will have to periodically poll the pool of sessions for a free session, but it's easy to implement, and it might work well enough.

Replies are listed 'Best First'.
Re^2: Ressource dispatcher
by jeepj (Scribe) on Mar 10, 2008 at 09:18 UTC

    Thank you Corion and pc88mxer, I considered both solutions, and finally decided to go for a file locking mechanism.

    The code is done in a common library, thus easily maintained, and this avoid the writing of a daemon. I am using the flock() function.

    Furthermore, the resource consumption is quite high when 15 or 20 scripts are running in parallel, so avoiding the database approach was a better solution (even if SQLite is quite low on memory and CPU usage).

    The persistence aspect, to know which script is running on a given session, is kept by the library: when a script requires a session, the function giving the lock is also printing in the file the name of the script, and the timestamp.