Skip to content

Commit

Permalink
Prevent over-provisioning
Browse files Browse the repository at this point in the history
Jenkins can keep on asking for more executors even though it has enough
slaves promised to it that will satisfy demand once they come online.
We already keep track of the number of slaves that we are in the process
of creating but have yet to give to Jenkins, so if we include that count
when determining demand, we can ensure we do not provision more
containers than permitted.
  • Loading branch information
pjdarton authored and ndeloof committed Feb 22, 2018
1 parent 9345f77 commit 47c038a
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/main/java/com/nirima/jenkins/plugins/docker/DockerCloud.java
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,22 @@ public synchronized Collection<NodeProvisioner.PlannedNode> provision(final Labe
final List<DockerTemplate> templates = getTemplates(label);
int remainingWorkload = numberOfExecutorsRequired;

// Take account of the executors that will result from the containers which we
// are already committed to starting but which have yet to be given to Jenkins
for ( final DockerTemplate t : templates ) {
final int numberOfContainersInProgress = countContainersInProgress(t);
final int numberOfExecutorsInProgress = t.getNumExecutors() * numberOfContainersInProgress;
remainingWorkload -= numberOfExecutorsInProgress;
}
if ( remainingWorkload != numberOfExecutorsRequired ) {
final int numberOfExecutorsInProgress = numberOfExecutorsRequired - remainingWorkload;
if( remainingWorkload<=0 ) {
LOGGER.info("Not provisioning additional slaves for {}; we have {} executors being started already", label, numberOfExecutorsInProgress);
} else {
LOGGER.info("Only provisioning {} slaves for {}; we have {} executors being started already", remainingWorkload, label, numberOfExecutorsInProgress);
}
}

while (remainingWorkload > 0 && !templates.isEmpty()) {
final DockerTemplate t = templates.get(0); // get first

Expand Down

0 comments on commit 47c038a

Please sign in to comment.