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?"
Practice
Solution
Step 1: Understand the master role
The Jenkins master is responsible for controlling and scheduling jobs, meaning it decides when and where jobs run.Step 2: Differentiate from agent role
Agents actually run the jobs on separate machines, not the master.Final Answer:
To control and schedule jobs -> Option BQuick Check:
Master controls jobs = B [OK]
- Confusing master with agent role
- Thinking master runs jobs directly
- Assuming master only stores logs
Solution
Step 1: Recall Jenkins pipeline syntax
In Jenkins declarative pipeline,agent anymeans the job can run on any available agent.Step 2: Check other options
Options likemaster agent,run agent, andnode masterare not valid syntax for defining agents.Final Answer:
agent any -> Option CQuick Check:
Correct agent syntax = A [OK]
- Using invalid keywords like 'master agent'
- Confusing 'node' with 'agent'
- Writing 'run agent' which is not valid
pipeline {
agent { label 'linux' }
stages {
stage('Build') {
steps {
echo 'Building on Linux agent'
}
}
}
}Solution
Step 1: Analyze the agent label
The pipeline specifiesagent { label 'linux' }, so it will run on an agent with the label 'linux'.Step 2: Understand job execution
Since the label is specific, the job will not run on any agent or the master unless they have that label.Final Answer:
The job runs on an agent labeled 'linux' -> Option DQuick Check:
Agent label 'linux' = C [OK]
- Assuming 'agent any' runs here
- Thinking job runs on master by default
- Believing syntax causes failure
Solution
Step 1: Understand agent offline status
An agent shows offline if Jenkins cannot connect to it, often because the machine is off or network unreachable.Step 2: Eliminate other causes
Master overload or pipeline syntax errors do not cause agent offline status. Label mismatch prevents job assignment but does not make agent offline.Final Answer:
Agent machine is turned off or unreachable -> Option AQuick Check:
Offline agent = unreachable machine [OK]
- Blaming master overload for offline agent
- Confusing syntax errors with connectivity
- Thinking label mismatch causes offline
Solution
Step 1: Understand workload distribution
Adding more agents allows Jenkins to run jobs in parallel on different machines, improving performance.Step 2: Evaluate other options
Running all jobs on master overloads it, disabling agents reduces capacity, and one agent limits parallelism.Final Answer:
Add more agents to distribute the workload -> Option AQuick Check:
More agents = better parallel job handling [OK]
- Overloading master with all jobs
- Disabling agents thinking it helps
- Relying on single powerful agent only
Ready to prove it?
Pass the test and this pattern moves unknown
