Skip to content

Commit

Permalink
[FIXED JENKINS-8408]
Browse files Browse the repository at this point in the history
If slaves are late to come online after a Jenkins startup, we will see a huge spike of builds as Jenkins attempt to get a workspace for polling.
  • Loading branch information
kohsuke committed Oct 26, 2013
1 parent 41ce6c5 commit 28737ee
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
3 changes: 3 additions & 0 deletions changelog.html
Expand Up @@ -55,6 +55,9 @@
<!-- Record your changes in the trunk here. -->
<div id="trunk" style="display:none"><!--=TRUNK-BEGIN=-->
<ul class=image>
<li class=bug>

This comment has been minimized.

Copy link
@jglick

jglick Nov 19, 2013

Member

Huh?

Do not polling
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-8408">issue 8408</a>)
<li class=bug>
Fixed the handling of nested variable expansion.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-20280">issue 20280</a>)
Expand Down
26 changes: 21 additions & 5 deletions core/src/main/java/hudson/model/AbstractProject.java
Expand Up @@ -81,11 +81,13 @@
import hudson.util.AlternativeUiTextProvider.Message;
import hudson.util.DescribableList;
import hudson.util.FormValidation;
import hudson.util.TimeUnit2;
import hudson.widgets.BuildHistoryWidget;
import hudson.widgets.HistoryWidget;
import jenkins.model.Jenkins;
import jenkins.model.JenkinsLocationConfiguration;
import jenkins.model.ModelObjectWithChildren;
import jenkins.model.Uptime;
import jenkins.model.lazy.AbstractLazyLoadRunMap.Direction;
import jenkins.scm.DefaultSCMCheckoutStrategyImpl;
import jenkins.scm.SCMCheckoutStrategy;
Expand Down Expand Up @@ -1532,7 +1534,19 @@ private PollingResult _poll(TaskListener listener, SCM scm) throws IOException,
}
}

// build now, or nothing will ever be built
// At this point we start thinking about triggering a build just to get a workspace,
// because otherwise there's no way we can detect changes.
// However, first there are some conditions in which we do not want to do so.

// give time for slaves to come online if we are right after reconnection (JENKINS-8408)
long running = Jenkins.getInstance().getInjector().getInstance(Uptime.class).getUptime();
long remaining = TimeUnit2.MINUTES.toMillis(10)-running;
if (remaining>0) {
listener.getLogger().print(Messages.AbstractProject_AwaitingWorkspaceToComeOnline(remaining/1000));
listener.getLogger().println( " (" + workspaceOfflineReason.name() + ")");
return NO_CHANGES;
}

Label label = getAssignedLabel();
if (label != null && label.isSelfLabel()) {
// if the build is fixed on a node, then attempting a build will do us
Expand All @@ -1541,17 +1555,19 @@ private PollingResult _poll(TaskListener listener, SCM scm) throws IOException,
listener.getLogger().println( " (" + workspaceOfflineReason.name() + ")");
return NO_CHANGES;
}

listener.getLogger().println( ws==null
? Messages.AbstractProject_WorkspaceOffline()
: Messages.AbstractProject_NoWorkspace());
if (isInQueue()) {
listener.getLogger().println(Messages.AbstractProject_AwaitingBuildForWorkspace());
return NO_CHANGES;
} else {
listener.getLogger().print(Messages.AbstractProject_NewBuildForWorkspace());
listener.getLogger().println( " (" + workspaceOfflineReason.name() + ")");
return BUILD_NOW;
}

// build now, or nothing will ever be built
listener.getLogger().print(Messages.AbstractProject_NewBuildForWorkspace());
listener.getLogger().println( " (" + workspaceOfflineReason.name() + ")");
return BUILD_NOW;
} else {
WorkspaceList l = b.getBuiltOn().toComputer().getWorkspaceList();
return pollWithWorkspace(listener, scm, b, ws, l);
Expand Down
1 change: 1 addition & 0 deletions core/src/main/resources/hudson/model/Messages.properties
Expand Up @@ -33,6 +33,7 @@ AbstractItem.Pronoun=Job
AbstractProject.AssignedLabelString_NoMatch_DidYouMean=There\u2019s no slave/cloud that matches this assignment. Did you mean \u2018{1}\u2019 instead of \u2018{0}\u2019?
AbstractProject.NewBuildForWorkspace=Scheduling a new build to get a workspace.
AbstractProject.AwaitingBuildForWorkspace=Awaiting build to get a workspace.
AbstractProject.AwaitingWorkspaceToComeOnline=We need to schedule a new build to get a workspace, but deferring {0}ms in the hope that one will become available soon
AbstractProject.Pronoun=Project
AbstractProject.Aborted=Aborted
AbstractProject.BuildInProgress=Build #{0} is already in progress{1}
Expand Down

2 comments on commit 28737ee

@schlamar
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I manually delete a workspace it will not be created anymore. I guess this is caused by this commit. Message is:

We need to schedule a new build to get a workspace, but deferring 414ms in the hope that one will become available soon (nonexisting_workspace)
Done. Took 0 ms
No changes

@jglick
Copy link
Member

@jglick jglick commented on 28737ee Nov 19, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@schlamar if you have noticed a regression, please file it ASAP in JIRA with any relevant steps to reproduce, marked with the regression label, and have it be “blocking” JENKINS-8408.

Please sign in to comment.