Performance Budgets in CI: p95 Thresholds That Hold

Performance Budgets In CI

A performance budget in continuous integration is an automated check that fails a build when a measured speed metric crosses a set limit. The most common metric for services is p95 latency: the response time that 95% of requests beat and 5% exceed. If a checkout endpoint has a p95 of 310 ms, one request in twenty takes longer than that.

Teams choose p95 over the average because averages hide slow outliers. A change that leaves the mean at 120 ms while pushing the slowest 5% from 310 ms to 900 ms hurts real users and never moves the average much.

In practice the gate is a few lines of configuration. In k6, a threshold such as p(95) below 400 on request duration makes the tool exit with a non-zero code, and the pipeline step fails. Lighthouse CI does the same for page metrics through assertions on Largest Contentful Paint or Total Blocking Time.

Writing the rule takes five minutes. Keeping it trustworthy is the work.

Why Thresholds Flake

The usual first attempt copies a number from a production dashboard into the pipeline. Production p95 reflects real traffic on tuned hardware. A CI job runs on a shared virtual machine with two to four cores, a cold cache, and neighbours competing for CPU. Run-to-run variation of 10% to 30% on hosted runners is ordinary, so a limit set 5% above yesterday’s reading fails at random.

Sample size is the second trap. A p95 computed from 100 requests rests on the five slowest. One garbage-collection pause among them shifts the result by tens of milliseconds. With 2,000 requests, 100 samples sit in the tail and the estimate settles down.

Third, many load tools understate tail latency through coordinated omission. A closed-loop generator waits for each response before sending the next request, so when the server stalls, the tool sends fewer requests and never records the queueing delay real users would feel. The result looks better than the truth, which, frankly, is the last thing a gate should do.

The gate also depends on its surroundings. The test needs a production-like build, a seeded database of realistic size, stubbed or stable third-party calls, and a load generator that does not share a CPU with the system under test. Results need somewhere to live between runs, such as a time-series store or a tracking service like Bencher, or there is no baseline to compare against.

Setting Limits That Hold

Measure The Noise First

Before choosing any limit, run the unchanged main branch 20 times on the CI runner and record p95 each time. Calculate the median and the standard deviation of those 20 values. Suppose the median is 310 ms and the standard deviation is 12 ms. That 12 ms is your noise floor. A gate cannot reliably detect a regression smaller than about two to three times that figure, here roughly 25 to 35 ms.

Derive The Limit From Data

Set the hard limit at the baseline median plus three standard deviations plus the regression you are willing to accept. With a 310 ms baseline, 12 ms deviation, and a tolerance of 15 ms, the limit lands near 360 ms. Expect a false failure rate well under 1% at that margin if noise is roughly normal. Add a softer warning at baseline plus two deviations that posts a comment on the pull request without blocking it. You measure the spread, add the tolerance, and the number defends itself in review.

Compare Against A Baseline Run

Absolute limits drift as runner hardware changes. A relative gate runs the base commit and the candidate commit in the same job, on the same machine, interleaved, and fails only if the candidate’s p95 is worse by more than a set percentage, commonly 5% to 10%. For small differences, apply a rank-based test such as Mann-Whitney U across repeated runs instead of comparing two single numbers. This doubles job time and removes most machine-to-machine variance.

Control The Test Conditions

Discard a warm-up period, typically the first 30 to 60 seconds, so just-in-time compilation and connection pools settle. Drive load at a fixed arrival rate, using k6’s constant-arrival-rate executor or wrk2, to avoid coordinated omission. Aim for at least 1,000 requests per gated endpoint. Pin the job to a dedicated or self-hosted runner where budget permits. Where it does not, tools such as CodSpeed count CPU instructions under simulation instead of timing wall-clock, trading realism for repeatability.

Two Pipeline Examples

An API team. A six-engineer team gates its order-search endpoint with a k6 test: 90 seconds at 40 requests per second after a 30-second warm-up, about 3,600 measured requests. The first limit, 300 ms copied from production, fails one build in four. They run the 20-build baseline and find a median p95 of 340 ms on their runner with a deviation of 18 ms. The new hard limit is 410 ms, with a warning at 376 ms. Over the following month the gate fails twice. One failure traces to a missing database index in a migration. The other was a noisy runner, cleared by an automatic single retry. Not perfect. Trusted.

A frontend team. A marketing site uses Lighthouse CI with a budget of 2.5 seconds for Largest Contentful Paint under simulated mobile throttling. Single runs swing by 400 ms. The team switches to five runs per URL and asserts on the median, a setting Lighthouse CI supports directly, and adds a JavaScript bundle size budget of 180 KB compressed as a second gate. Bundle size is deterministic, so it catches most regressions before the timing check has anything to say. The timing budget stays as a warning for two weeks, then becomes blocking once its false alarm rate is known.

Gate Types Compared

Gate TypeHow It DecidesStrengthWeakness
Absolute p95 limitFails above a fixed value, such as 360 msSimple to read and explainBreaks when runner hardware changes; needs periodic recalibration
Relative to base commitFails if candidate is 5% to 10% slower in the same jobCancels most machine varianceDoubles run time; slow drift across many small changes slips through
Statistical testRank test across repeated runs of both versionsDetects smaller regressions with a known error rateNeeds 10 or more runs per side; harder to explain
Deterministic proxyBundle size, query count, or instruction countNo timing noise at allMeasures a cause, not the latency users feel
Trend alertFlags a shift in the rolling median over recent buildsCatches gradual creepReports after merge, so it cannot block

Most durable setups combine two rows: a deterministic proxy or relative gate that blocks merges, and a trend alert that watches for drift.

Common Mistakes

Gating on p99 with a short test. At 1,000 requests the 99th percentile rests on ten samples. Use p95 for the gate and record p99 for information until test length supports it.

Retrying until green. One automatic retry to filter runner noise is reasonable. Three retries turn a 30% failure chance into a 3% one and hide real regressions the same way.

Raising the limit after every failure. If the number moves each time someone complains, it stops being a budget. Change it only with a new baseline measurement attached to the pull request.

Testing against an empty database. A query that returns in 4 ms on 50 rows may take 400 ms on five million. Seed data at a realistic scale, and it rarely takes as long to set up as teams fear.

Running the load generator on the same two-core runner as the service. The tool and the target then compete for CPU, and the measurement reflects that contest instead of the code.

FAQ

What is a good p95 latency threshold?

There is no universal figure. Derive it from your own baseline: median p95 on the CI runner plus three standard deviations plus the regression you accept. For web pages, Google’s Core Web Vitals use 2.5 seconds for Largest Contentful Paint as a reference point.

Why use p95 instead of average response time?

The average can stay flat while the slowest requests get much worse. p95 tracks the experience of the unluckiest one in twenty users and is stable enough to measure in a short test.

How many requests do I need for a stable p95?

At least 1,000 per endpoint, which puts 50 samples in the tail. Several thousand is better. Below a few hundred, the figure swings too much to gate on.

How do I stop performance tests from being flaky in CI?

Measure run-to-run noise, set limits outside it, add a warm-up, use fixed arrival rates, compare against the base commit in the same job, and prefer dedicated runners.

Should a performance budget block merges or only warn?

Start with warnings for two to four weeks to learn the false alarm rate. Promote to blocking once failures are rare and each one has a traceable cause.

Author’s Insight

Across tool documentation and published engineering write-ups, failed performance gates share one pattern: the limit was chosen before the noise was measured. The statistics involved are modest, a median, a standard deviation, a minimum sample count, yet skipping them turns the gate into a coin toss that developers learn to ignore. Deterministic proxies such as bundle size and query counts deserve more use than they get, because they block cleanly and leave timing checks to confirm instead of decide. A budget’s worth shows in how rarely it is overridden, and that depends more on calibration than on the tool chosen.

Key Takeaways

  • A CI performance budget fails the build when a metric such as p95 latency crosses a limit.
  • Production numbers do not transfer to shared runners, where 10% to 30% variation is normal.
  • Run the baseline 20 times, then set the limit at median plus three standard deviations plus accepted regression.
  • Collect at least 1,000 requests per endpoint, discard warm-up, and drive load at a fixed arrival rate.
  • Relative comparison against the base commit removes most hardware variance at the cost of longer jobs.
  • Pair a blocking gate with a trend alert, begin in warning mode, and change limits only with fresh measurements.

Related Articles

Performance Budgets in CI: p95 Thresholds That Hold

A performance budget is a speed limit written into the build pipeline: if a code change makes the slowest ordinary requests slower than an agreed figure, the merge is blocked. Teams adopt these gates and then switch them off within weeks because they fail at random. This guide is for backend and frontend engineers, tech leads, and anyone who maintains a delivery pipeline and wants latency checks that people trust. It explains what the 95th percentile measures, why shared build machines distort it, how many samples a stable reading needs, how to derive a limit from measured noise, and which gate designs suit which kind of test.

development

dailytapestry_com.pages.index.article.read_more

Token Cost per Merged PR: Budgeting AI Assistants

Engineering teams paying for AI coding assistants by the token need a unit that ties spend to shipped work, and cost per merged pull request is the one finance and engineering can both read. This guide is for engineering managers, tech leads, and founders who approve tooling budgets or have just received a surprising usage invoice. It explains how input, output, and cached tokens add up across an agent session, why abandoned attempts belong in the figure, how to collect the data from usage exports and repository history, what model choice does to the bill at current list prices, and which shortcuts make the number misleading

development

dailytapestry_com.pages.index.article.read_more

Cybersecurity Basics for Developers

Modern software development moves at a breakneck pace, but speed often compromises the integrity of the codebase. This guide provides developers with a high-level technical roadmap for integrating security into the CI/CD pipeline, moving beyond basic "don't leak keys" advice to architectural resilience. By implementing specific shifts in authentication, input handling, and dependency management, engineers can mitigate 80% of common vulnerabilities before a single line of code reaches production.

development

dailytapestry_com.pages.index.article.read_more

Performance Monitoring Tools for Modern Applications

Modern application performance monitoring (APM) has evolved from simple server pings to complex observability across distributed microservices and hybrid cloud environments. This guide provides CTOs and DevOps engineers with a deep dive into selecting and implementing monitoring stacks that reduce Mean Time to Resolution (MTMR) and prevent revenue-leaking downtime. We address the transition from reactive alerting to proactive telemetry, ensuring your infrastructure supports high-scale traffic without degrading user experience.

development

dailytapestry_com.pages.index.article.read_more

Latest Articles

AI-Generated Code and the EU Product Liability Directive

Europe’s rewritten product liability law treats software as a product and holds its maker answerable for harm without any need to show carelessness. It applies to anything released after 9 December 2026, and it draws no line between functions typed by an engineer and functions produced by a coding assistant. This guide is for founders, engineering leads, and product managers shipping apps, firmware, or connected devices to European users, and for consumers curious about their rights. It explains who counts as the manufacturer, which harms qualify, how courts can presume a defect, what records help a defence, and where vendor contracts stop protecting you

development

Read »

Agentic Coding Guardrails: Sandboxing And Secrets

Agentic coding systems can write and run code, so mistakes become security incidents fast. This guide explains how sandboxing and secrets handling work in practice, where failures happen, and how to test guardrails using concrete checks. Readers will learn threat models for code execution, safe patterns for environment variables and secret stores, and how to evaluate logs, permissions, and data exfiltration risks without relying on hype.

development

Read »

Token Cost per Merged PR: Budgeting AI Assistants

Engineering teams paying for AI coding assistants by the token need a unit that ties spend to shipped work, and cost per merged pull request is the one finance and engineering can both read. This guide is for engineering managers, tech leads, and founders who approve tooling budgets or have just received a surprising usage invoice. It explains how input, output, and cached tokens add up across an agent session, why abandoned attempts belong in the figure, how to collect the data from usage exports and repository history, what model choice does to the bill at current list prices, and which shortcuts make the number misleading

development

Read »

Database Indexing: Finding the 99th-Percentile Bottleneck

Database indexing affects query latency, CPU use, and tail performance. This article explains how to locate the 99th-percentile bottleneck using query plans, index design, and workload measurements. It helps readers who manage apps, analytics, or data platforms understand why “fast average” can hide slow outliers. You’ll learn practical steps to diagnose index-related tail latency, compare options, avoid common mistakes, and interpret results safely.

development

Read »

Software Supply Chains: SBOM Requirements in 2026

SBOMs (software bill of materials) list what software components a product uses, down to versions and licenses. This matters for healthcare-adjacent software, regulated vendors, and anyone buying or building connected systems. This article explains what SBOMs cover, what 2026 SBOM requirements typically target, and how to judge an SBOM’s quality. You’ll learn practical steps for procurement and engineering teams, common failure modes, and how to read an SBOM without getting misled.

development

Read »

Prompt Injection in CI/CD: OWASP LLM Top 10 Controls

Prompt injection in CI/CD is a supply-chain risk where malicious text in code, dependencies, or build logs steers an LLM to leak secrets or change pipeline behavior. This guide targets engineers and security reviewers who use LLMs for code review, test generation, or release notes. You will learn how prompt injection reaches CI/CD, how OWASP LLM Top 10 controls map to pipeline controls, and what to measure in practice to reduce exposure.

development

Read »