Agent connection methods (SSH, JNLP) in Jenkins - Time & Space Complexity
We want to understand how the time to connect Jenkins agents changes as the number of agents grows.
How does the connection method affect the time Jenkins spends managing agents?
Analyze the time complexity of this Jenkins pipeline snippet that connects multiple agents using SSH or JNLP.
pipeline {
agent none
stages {
stage('Connect Agents') {
steps {
script {
for (int i = 0; i < agents.size(); i++) {
agents[i].connect()
}
}
}
}
}
}
This code loops through a list of agents and connects each one using its connect method.
Look for repeated actions that take time.
- Primary operation: Connecting each agent (SSH or JNLP connection setup)
- How many times: Once per agent, so as many times as there are agents (n times)
Connecting agents happens one by one, so time grows as more agents are added.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | 10 connections |
| 100 | 100 connections |
| 1000 | 1000 connections |
Pattern observation: Time grows directly with the number of agents; doubling agents doubles connection time.
Time Complexity: O(n)
This means the total connection time increases linearly as you add more agents.
[X] Wrong: "Connecting multiple agents happens all at once, so time stays the same no matter how many agents."
[OK] Correct: Each agent connection is a separate action that takes time, so more agents mean more total time.
Understanding how Jenkins manages agent connections helps you explain system scaling and resource use clearly.
What if Jenkins connected agents in parallel instead of one by one? How would the time complexity change?