Limit Number of Concurrent Jobs on Node

Situation

Some grid nodes may have limited resource, and can only run limited number of concurrent jobs.

Demonstration

Project1, project2, and project3 are used to demonstrate the case where server node only permits to run two concurrent jobs.

  1. Trigger project1
  2. Trigger project2 right after you triggered project1, without waiting for its finish.
  3. Trigger project3 right after you triggered project2, without waiting for its finish.
  4. Switch to build log of these three configurations. You will see that project1 and project2 are actually doing the job (printing the message do my job with acquired resource...), while project3 is waiting for the resource (printing the message Executing pre-execute script...).
  5. After project1 or project2 finishes (in about 1 minute), project3 will acquire the resource and do the job.

Resolution

Switch to master step definition of these three projects:

  1. the pre-execute action is defined as:
    groovy:
    node.getResource("resource1", new java.util.concurrent.Semaphore(2)).acquire();
    

    This tells QuickBuild to get node resource named resource1, and create the resource as a Java semaphore object with two permits if it does not already exist. And then acquire the resource by calling its acquire method before executing the step.

  2. the post-execute action is defined as:
    groovy:node.getResource("resource1").release();
    

    This tells QuickBuild to release the node resource named resource1 before finishing the step.

Labels:

Enter labels to add to this page:
Wait Image 
Looking for a label? Just start typing.