Resource Throttling in Jenkins

Resource Throttling in Jenkins

A complete, plain-English guide to holding Jenkins back on purpose: how to limit how many builds run at once, how often they start, and how much of a shared machine, service, or cloud budget they may use, so that fast feedback never turns into a crashed test server or a shocking bill.

Imagine a small water tank that feeds a whole street. On an ordinary evening, a few taps are open and the pressure is fine. But on a hot Sunday, every household turns on a sprinkler at once. The tank runs dry, the pressure collapses, and nobody can even fill a kettle. The water company solves this not by making people thirstier, but by adding limits: sprinklers only on certain hours, and no more than so many at a time. Everyone gets a fair, reliable supply because nobody is allowed to take everything at once.

A busy Jenkins server has the same problem. Developers push code all day. Each push can start builds, tests, and deployments, and each of these leans on shared things: build machines, test databases, cloud accounts, package registries, and third-party services. Left alone, Jenkins will happily start everything it can, as fast as it can, until something breaks. Resource throttling is the set of tools that let you say “no more than this many at once” or “no faster than this rate”. This guide teaches the whole topic from zero, and shows how to use throttles to protect your systems without slowing your team more than necessary.

1What Is Resource Throttling?

We begin with the simplest picture: what a throttle is, and what it protects.

Jenkins is a tool that automates building, testing, and delivering software. Every build it runs consumes resources: processor time and memory on agents, slots on a test database, calls to an outside service, and money on a cloud account. A resource is only useful if it stays healthy. A database that receives twenty simultaneous test runs when it can handle three does not simply run slowly. It falls over, and every test fails.

Throttling means deliberately limiting how much work is allowed to use a resource. A throttle can limit the number of builds running at the same moment, the number of builds started in a period of time, or the amount of a machine that a single build may take. Work that exceeds the limit is not thrown away. It waits in the queue and starts when there is room.

flowchart LR
  A["Many builds want to run"] --> B["The throttle decides how many may proceed"]
  B --> C["Allowed builds use the shared resource"]
  B --> D["The others wait in the queue"]
  D --> B
    
Figure 1. A throttle sits between demand and a shared resource. Builds that do not fit wait and try again.
Everyday analogy

A busy restaurant does not seat every arriving customer at once. The host keeps a count of free tables and lets in only as many parties as the kitchen can handle. The others wait by the door. Nobody is turned away for good, and the kitchen never drowns. The host is the throttle.

What a throttle is not

Not

A way to make builds faster

A throttle usually makes an individual build wait longer. Its purpose is to keep the shared system healthy, so that all builds finish reliably.

Not

A security wall

Throttles limit volume, not who may act. Permissions and credentials handle who is allowed in.

Not

A single feature

Jenkins has no one switch called throttling. It is a family of tools, from executor counts to plugins to cloud caps.

Not

Free

Every limit trades speed for safety. Too tight a limit leaves capacity idle and developers waiting.

i
Note

Several of the tools in this guide come from plugins, and their names, options, and screens change over time. Check the current documentation and the Pipeline Syntax page on your own server before relying on any option named here.

2Why Throttling Exists

To see why throttles matter, imagine a busy afternoon with none.

Problem one: shared things with a hard limit

A team keeps one integration test database. It was built to serve three test runs at the same time. On a busy afternoon, eight pipelines reach the integration test stage together. The database is overloaded, queries time out, tests fail for no reason connected to the code, and developers waste hours chasing false alarms. The builds were each correct. Their number made them wrong.

Problem two: bursts of demand

A large merge, a change to a shared library, or a scheduled job can trigger dozens of builds within a minute. The queue fills, all agents are busy, and a developer’s urgent one-line fix waits behind a hundred less important runs.

Problem three: outside limits

Many services outside your control set their own limits. Code-hosting services cap the number of requests per hour. Public container registries limit how many images an anonymous user may pull. If your builds ignore these limits, they get blocked, and builds fail for reasons that have nothing to do with your code.

Problem four: money

Cloud agents cost money by the minute. A mistake in a pipeline, such as a huge matrix or a runaway trigger, can start hundreds of machines. Without a cap, the first sign of trouble may be the invoice.

3
test runs a database can handle at once, in this example
8
pipelines that arrive together without a throttle
5
of them fail for reasons unrelated to their code
Everyday analogy

A motorway on-ramp has a traffic light that lets one car join every few seconds at rush hour. Drivers grumble, but the traffic on the motorway keeps moving. Without the light, cars would flood in, the road would jam, and every journey would take longer. A short, controlled wait at the ramp beats a long jam on the road.

A short wait at the door beats a crash inside the room.

3Concepts and the Three Kinds of Limits

A few ideas come up in every throttling discussion. Learn them once here.

Idea 1

Concurrency

How many things are happening at the same moment, for example how many builds are running right now.

Idea 2

Rate

How many things start in a period of time, for example ten builds per hour.

Idea 3

Capacity

How much a resource can handle before it degrades. The throttle should be set at or below it.

Idea 4

Queue

The waiting line where builds sit until they are allowed to run.

Idea 5

Back-pressure

Making senders slow down when the receiver is full, instead of letting work pile up dangerously.

Idea 6

Category

A named group of jobs that share a limit, so the limit applies to the group as a whole.

The three kinds of limits

KindQuestion it answersTypical Jenkins toolExample
Concurrency limitHow many at once?Executors, throttle categories, locks with a quantity, cloud capsNo more than three builds may use the test database together
Rate limitHow many per period?Build rate limiting, quiet period, polling intervals, API rate strategiesAt most two builds of this job per hour
Size limitHow much may one build take?Container resource limits, agent sizesEach build may use two cores and four gigabytes of memory
Everyday analogy

A swimming pool has three separate rules. Only thirty swimmers at a time (concurrency). No more than one hundred entries per hour, to keep the queue orderly (rate). And each swimmer gets only one lane, not three (size). A pool manager uses all three rules, because each solves a different problem.

i
Tip

Before choosing a tool, name which of the three limits you need. “The database can only handle three at once” is a concurrency limit. “The service allows sixty requests an hour” is a rate limit. “Builds are eating all the memory on the agent” is a size limit. Each has a different fix.

4Executors: The First and Simplest Throttle

Before any plugin, Jenkins already has a built-in throttle: the number of executors.

An executor is a slot on a build agent that runs one piece of work at a time. If your agents together offer ten executors, then at most ten builds, or ten parts of builds, can run at the same moment. All others wait in the build queue. This is the coarsest, and most important, throttle you have. It protects the agents themselves from being overloaded.

Everyday analogy

A car park has a fixed number of spaces. The barrier lets in one car only when a space is free. The number of spaces is the executor count. It limits the whole building, whatever those cars are doing inside.

What executors control and what they do not

What executors control

  • How much work each agent runs at once.
  • The total number of simultaneous builds across all agents.
  • Which kind of machine takes which work, through labels.

What executors do not control

  • How many builds use one shared database or service, since those may run on any agent.
  • How fast builds start over time.
  • How much processor or memory one build takes on a shared agent.
  • What outside systems allow.

Setting the number sensibly

The number of executors on a node should follow what the machine can genuinely carry. Compute-heavy builds need few executors per machine, because each already uses many cores. Builds that mostly wait on networks can share a machine in greater numbers. A machine with too many executors slows every build on it, and one with too few wastes its capacity. Measure the load, change the number a little at a time, and watch what happens to build times.

!
Watch out

More executors is not always a cure for a long queue. If the real limit is a shared test database, adding executors only lets more builds pile onto the database at once, and makes things worse. Throttle the bottleneck, not the whole system.

The controller and executors

The controller, the main Jenkins server, can also have executors. Most teams set this to zero, so that all builds run on agents and the controller stays free for its real job of planning and serving pages. That is itself a throttle: it stops builds from competing with Jenkins for its own machine.

5The Throttle Concurrent Builds Plugin: Categories

When the limit belongs to a shared thing, not to a machine, you need a throttle that spans jobs and agents. The best-known tool for this is the Throttle Concurrent Builds plugin.

This plugin lets an administrator define categories. A category is a name, such as “integration-database”, together with a set of limits. Jobs, or parts of jobs, then declare that they belong to the category. Jenkins counts how many builds in the category are running and refuses to start new ones once the limit is reached. They wait in the queue until a running one finishes.

SettingWhat it doesExample
Category nameA label that jobs use to join the groupintegration-database
Maximum total concurrent buildsThe most builds of this category running at once across the whole Jenkins3
Maximum concurrent builds per nodeThe most builds of this category running at once on any single agent1 or 2
Multi-configuration throttlesSeparate limits for matrix-style jobs and their combinationsLimit the number of combinations at once
Per-project optionThrottle one job on its own, not as part of a categoryOnly two runs of this one job at a time
Everyday analogy

A rented meeting room can hold at most three groups at once. Whichever department books it, the caretaker counts the groups inside, and asks new arrivals to wait when three are already there. The room’s limit belongs to the room, not to any one department. A category is the room’s limit.

Total limit and per-node limit

The two numbers protect different things. The total limit protects the shared resource, such as the database or a licence. The per-node limit protects the agent, by stopping several throttled builds from landing on the same machine. For a database that can serve three test runs, you might set the total to three. If each test run is heavy on the agent as well, you might also set the per-node limit to one, so that the three runs spread over three agents.

Where categories are defined

Categories are defined once, in the system configuration of Jenkins, by an administrator. This keeps the limits central and consistent. Job authors then only choose the category name. A typo in a category name in a Jenkinsfile can mean the job is not throttled at all, or is throttled by the wrong group, so agree on a list of names and document what each one protects.

i
Tip

Name a category after the thing it protects, not after the team that uses it. “integration-database” says why the limit exists. “payments-limit” does not, and nobody will dare change it later.

6Using Throttles in Pipelines, Freestyle Jobs, and Matrices

Where you apply a throttle decides exactly what is counted, and how many executors are wasted while builds wait.

Two ways in a pipeline

In a Pipeline, the throttle plugin offers two places to declare a category. The first is a job property, set for the whole job. The whole run is then counted against the category, from start to finish, and a new run waits in the queue before it even begins. The second is a step that wraps a block of work, usually the block that takes an agent. Only the wrapped block is counted, and other parts of the pipeline run freely.

PlacementWhat is countedBest forWatch for
Job property, whole jobThe entire run of the pipelineJobs that use the shared resource throughoutOver-throttles builds that use it for only one stage
Throttle step around an agent blockOnly the agent block inside itPipelines where one stage uses the shared resourceMust wrap the agent block correctly to count as intended
Freestyle job optionThe whole job runOlder job typesFewer options for partial throttling
Everyday analogy

A theme park can limit the number of visitors in the park at any time, or limit the number on one ride. A whole-park limit is a job-level throttle. A ride limit is a step-level throttle. If only one ride is fragile, limit that ride, and let visitors roam the rest of the park freely.

Keep the throttled part small

A pipeline that compiles code, runs unit tests, runs integration tests against the shared database, and then packages the result should throttle only the integration test stage. Compiling and unit testing use only the agent and can run with as many others as executors allow. A whole-job throttle would hold back all of that work for no reason.

Matrix jobs

A matrix, or multi-configuration, job runs the same work for many combinations, such as several operating systems and versions. Each combination is its own build. A single trigger can therefore create dozens of builds at once. Matrix-specific throttles let you limit how many combinations of one matrix run together, so that a single commit cannot swamp your agents.

Combining with parallel branches

Parallel branches inside one pipeline each want an executor, and may each be counted separately by a step-level throttle. If a pipeline has six branches that use the database, and the category allows three, then three branches run and three wait, even within the same build. Design with this in mind, and consider whether so many branches make sense for that resource.

!
Watch out

Exact syntax and behaviour differ between plugin versions, and between job types. Test with several overlapping builds, watch the queue messages, and confirm the counts on a non-critical job before relying on a throttle to protect anything important.

7Rate Limiting: Quiet Periods, Build Rates, and Polling

Sometimes the problem is not how many builds run together, but how fast new ones keep starting. Rate limits answer that.

The quiet period

Jenkins waits a few seconds, five by default, between a trigger and the moment a build leaves the queue. If more triggers for the same job arrive during that time, they are merged into one build. This short pause absorbs bursts of commits, and every job benefits from it without any extra setup. A longer quiet period merges more triggers into fewer builds, at the cost of slower feedback for the first commit.

Limiting builds per time period

Jenkins also offers ways to limit how many builds of a job may start in a period. A freestyle job has a built-in option to throttle builds, where you state a number of builds and a time period, such as one build per hour. Newer Pipeline versions provide a similar option that you can set as a job option, often with a “user boost” feature so that a build started by a person by hand skips the limit, while automatic triggers respect it. Availability and names vary by version, so check the help page on your server.

Everyday analogy

A bakery says “one batch of bread per hour, whatever the orders”. Customers who arrive in a rush get their loaves in turn, but the oven is never overworked. If the owner personally needs a special loaf right now, she can override the rule. That override is the user boost.

Polling and triggers

Many jobs learn about new commits by polling, which means asking the source-control server every few minutes, “Is there anything new?”. Hundreds of jobs polling every minute can put a heavy load on both Jenkins and the source-control server. Webhooks, where the server sends a message when something changes, are much lighter. Where polling is unavoidable, spread the schedules so that jobs do not all ask on the same minute.

ToolWhat it limitsBest forCost
Quiet periodMerges close-together triggers into one buildBusy branches with frequent commitsSlightly slower first feedback
Build rate limitNumber of builds started per time periodExpensive jobs that need not run on every triggerSome commits wait for the next window
Webhooks instead of pollingLoad from repeated status checksAny large installationNeeds network setup
Staggered schedulesLoad spikes at round times such as the top of the hourMany scheduled jobsSlightly less predictable start times
i
Tip

Avoid scheduling many jobs at exactly midnight or at the top of the hour. Many teams choose these times by habit, and the result is a spike every night. Spreading start times by a few minutes costs nothing and smooths the load.

8Throttling, Locks, and the Other Concurrency Tools

Jenkins offers several tools that limit concurrency. Each fits a different problem. Here they are side by side.

ToolWhat it controlsExtra buildsBest for
ExecutorsHow many builds run on machines at allWait for a slotProtecting agents from overload
Throttle categoriesHow many builds of a group run together, with totals and per-node capsWait in the queueSharing a resource that can serve several builds at once
Lock with a quantity or a poolExclusive use of named resources, one build per resourceWait for a free resourceResources that must not be shared, such as a single device
Disable concurrent buildsOverlap of runs of the same jobWait in the queueJobs that must never overlap with themselves
Rate limit optionStarts per time periodWait until the next periodExpensive jobs
Cloud and container capsHow many dynamic agents may existWait for an agent to startControlling cost and cluster load
Milestone stepOrder of builds at a checkpointOlder builds are abortedStopping outdated builds from finishing late
Everyday analogy

A car-hire firm has a fixed number of cars (executors), a maximum of ten cars out at once on any single weekend deal (a category), a rule that a particular sports car goes to only one driver at a time (a lock), and a limit of fifty rentals a day (a rate limit). All keep the business healthy, in different ways.

Throttle category or lock?

This is the most common choice. A lock treats each resource as a single item that one build holds at a time. It is ideal when you have named things, such as one staging server or five test phones. A throttle category treats the resource as a pool with a count. It is ideal when the resource can serve several builds at once, and you simply want to cap the number, such as a database that handles three parallel runs, and you do not care which “slot” each build gets.

Choose a lock when

  • The resource must be used by exactly one build at a time.
  • Builds need to know which resource they received.
  • You have a small set of named, individually managed items.

Choose a throttle category when

  • The resource can handle several builds, up to a known number.
  • Builds are interchangeable, and no build needs to identify a slot.
  • You want a central limit that administrators can change in one place.
i
Tip

Prefer the simplest tool that fits. If a single job option solves the problem, use it. Reach for categories, locks, and caps only when the simpler options cannot express your limit.

9Cloud, Container, and Machine-Size Limits

When agents are created on demand, throttling protects your budget and your cluster. And inside each agent, size limits protect the builds from one another.

Caps on dynamic agents

Cloud and container plugins create agents when builds need them. Without limits, a burst of builds can create hundreds of machines. Most such plugins offer caps. A container platform plugin usually offers a limit on the total number of build pods in a cloud, and a limit on the number of instances of each pod template. Virtual machine plugins offer a maximum number of instances. Set these below your account quotas and your budget, so that a runaway pipeline hits a Jenkins limit before it hits a cloud bill.

Everyday analogy

A company gives an employee a spending limit on a company card. It is not an insult. It ensures that a lost card or a typing mistake cannot empty the account. Agent caps are the spending limit on your cloud card.

Cap

Total agents per cloud

The absolute maximum of agents that the cloud may have at once. Your safety net.

Cap

Instances per template

The maximum for each kind of agent, so one kind, such as large machines, cannot use the whole budget.

Cap

Idle timeout

How long an unused agent stays alive before removal. Shorter timeouts cut cost, and add start-up delay.

Cap

Quota alerts

Warnings from the cloud side when you approach account limits, so you can act before builds fail.

Size limits inside an agent

On container platforms, each build pod can declare requests, the amount of processor and memory it expects to need, and limits, the amount it may never exceed. Requests help the platform place pods sensibly. Limits stop one greedy build from starving its neighbours. A build that goes over its memory limit is stopped by the platform, and the failure is loud and clear, which is better than a silent slowdown of everything else.

SettingMeaningIf set too lowIf set too high
Processor requestShare of processor time reserved for the buildSlow builds when the node is busyWasted capacity and fewer builds per node
Memory requestMemory reserved for the buildPods placed on nodes without enough memoryFewer pods fit on each node, higher cost
Memory limitMaximum memory before the build is stoppedBuilds killed for running out of memoryOne build can hurt others on the node
Processor limitMaximum processor time the build may useBuilds slowed by throttling even when the node is idleNoisy neighbours
!
Watch out

Guessing sizes leads to two opposite problems: pods too small, which crash or crawl, and pods too big, which waste money. Watch the actual usage of typical builds for a week, then set requests near the typical use and limits somewhat above the peak.

10Throttling Toward External Systems

Your builds do not only use your own machines. They also call outside services with limits of their own. Good pipelines respect those limits.

Where outside limits appear

  • Source-control services cap the number of requests per hour for each account or application. Jenkins plugins that scan repositories and update commit statuses can use up the allowance.
  • Container registries may limit the number of image pulls, especially for anonymous users or shared addresses.
  • Package registries and mirrors may block clients that make too many requests too quickly.
  • Cloud provider interfaces limit how fast you may create, list, or delete resources.
  • Notification and chat services limit the number of messages per minute.

How the pieces of Jenkins help

Tool

API rate strategy

Source-control integration plugins often let you choose how to behave near the limit, for example by slowing requests as the allowance runs low, instead of running into a block.

Tool

Proxy caches

Pulling images and packages through your own repository cache means the outside service is asked once, not once per build.

Tool

Retry with waiting

A pipeline can retry a failed call after waiting, and can wait longer each time, which is called exponential backoff.

Tool

Throttle categories

A category named after the outside service caps how many builds call it together.

sequenceDiagram
  participant P as Pipeline Step
  participant S as External Service
  P->>S: Send a request
  S-->>P: Too many requests so please wait
  P->>P: Wait a short time
  P->>S: Try again
  S-->>P: Still busy
  P->>P: Wait twice as long
  P->>S: Try again
  S-->>P: Success
    
Figure 2. Retrying with growing waits, so a busy service gets time to recover.
Everyday analogy

When you phone a busy help line and hear the engaged tone, you do not redial ten times a second. You wait a minute, try again, and if it is still busy, wait a few minutes longer. Patient retries give the line time to clear. Hammering it only keeps it jammed.

Why growing waits matter

If fifty builds all fail at once and all retry after exactly five seconds, the outside service gets another burst of fifty requests at the same moment, and everything fails again. Growing waits, plus a small random variation, spread the retries out over time. Jenkins provides retry steps and waiting steps that can be combined for this, and the wait step even has a built-in growing delay option in many versions.

!
Watch out

Retries can hide a real outage, and a large number of retrying builds can make an outside service’s problem worse. Keep the number of retries small, put a time limit on the whole operation, and record how often retries happen.

11The Queue, Priorities, and Fairness

Throttles create waiting. How the waiting line behaves decides whether the system feels fair.

flowchart TD
  A["A queued build is ready"] --> B{"Is an executor with the right label free"}
  B -->|No| C["Stay in the queue"]
  B -->|Yes| D{"Would a throttle rule be broken"}
  D -->|Yes| E["Stay in the queue as blocked by a throttle"]
  D -->|No| F["Start on the executor"]
  C --> A
  E --> A
    
Figure 3. A build must pass both the executor check and every throttle rule before it starts.

Why builds wait

A ready build can wait for several different reasons. No executor with the right label is free. Or a throttle category is full. Or a lock is held. Or another run of the same job must finish first. Jenkins shows the reason for each waiting item in the queue. Reading it is the fastest way to know which kind of limit is holding the build.

Queue reasonWhich limit is responsibleWhat to check
Waiting for the next available executorExecutor capacityFree executors, labels, and agent status
Blocked by a throttle or categoryA throttle categoryRunning builds in the category and the configured maximum
Waiting for a lockA lockable resourceWho holds the lock, and whether someone reserved it
Waiting for a previous build to finishDisabled concurrent buildsWhether overlap is really harmful for this job
In the quiet periodThe quiet periodThe countdown, which is short by design
Waiting for a cloud agent to startA cloud cap, or a slow startCap values, quotas, and the platform’s events

Fairness and priority

By default, the queue is mostly first come, first served. That is fair, but not always sensible. An urgent production fix may wait behind a hundred routine runs. Plugins exist that let administrators assign priorities to jobs, so that important work is chosen first when a slot frees up. This can help, but it also introduces a risk: low-priority work may wait forever if higher-priority work never stops arriving, which is called starvation. Use priorities sparingly, with a few clear levels, and watch the waiting time of the lowest level.

Everyday analogy

A hospital emergency department sees patients by urgency, not arrival. That is right for the sickest patients. But if urgent cases never stop coming, a patient with a sprained wrist may wait all day. Good hospitals watch the longest wait, and treat it as a warning sign.

i
Tip

Keep a separate, small pool of executors, marked with its own label, for urgent work such as hotfixes. It gives important builds a guaranteed lane without needing a complex priority scheme.

12How Throttling Works Internally

This chapter lifts the lid. Knowing how the queue asks questions explains many puzzling delays.

The queue is a loop of questions

Jenkins runs a scheduling routine again and again, many times a minute. Each time, it looks at every waiting build and asks whether it is allowed to start. It asks several parties. The scheduler checks whether an executor with a matching label is free. Then plugins that add rules, including the throttle plugin and the lock plugin, are consulted. Each rule can answer “yes, go ahead” or “no, wait, because of this reason”. Only if everyone agrees does the build begin. The reason from the first “no” is the one shown in the queue.

Everyday analogy

Before a plane takes off, the pilot checks with the tower, the ground crew, the fuel team, and the cabin crew. Any one of them can say “not yet”, and the plane waits. The pilot repeats the checks every few moments. The Jenkins scheduler does exactly this for every waiting build.

How counting works

The throttle plugin keeps track of which builds belong to each category, by looking at the builds that are currently running. When a queued build asks permission, the plugin counts the running builds in its category, on the whole system and on each node, and compares the counts with the limits. If a limit is reached, it says no. When a running build finishes, the count drops, and on the next round the waiting build may pass.

Job-level and step-level counting

A job-level throttle is checked when the build sits in the queue, before it starts. A step-level throttle is checked when the running pipeline reaches the wrapped block. The build has already started, but its progress pauses at that point until it may enter. This difference explains why step-level throttles appear as “waiting” inside a running build, while job-level throttles appear as waiting in the queue.

QuestionJob-level throttleStep-level throttle
When is it checked?Before the build leaves the queueWhen the pipeline reaches the wrapped block
Where does the build wait?In the build queueInside the running build
Does the waiting build use an executor?NoDepends on placement, and it should not if the throttle wraps the agent block
What is counted?Whole runsOnly the wrapped blocks

Where the state lives

Category definitions live in the system configuration on the controller. Counts are worked out from the builds that are running, so they are not stored as separate numbers that could drift. Rate limits use recorded start times of recent builds. This design means restarts do not usually corrupt counts, but a build that vanished unexpectedly, for example after an agent crash, may keep counting until Jenkins notices it is gone.

i
Note

The details here describe the general design of these tools. Implementations differ between versions and plugins, so treat this as a mental model and confirm exact behaviour on your own server with a small experiment.

13Choosing the Right Limits

A throttle set too loose does not protect. A throttle set too tight wastes time. Here is a simple way to choose numbers.

Start from the resource, not from the builds

Ask what the shared thing can handle. A database that runs three test suites in parallel without slowing down has a capacity of three. A service that allows sixty requests an hour, with each build making ten, supports six builds an hour. A licence server with five seats supports five users. The limit you set should be at or slightly below that capacity, never above it.

Then check the demand

A simple rule from queueing theory, known as Little’s law, says that the average number of builds in progress equals the arrival rate multiplied by the time each takes. If thirty builds arrive each hour, and each holds the throttled resource for six minutes, which is a tenth of an hour, the average number holding the resource is thirty times a tenth, which is three. If your limit is three, you are running at the edge, and waits will be long at busy times.

30
builds arrive per hour in the example
6 min
each build holds the throttled resource
3
builds hold the resource on average, so a limit of 3 has no spare room
Everyday analogy

A shop with three tills, and customers who each need six minutes at the till, and thirty customers an hour, has every till busy almost all the time. Any small rush creates a long queue. A fourth or fifth till would make the shop feel calm. A throttle limit with no spare capacity behaves the same way.

Three ways to reduce the queue

Option 1

Raise the capacity

Add a second database instance, or another licence, and raise the limit accordingly.

Option 2

Shorten the hold time

Throttle only the part that needs the resource, and speed up that part, so each build lets go sooner.

Option 3

Reduce the demand

Run the resource-heavy tests less often, for example only on the main branch or overnight, and use quick checks for other builds.

i
Tip

Aim for average use of about half to two-thirds of the limit. That leaves room for bursts, and keeps waiting times short. Averages near the limit lead to queues that grow quickly at any small surge.

14Performance, Scalability, and Reliability

Throttles trade speed for safety. This chapter explains what that trade costs, and how to keep the system dependable when limits are in place.

What a throttle costs

Every throttle turns some parallel work into waiting. If a category allows three builds and thirty arrive in an hour, each holding the resource for six minutes, the resource is busy all the time, and the wait for the next build depends on how many are already in line. The lower the limit compared with demand, the longer developers wait. The right comparison is not “is there a wait?” but “is the wait shorter than the failures and crashes it prevents?”.

SituationWithout a throttleWith a well-set throttle
Eight builds hit a database built for threeOverload, timeouts, five false failures, rerunsThree run, five wait a few minutes, all pass
A large merge triggers dozens of buildsAll agents busy, urgent fix waits behind themBursts absorbed, urgent work uses a reserved pool
Builds pull images from a public registryRate limits hit, builds fail at randomPulls go through a cache, and rarely reach the limit
A pipeline mistake creates a huge matrixHundreds of paid machines startCloud cap stops it at a known ceiling
Everyday analogy

A lift with a weight limit makes a few people wait for the next ride. That short wait is far better than an overloaded lift that breaks and traps everyone. A throttle is the lift’s weight limit.

Ways to keep the cost small

  • Throttle only what needs it. Wrap the exact stage that uses the shared resource, not the whole pipeline.
  • Shorten the hold time. Prepare data and build artifacts before entering the throttled block, and clean up after leaving it.
  • Increase the capacity behind the limit. Add another instance, and raise the limit with it.
  • Keep hot paths free. Quick unit tests and static checks should not depend on any throttled resource.
  • Reserve capacity for urgent work. Use a separate label or pool.
  • Use elastic capacity where safe. For stateless work, let cloud agents expand within a cap.

Scalability of the throttles themselves

The scheduling loop consults every rule for every waiting build. With hundreds of builds waiting on many categories, this bookkeeping grows. It is normally light, but a very large queue of long-waiting builds, or a pile of complicated rules, can add load to the controller. Keep the number of categories modest, the number of long-waiting builds low, and avoid using throttles as a substitute for adding capacity.

Reliability: when the count is wrong

SituationWhat happensProtection
A build hangs inside a throttled blockIt keeps counting, and others wait for its slotTimeouts on the throttled work
An agent crashes while running throttled buildsThe counts may stay high until Jenkins notices the builds are goneReliable agents, and a way to clear orphaned builds
The controller restartsCounts are rebuilt from running builds, and pipelines resumeTest restarts, and watch for odd counts afterwards
A category name is mistypedThe job is not throttled, or is throttled with the wrong groupAgreed names, and a review of Jenkinsfile changes
The limit is set higher than the true capacityThe protected resource still overloadsMeasure the real capacity, and set the limit at or below it
i
Tip

Add a timeout to every throttled block, set well above the normal run time. A build that hangs then fails clearly and frees its slot, instead of quietly reducing everyone’s capacity.

15Security, Abuse, and Cost Control

Throttles are safety tools for volume. They also help against misuse, though they are not security walls.

Volume as an attack

Not all overload is an accident. A user with the right to start builds can, deliberately or not, start thousands of them. A pull request from a stranger can add a huge matrix, or a loop that starts endless jobs. Even without theft of data, this can exhaust agents, fill the queue, run up the cloud bill, and stop the team from working. This is called a denial of service, and cost caps are one of the best defences.

Risk 1

Runaway pipelines

A bug or a malicious change creates endless builds. Caps on agents and on rate stop the damage from growing.

Risk 2

Untrusted pull requests

Outside contributions can trigger heavy work. Run them on a limited pool with tight caps, and do not give them shared resources.

Risk 3

Removing the throttle

A change to a Jenkinsfile can drop a category, so a protected resource is unprotected again. Review such changes carefully.

Risk 4

Category tampering

Anyone who can change system configuration can raise limits. Restrict that right to administrators.

Risk 5

Cost blow-ups

Cloud agents without a cap turn a mistake into a large invoice. Set caps below budget and quota.

Risk 6

Waiting as denial

A build that never releases a throttled slot can block others for hours. Timeouts prevent this.

Everyday analogy

A shared photocopier in an office has a daily page limit for each department. It is not there because anyone is dishonest. It stops a single job, or a single mistake, from using all the paper and leaving everyone else with nothing.

Habits that protect you

  • Set hard caps at the outer edge. Cloud and container caps below quotas and budget are your last line of defence.
  • Give untrusted builds their own small pool. Use labels and separate caps for outside contributions.
  • Restrict who can change throttles. Only administrators should define categories and limits.
  • Review pipeline changes. A change that touches throttles, matrices, or triggers deserves the same care as a change to production code.
  • Alert on cost and queue growth. A sudden rise is the first sign of a runaway.
  • Use timeouts. They limit how long any build can occupy a limited resource.
!
Watch out

A throttle limits volume, not permission. It does not stop a user from doing something they should not be allowed to do, only from doing too much of it at once. Keep real access control in permissions and credentials, and use throttles as an extra layer.

Caps turn a disaster into an inconvenience.

16Monitoring, Logging, and Troubleshooting

When builds wait too long, or a protected resource still overloads, here is how to find the reason calmly.

What Jenkins shows you

  • The build queue. Lists waiting builds with the reason each is waiting, and how long it has waited.
  • The executor status panel. Shows which executors are busy and what they are running.
  • Load statistics. A chart over time of total executors, busy executors, and queue length.
  • The console log. A build waiting inside a step-level throttle prints a message naming the category.
  • Metrics plugins. Export queue size, waiting time, and executor use to your normal dashboards, so you can alert on them.
  • Cloud and cluster dashboards. Show agent counts, quotas, and spending.
flowchart TD
  A["Builds wait longer than expected"] --> B{"Does the queue reason mention a throttle or category"}
  B -->|Yes| C{"Is the count of running builds in the category correct"}
  C -->|No| D["Look for stuck or orphaned builds and clear them"]
  C -->|Yes| E["The limit is working so raise it or add capacity"]
  B -->|No| F{"Are all executors busy"}
  F -->|Yes| G["Add capacity or shorten builds"]
  F -->|No| H["Check labels, locks, and disabled concurrent builds"]
    
Figure 4. A decision path for builds that wait longer than expected.

Common symptoms and causes

SymptomLikely causeWhat to do
Queue reason says blocked by a category, but nothing seems to runA hung or orphaned build still countsFind it, abort it, and add a timeout
The protected resource still overloadsThe limit is above the true capacity, or some jobs are not in the categoryMeasure capacity, and check every job that uses the resource
Some jobs are never throttledMistyped category name, or the job type does not support the optionCompare names and test with overlapping builds
Executors idle while builds waitA throttle, lock, or label mismatch is holding them backRead the queue reason for each waiting item
Executors busy but nothing progressesBuilds hold executors while waiting for a throttle inside an agent blockMove the throttle outside the agent block
Builds fail with outside rate errorsToo many calls to an external serviceUse a proxy cache, backoff, and a category for that service
Cloud bill jumpsMissing or high agent cap, or a runaway matrixSet caps, and review recent pipeline changes
Urgent builds wait behind routine onesNo reserved capacity or priorityCreate a small urgent pool with its own label

Numbers worth tracking over time

Track the average and worst waiting time in the queue, split by reason. Track how full each throttle category is over the day. Track how many builds needed retries because of outside limits. Track agent counts and cost. A weekly look at these charts shows whether your limits are too loose, too tight, or well placed.

17Choosing a Tool, Patterns, and Anti-patterns

Patterns are choices that keep throttles helpful. Anti-patterns are habits that turn limits into obstacles.

A simple way to choose

flowchart TD
  A["What are you protecting"] --> B{"A shared service or environment"}
  B -->|Yes| C{"Must builds run strictly one at a time"}
  C -->|Yes| D["Use a lock on the resource"]
  C -->|No| E["Use a throttle category with a maximum"]
  B -->|No| F{"Machine or cloud capacity"}
  F -->|Yes| G["Set executor counts and cloud caps"]
  F -->|No| H{"Too many builds per hour"}
  H -->|Yes| I["Use rate limiting or a longer quiet period"]
  H -->|No| J["Reconsider whether a throttle is needed"]
    
Figure 5. A quick decision path for choosing a throttling tool.

Patterns that help

Pattern

Throttle the bottleneck

Put the limit on the specific shared thing that overloads, not on the whole system.

Pattern

Narrow throttled blocks

Wrap only the stage that uses the resource, so everything else runs freely.

Pattern

Named after the resource

Categories are named for what they protect, with a description of the true capacity behind the number.

Pattern

Caps on dynamic agents

Cloud and container caps below quota and budget, always.

Pattern

Cache before you call

Proxy repositories in front of outside registries, so builds rarely reach the outside limits.

Pattern

An urgent lane

A small pool reserved for hotfixes, so important work never waits behind routine runs.

Anti-patterns to avoid

ANTI-PATTERN 01 Avoid
Context

A team applies a category to the whole pipeline, because it was the quickest way to protect the test database.

What goes wrong

Only three builds at a time may even compile or run unit tests. Developers wait an hour for feedback that never needed the database, and the team starts to resent the limit.

Better decision

Throttle only the integration test stage, and leave compilation and unit tests unthrottled.

ANTI-PATTERN 02 Avoid
Context

To reduce a long queue, an administrator doubles every limit without checking the capacity behind them.

What goes wrong

The protected database is overloaded again, tests fail at random, and the team loses trust in the results. The queue was long because demand was high, and only real capacity can fix that.

Better decision

Measure the true capacity, raise limits only when capacity rises, and reduce the demand by running heavy tests less often.

ANTI-PATTERN 03 Avoid
Context

A throttle is placed inside an agent block, with no timeout.

What goes wrong

Each waiting build holds an executor while doing nothing. One hung build inside the throttled block stalls the rest, and soon all executors are held by builds that are only waiting.

Better decision

Place the throttle around the agent block, so waiting builds do not hold executors, and add timeouts on the throttled work.

ANTI-PATTERN 04 Avoid
Context

Cloud agents are set up without any cap, “so builds never wait”.

What goes wrong

A pipeline change adds a large matrix, and hundreds of machines start. The team learns of it from a very large invoice.

Better decision

Set caps on total agents and on each template, below quotas and budget, with alerts as they approach.

18Advantages, Trade-offs, Best Practices, and Common Mistakes

A balanced view of throttling, and the habits that keep it working for you.

Advantages

  • Protects shared resources from overload.
  • Turns bursts into a steady flow.
  • Prevents blocks from outside services.
  • Caps cost and limits the damage from mistakes.
  • Makes results more reliable, with fewer random failures.
  • Central limits that administrators can adjust.

Disadvantages and trade-offs

  • Adds waiting, so feedback is slower for some builds.
  • Limits can be wrong, too loose or too tight.
  • Stuck builds can hold slots and block others.
  • Several tools with overlapping features cause confusion.
  • Names and behaviour depend on plugin versions.
  • Not a security control.

Best practices in one place

  1. Find the real bottleneck first. Throttle the shared thing that fails, not the whole system.
  2. Set limits from measured capacity, at or slightly below what the resource can handle.
  3. Keep throttled blocks small, and do preparation and cleanup outside them.
  4. Place throttles around the agent block, so waiting builds do not hold executors.
  5. Add timeouts to every throttled block.
  6. Name categories after the resource, and document the true capacity behind each number.
  7. Cap dynamic agents below cloud quotas and budget.
  8. Use proxies, caches, and backoff for outside systems.
  9. Reserve an urgent lane for hotfixes.
  10. Watch queue waiting times and category fullness, and review limits regularly.
  11. Test with overlapping builds before trusting a new throttle.

The mistakes seen most often

Mistake 1: throttling too much

A whole pipeline is throttled to protect one stage, and developers wait for no reason. The fix is to wrap only the stage that needs it.

Mistake 2: limit above capacity

A category allows ten builds, but the database handles three. Nothing is protected. The fix is to measure and set the limit at capacity.

Mistake 3: the missing job

Nine of ten jobs that use a resource are in the category, and the tenth is not, so it can still overload the resource. The fix is a list of every job that touches the resource, kept up to date.

Mistake 4: no cap on cloud agents

A runaway matrix starts hundreds of machines. The fix is caps and cost alerts.

Mistake 5: hammering an outside service

Fifty builds retry every few seconds when a service is busy, and keep it jammed. The fix is caching, a category for that service, and growing waits.

19Worked Scenario: Protecting a Shared Test Database

Let us follow one imaginary team as it tames an overloaded test database, and learns why the first fix is rarely the last one.

The starting point

A team of twenty developers shares one integration test database. It can serve three test runs at once without slowing down. About thirty builds arrive each hour. A whole pipeline takes about fifteen minutes, and its integration test stage, which is the only part that touches the database, takes about six. On busy afternoons, eight pipelines reach the integration stage together. The database is overloaded, queries time out, and about a third of the runs fail for reasons unrelated to their code. Developers rerun builds, which adds more load.

1

Name the bottleneck and its capacity

The team agrees that the shared thing is “the integration database” and that its true capacity is three parallel runs. They create a throttle category with that name, a maximum of three in total, and a description that records why.

2

First attempt: throttle the whole job

They apply the category to the entire pipeline. The overload stops, but a new problem appears. Each build now holds a slot for fifteen minutes, so thirty builds an hour need an average of 7.5 slots, and only three exist. The queue grows all afternoon.

3

Narrow the throttle to the stage

They wrap only the integration test stage, placed around its agent block. Now each build holds a slot for six minutes. Average demand is thirty builds times a tenth of an hour, which is three. That exactly equals the limit, so any small burst still makes a queue.

4

Add real capacity

The team builds a second database instance, and raises the category limit to six. Average use is now three of six, about half, which leaves room for bursts.

5

Add safety nets

A timeout of twenty minutes goes around the throttled stage, so a hung run cannot hold a slot. Cloud agents get a cap, and an alert warns when the queue is long for more than ten minutes.

6

Review and adjust

After a month, the team reviews the load chart and the queue waiting times, keeps the limit of six, and notes that if builds per hour double, it is time to add a third database.

VersionAverage slots neededLimitOutcome
No throttle3, but bursts of 8NoneOverload, about a third of runs fail for unrelated reasons
Whole job throttled7.53No overload, but the queue grows all day
Only the integration stage throttled33Stable, but no spare room for bursts
Stage throttled, with a second database36About half used, short waits, results reliable
Everyday analogy

It is like a shop with a small fitting room. First, the owner lets only three people into the whole shop, and the street outside fills up. Then she limits only the fitting room, and the shop floor flows again. Finally she adds a second fitting room. Each step is the right fix for the problem that the previous step revealed.

i
Tip

The numbers here are made up to show the pattern. Do the arithmetic for your own system: builds per hour, minutes holding the resource, and true capacity. It takes five minutes and prevents a month of guesswork.

20Real-World Usage Patterns

Here is how throttling tends to appear in real Jenkins installations. These are illustrative patterns in general terms, not claims about the private setups of any particular company.

Jenkins is one of the most widely used automation servers, and teams of every size meet the same limits: shared environments, outside rate limits, and cloud bills. What tends to be common is a habit of throttling the real bottleneck, capping dynamic capacity, and watching the queue. The patterns below show that habit in practice.

Pattern: a shared test database

A product team caps the number of builds that use its integration database, throttling only the integration stage and adding a second instance as demand grows.

Pattern: a licensed tool with a few seats

A team with a limited number of licences for a commercial tool creates a category for the tool, with the limit equal to the number of seats, so builds never exceed what the company owns.

Pattern: a Kubernetes cluster shared with production

A platform team caps the number of build pods and sets memory and processor limits on each, so that a burst of builds can never squeeze out the cluster’s other workloads.

Pattern: staying inside outside limits

A company pulls all base images through its own repository cache, and uses a rate strategy in its source-control plugin, so its builds rarely meet the hourly limits of outside services.

Pattern: the nightly heavy lane

A team runs slow performance tests only on a nightly schedule, with a build rate limit, so that daytime builds stay quick and the shared test environment is never crowded.

i
Note

Jenkins is often used together with Docker, Kubernetes, and cloud platforms, which have quotas and limits of their own. The most reliable setups keep Jenkins limits below the limits of everything it touches, so Jenkins slows itself down before another system has to do it.

21Frequently Asked Questions

Q1What is throttling in Jenkins in one sentence?
It is the set of tools that limit how many builds run at once, how often they start, and how much of a shared resource they may use, so that bursts of work do not overload machines, services, or budgets.
Q2Is there one setting called throttling?
No. It is a family of tools: executor counts, throttle categories from a plugin, locks, build rate limits, quiet periods, and caps on cloud and container agents. Choose by the kind of limit you need.
Q3What is a throttle category?
A named group with a limit on how many builds in the group may run at once, across the whole Jenkins and optionally per agent. Jobs, or parts of jobs, join the category by name.
Q4Should I throttle the whole job or just one stage?
Prefer just the stage that uses the shared resource, wrapped around its agent block. A whole-job throttle holds back work that never needed the limit, and makes feedback slower for no benefit.
Q5What is the difference between a throttle category and a lock?
A lock gives one build exclusive use of a named resource. A category caps how many builds may use a pool at once, when the resource can serve several. Use locks for single items, and categories for counted capacity.
Q6Why do my builds wait even though executors are idle?
Something other than executor capacity is holding them: a throttle category that is full, a lock, a label mismatch, or a disabled concurrent builds option. The queue shows the reason for each waiting build.
Q7How do I choose the limit number?
Start from the true capacity of the shared resource, and set the limit at or a little below it. Then use the arrival rate and the time each build holds the resource to check that average use is well below the limit.
Q8How do I stop a runaway pipeline from costing a fortune?
Set caps on the total number of dynamic agents and on each agent template, below your cloud quotas and budget. Add cost alerts and review pipeline changes that touch matrices or triggers.
Q9How can I avoid outside rate limits?
Pull images and packages through your own proxy cache, use the rate strategy options of source-control plugins, keep polling to a minimum in favour of webhooks, and retry with growing waits instead of hammering the service.
Q10What happens if a build hangs inside a throttled block?
It keeps counting against the category, so others wait for its slot. Put a timeout around every throttled block so hung builds fail and free their place.
Q11Can I give urgent builds priority?
Yes. Plugins can assign priorities, but a simpler approach is to reserve a small pool of executors with its own label for hotfixes. Watch the waiting time of low-priority work so it does not starve.
Q12Is throttling a security feature?
Not by itself. It limits volume, which helps against runaway and abusive workloads, but it does not decide who may do what. Keep access control in permissions and credentials, and use throttles as an extra layer.

22Summary and Key Takeaways

Key Takeaways

  • Throttling means limiting on purpose. It caps how many builds run at once, how often they start, and how much of a machine or service they may take, so shared resources stay healthy.
  • Pick the tool by the kind of limit. Executors and cloud caps limit machine capacity, throttle categories limit a shared pool, locks limit single items, and rate options limit starts over time.
  • Throttle the bottleneck, narrowly. Wrap only the stage that uses the shared resource, around its agent block, so waiting builds do not hold executors.
  • Set limits from real capacity. Use the resource’s true capacity and Little’s law to check demand, and aim for average use of about half to two-thirds of the limit.
  • Respect outside limits. Use proxy caches, rate strategies, and retries with growing waits, so your builds are not blocked by other people’s limits.
  • Cap cost and volume. Set hard caps on dynamic agents below quota and budget, add timeouts to throttled blocks, and give untrusted builds their own small pool.
  • Watch and adjust. Track queue waiting times and category fullness, read the queue reason when builds wait, and test every new throttle with overlapping builds.