Throttling on arbitrary resources.

Implements throttling for arbitrary resources.
https://github.com/seomoz/qless-core/issues/27

Currently running in our production system with 14k worker processes spread across 15 redis processes.

Created a throttle object model in qless-core which consists of a active job set, a pending job set, and a maximum value. The throttle controls how many jobs that can run simultaneously.

Modified the put command to attempt to throttle new jobs. This is to prevent wasting pops to move jobs into the throttled state.

Modified the pop command to check if all the throttles for the job are available and if not to add it to pending queue for one of the throttles.

Modified the complete, fail, retry commands to release all throttles associated with the job.

When a throttle is released the throttle checks its pending job set and inserts up to (maximum - active) jobs into the waiting queue to be popped.

Let me know of any questions, changes that need to be made etc.


I thought about adding it to every unavailable set, then the logic around when to add it back to the queue becomes confusing. Do all jobs in a given queue get stuck behind the first job in the pending set if its other throttles are not available? By only using one we basically keep moving it to the back of the pending set. honestly not a huge fan of multiple throttles in general.