Skip to content

Commit

Permalink
[JENKINS-26755] cache node environment
Browse files Browse the repository at this point in the history
to prevent inefficient channel overuse
  • Loading branch information
ndeloof committed Feb 3, 2015
1 parent d6d96e1 commit e0a394a
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion core/src/main/java/hudson/model/Computer.java
Expand Up @@ -164,6 +164,13 @@
private volatile String cachedHostName;
private volatile boolean hostNameCached;

/**
* @see #getEnvironment()
*/
private volatile EnvVars cachedEnvironment;
private volatile boolean environmentCached;


private final WorkspaceList workspaceList = new WorkspaceList();

protected transient List<Action> transientActions;
Expand Down Expand Up @@ -339,6 +346,7 @@ public final void launch() {
* make much sense because as soon as {@link Computer} is connected it can be disconnected by some other threads.)
*/
public final Future<?> connect(boolean forceReconnect) {
environmentCached = false;
connectTime = System.currentTimeMillis();
return _connect(forceReconnect);
}
Expand Down Expand Up @@ -939,7 +947,13 @@ public Map<String,String> getEnvVars() throws IOException, InterruptedException
* If this is the master, it returns the system property of the master computer.
*/
public EnvVars getEnvironment() throws IOException, InterruptedException {
return EnvVars.getRemote(getChannel());
if (environmentCached) {
return cachedEnvironment;
}

cachedEnvironment = EnvVars.getRemote(getChannel());
environmentCached = true;
return cachedEnvironment;
}

/**
Expand Down

0 comments on commit e0a394a

Please sign in to comment.