0
0
Jenkinsdevops~5 mins

Master-agent architecture in Jenkins - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: Master-agent architecture
O(1)
Understanding Time 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?

Scenario Under Consideration

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.

Identify Repeating Operations

Look for repeated or parallel work done by agents.

  • Primary operation: Parallel build steps executed on agents.
  • How many times: Once per agent, simultaneously.
How Execution Grows With Input

As the number of agents increases, tasks run at the same time, reducing total time.

Input Size (agents)Approx. Total Time
2Time for 1 task (parallel)
10Time for 1 task (parallel)
100Time for 1 task (parallel)

Pattern observation: Total time stays about the same as agents increase, because tasks run in parallel.

Final Time Complexity

Time Complexity: O(1)

This means total build time does not grow with more agents since tasks run at the same time.

Common Mistake

[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.

Interview Connect

Understanding how Jenkins master-agent architecture scales helps you explain real-world build pipelines clearly and confidently.

Self-Check

"What if tasks on agents had dependencies and could not run fully in parallel? How would the time complexity change?"