Ok I'll try to explain a bit further, and i apologize for the confusion, the random variable was just to test having multiple values being put into the "return value" hash. In this demo, it does indeed do absolutely nothing.
In my main program, clients connected, and threadPool1 handles their responses. They issue commands, and can either specify those commands to be run in their same thread so they can see the output in the interactive shell, or run in the background (and get pushed to threadPool2).
So the jobQueue. When users issue commands, their command can not always be run right away depending on their criteria and what machine in our farm they want to run it on. The queue maintains the order commands were executed in by using the JobNodes which contain information from the command they entered. The jobQueue is not REALLY acting as a typical queue, but more as a utility to block the thread that issued the command until it is it's turn (using subroutines like enqueueJob() that block until a value is set). The first case it blocks is setting the job number. After the job queue returns the job number as shown in my demo, the client thread will continue. The jobQueue will pause the command again to tell it actually what resource it should be using.
The purpose of the JobQueue is we want to preserve the order the commands are issued in regardless of if the database is updated before the queue gets back to a job that was deferred. For example
- User1 issues 2 commands for machine M1
- User2 issues 2 commands for M1, and M1 can only have 3 commands running
- User3 issues 2 commands for M1
Our queue now has (user2, user3, user3)
The current approach, using the Thread::Queue as an array, allows us to issue one DB query at the beginning of each iteration for the state of all our resources, so we can reference that instead of querying the database for every job in the queue every time we check it. So our process is:
- Query database for current state and build hash
- check nodes
- repeat steps above starting at beginning of array
This allows us to preserve the order because: if we dequeue/enqueue user2's, and one of user1's finishes and updates our database, then when we dequeue user3's command, it will see that M1 has an available resource, and run that job. That is what we want to avoid. Using it as a proper queue would not preserve the order in that fringe case without some more tinkering.
|Replies are listed 'Best First'.|
Re^7: Thread terminating abnormally COND_SIGNAL(6)
by BrowserUk (Pope) on Jul 18, 2013 at 00:52 UTC
by rmahin (Scribe) on Jul 18, 2013 at 01:44 UTC
by BrowserUk (Pope) on Jul 18, 2013 at 03:12 UTC
by rmahin (Scribe) on Jul 18, 2013 at 17:51 UTC
by BrowserUk (Pope) on Jul 18, 2013 at 20:04 UTC