Master-agent architecture in Jenkins - Time & Space Complexity
We want to understand how the time to complete tasks changes when using Jenkins master-agent setup.
How does adding more agents affect the total work time?
Analyze the time complexity of the following Jenkins pipeline snippet using master and agents.
pipeline {
agent none
stages {
stage('Build') {
parallel {
stage('Agent 1') {
agent { label 'agent1' }
steps { echo 'Building on agent 1' }
}
stage('Agent 2') {
agent { label 'agent2' }
steps { echo 'Building on agent 2' }
}
}
}
}
}
This pipeline runs build steps in parallel on two separate agents managed by the master.
Look for repeated or parallel work done by agents.
- Primary operation: Parallel build steps executed on agents.
- How many times: Once per agent, simultaneously.
As the number of agents increases, tasks run at the same time, reducing total time.
| Input Size (agents) | Approx. Total Time |
|---|---|
| 2 | Time for 1 task (parallel) |
| 10 | Time for 1 task (parallel) |
| 100 | Time for 1 task (parallel) |
Pattern observation: Total time stays about the same as agents increase, because tasks run in parallel.
Time Complexity: O(1)
This means total build time does not grow with more agents since tasks run at the same time.
[X] Wrong: "Adding more agents always increases total build time."
[OK] Correct: More agents let tasks run in parallel, so total time usually stays the same or decreases.
Understanding how Jenkins master-agent architecture scales helps you explain real-world build pipelines clearly and confidently.
"What if tasks on agents had dependencies and could not run fully in parallel? How would the time complexity change?"