views:

186

answers:

2

I'm looking for simple ways to monitor and limit the number of instances of our application under Terminal Server (2003 and 2008).

The purpose of this restriction is to make sure we don't overload our servers. This is an internal administrative requirement - I am not looking for a licensing solution.

The application in question is written in Python 2.6 (32-bit) but I'm happy to receive development tool agnostic answers. Although we are not using Citrix, I am happy to receive Citrix related ideas with the hope that I can use a similar technique with Terminal Server.

Thank you, Malcolm

+1  A: 

The various instances of your application need some way to communicate with one another. When an instance starts up, it asks the question, 'how many are already running?'. If there are more than the allowed n, it chooses not to start up.

One implementation approach might be to make n files to lock for the n instances of your application you allow to run at the same time. Then, the application tries to get a lock on one of those files; if it can't, it exits immediately. Release the lock when you're done, but presumably the OS would release the lock for you if you crash.

Another approach would be to register some per-process unique piece of information (a PID?) in a central location (some database) when you start.

Yet a third might be to use a host-only network server where either a dedicated server program or one of the instances coordinates communications with the other instances. If the host exits, one of the other instances can self-promote to being the server.

Matt Anderson
A: 

Based on feedback on the Python Win32 API mailing list I'm also considering one of the following techniques:

  1. Using Windows Semaphores

  2. Using a pool of Mutexes (offer better recoverability than semaphores)

  3. Using a range of ports

Malcolm

Malcolm