Somewhere between increasing concurrency and watching latency get worse, I was reminded that CPUs don’t particularly care about my optimism.
There’s a special kind of confidence that comes from looking at a slow workload and thinking:
“What if we just run more of them in parallel?”
It sounds reasonable.
Modern processors have multiple cores. Application runtimes support concurrency. Operating systems have schedulers.
Surely if one request takes a certain amount of time, running several requests concurrently should increase throughput.
And sometimes it does.
But sometimes you increase concurrency, throughput barely moves, and latency starts climbing like it has somewhere important to be.
Congratulations.
You’ve discovered saturation.
I’ve spent time experimenting with CPU-bound AI inference workloads, and one lesson has stuck with me:
Concurrency is not a performance optimization by itself. It’s a way of utilizing available capacity.
Once you’ve exhausted that capacity, adding more concurrent work doesn’t magically create additional processing power.
It creates contention.
And for latency-sensitive systems, contention is where things get interesting.
This isn’t about a particular AI model, product, or deployment.
It’s about performance engineering principles that become especially obvious when the expensive part of a request involves CPU-bound computation.
1. Latency and throughput are not the same thing
Before discussing concurrency, there’s a distinction worth making.
Latency is how long an individual operation takes to complete.
Throughput is how many operations a system completes over a period of time.
They are related.
They are not interchangeable.
Suppose a system processes requests using a computationally expensive operation.
If you run one request at a time, your throughput may be limited because some resources remain underutilized.
Introducing concurrency can help.
Multiple requests can make progress simultaneously, using more of the available processing capacity.
Initially, this can be a win.
More completed requests per second, without a proportionate increase in response time.
Then you reach the point where your CPUs are already doing as much useful work as they can.
Adding more concurrent requests doesn’t increase physical compute capacity.
Instead, requests compete for CPU time, caches, memory bandwidth, and other shared resources.
Throughput begins to flatten.
Latency continues to rise.
And if you keep pushing, you may end up with a system that is technically processing many requests concurrently but completing each one much more slowly.
A busy system is not necessarily an efficient system.
This is particularly relevant to AI inference because the expensive work may involve matrix operations, token processing, or other computations that are already internally parallelized.
Which leads to a subtle problem.
Your application isn’t always the only thing trying to use multiple CPU cores.
2. Your model runtime might already be parallel
One of the first things worth understanding when benchmarking inference is how the underlying runtime executes work.
Depending on the model, runtime, and execution provider, inference may already use multiple CPU threads.
For example, a runtime might parallelize parts of an operation across several cores.
Now imagine your application accepts multiple concurrent inference requests.
Each request can invoke a runtime that also tries to use multiple threads.
You now have two separate levels of parallelism:
- Application-level concurrency.
- Runtime-level parallel execution.
Neither is inherently bad.
But failing to account for their interaction is a great way to make a benchmark behave strangely.
Consider a purely illustrative system with a limited number of CPU cores.
One inference request may already utilize a substantial fraction of the machine.
Launching several additional requests concurrently doesn’t guarantee that the machine can execute all their computational work efficiently.
You may introduce thread contention, additional context switching, and pressure on shared CPU caches.
The result can be lower efficiency and longer request durations.
The important question isn’t simply:
“How many requests can I run concurrently?”
It’s:
“How much parallel work does each request already create, and how does that interact with the machine’s available capacity?”
This distinction matters well beyond AI.
Database query engines, compression libraries, image-processing workloads, and numerical computing frameworks can exhibit similar behavior.
If a library is already parallelizing expensive work internally, blindly adding application concurrency may be counterproductive.
3. The concurrency curve has a limit
One of the most useful ways to reason about performance is to imagine increasing concurrency gradually.
At low concurrency, the system may have spare processing capacity.
Increasing the number of active requests improves utilization.
Throughput rises.
As utilization approaches the machine’s effective capacity, throughput grows more slowly.
Eventually, it can approach a plateau.
At that point, increasing concurrency mostly increases the amount of work waiting to be completed.
This is where latency can become unpleasant.
A useful relationship here is Little’s Law:
[ L = \lambda W ]
Where:
- (L) is the average number of requests in the system.
- (\lambda) is the average throughput.
- (W) is the average time a request spends in the system.
For a stable system over an appropriate observation period, these quantities are related.
Now consider what happens as throughput approaches a practical limit.
If the number of in-flight requests keeps increasing while throughput barely changes, average time in the system has to increase.
Those additional requests don’t disappear.
They wait, execute slowly, or eventually time out.
And that’s the part many concurrency benchmarks make painfully obvious.
Increasing the number of active requests is easy. Increasing the amount of useful work completed per second is considerably harder.
4. Why average latency can be misleading
Another performance-engineering lesson is that averages don’t tell the whole story.
Imagine two systems with the same average response time.
One might serve most requests at roughly the same speed.
Another might serve many requests quickly while a smaller number experience significant delays.
For an interactive or latency-sensitive workload, those systems don’t necessarily provide the same experience.
That’s why I prefer looking at latency distributions.
Common measurements include:
- p50: The median request latency.
- p95: The latency at or below which 95% of measured requests fall.
- p99: The corresponding 99th-percentile latency.
These measurements can reveal how a workload behaves as contention increases.
A system might maintain a fairly stable median while tail latency deteriorates.
Or it might show a noticeable shift across the entire distribution.
Either way, reporting only an average can hide operationally significant behavior.
One important detail: percentile measurements need enough samples and a clearly defined measurement window to be meaningful.
And when comparing benchmarks, the request distribution and workload must be consistent.
Otherwise, you’re comparing different problems and pretending they’re the same experiment.
Which is surprisingly easy to do.
5. CPU utilization is a clue, not a conclusion
When a workload gets slower, checking CPU utilization is a sensible first step.
But seeing high CPU utilization doesn’t automatically tell you why performance is poor.
High utilization might indicate that the processor is performing useful work close to capacity.
It could also coexist with inefficient scheduling, contention, or execution overhead.
Similarly, low CPU utilization doesn’t automatically prove there is plenty of usable compute capacity.
The workload might be blocked by memory access, synchronization, I/O, or another constraint.
So I wouldn’t use CPU percentage as the sole performance metric.
I’d combine it with request throughput, latency distribution, thread configuration, memory behavior, and profiling data.
The objective is to understand where execution time is actually going.
Not to collect enough green dashboards to feel reassured.
This is also why benchmarks should distinguish between elapsed time and CPU time where possible.
A request can spend a long time waiting to execute even when its actual computation hasn’t become more expensive.
That difference matters when you’re deciding whether the solution is reducing computation, managing contention, or controlling the number of simultaneous requests.
6. Sometimes the answer is less concurrency
This is the part that feels counterintuitive.
When a system gets slower under load, the instinct is often to allow more requests through.
More workers.
More threads.
Bigger pools.
Higher concurrency limits.
But if the workload is CPU-bound and already operating near capacity, increasing those limits can make tail latency worse without delivering meaningful throughput gains.
In those circumstances, bounded concurrency can be a more useful design tool.
Rather than allowing an unlimited number of expensive operations to execute simultaneously, the system permits only a controlled number.
Additional requests may wait in a bounded queue, receive backpressure, or be rejected when capacity is exhausted.
Each option has a tradeoff.
Queuing can smooth short bursts, but it introduces waiting time.
Rejecting overload can preserve the responsiveness of accepted requests, but callers must handle that behavior.
Backpressure can prevent downstream saturation, but it requires deliberate propagation through the application.
The right choice depends on the service contract.
What matters is that overload behavior should be designed intentionally.
Because if you don’t define a concurrency limit, the system will eventually discover a limit for you.
Usually in a much less convenient way.
7. Benchmarking without lying to yourself
A benchmark is useful only if the experiment actually measures what you think it measures.
For CPU-bound inference, I would approach benchmarking in stages.
Establish a baseline
Start with a controlled, low-concurrency workload.
Measure request latency, throughput, and resource utilization.
Keep the input characteristics consistent.
Ensure model initialization, warm-up behavior, and other one-time costs are either measured separately or explicitly included.
Increase load gradually
Rather than jumping directly to a very high concurrency value, increase load in controlled steps.
Record throughput and latency distribution at each step.
Look for the point where adding concurrency stops producing meaningful throughput improvements.
Control the environment
CPU frequency scaling, background processes, container CPU limits, memory pressure, and runtime thread settings can influence results.
A benchmark from an otherwise idle development machine isn’t automatically representative of a containerized deployment.
And a result from one hardware configuration should not be casually generalized to every other machine.
Separate measurement from explanation
If p99 latency increases at a particular concurrency level, that’s an observation.
CPU contention might explain it.
But the explanation should be supported by profiling or additional measurements.
Otherwise, it’s a hypothesis.
I’ve learned to be particularly careful about this distinction.
Because it’s very easy to see two metrics move together and construct an extremely convincing story about why.
Computers are excellent at making your assumptions look plausible.
Until you measure something else.
Repeat the experiment
One successful run is not a performance characterization.
Repeat measurements, examine variance, and avoid presenting unusually favorable results as representative behavior.
The goal isn’t to win an argument with a benchmark.
It’s to understand the system well enough to make a defensible engineering decision.
8. Performance is a capacity-planning problem
Once you understand the relationship between request cost, concurrency, and available compute, the next question becomes architectural.
How much work can a single instance process while meeting its latency requirements?
What happens when demand exceeds that capacity?
Can requests be queued safely?
When should the system reject work?
And what would justify scaling horizontally instead of tuning the current instance?
These questions are familiar to anyone who’s worked with databases, web servers, or message-processing systems.
AI inference simply makes the computational cost harder to ignore.
The expensive operation can dominate request latency.
That means every additional millisecond of compute, queuing, or scheduling delay matters.
But scaling should follow measurement.
If an instance is CPU-saturated, adding replicas may increase aggregate capacity when requests can be distributed effectively.
If the bottleneck is somewhere else, adding compute might provide very little benefit.
And if the system has inefficient internal threading, multiplying that inefficiency across more instances can become an expensive mistake.
Capacity planning starts with understanding the unit cost of useful work.
Not with selecting a larger instance because the dashboard looks uncomfortable.
9. What I’d do differently before optimizing
If I were approaching a new CPU-intensive service today, I’d establish a few things before attempting performance improvements.
First, define the latency objective.
A latency-sensitive service needs a measurable response-time requirement, ideally including tail latency and expected load.
Second, characterize the cost of one operation.
Understand what a single request does before layering concurrency on top of it.
Third, inspect internal parallelism.
Know whether the runtime is already using multiple threads or parallel kernels.
Fourth, find the saturation point.
Measure the throughput-versus-concurrency relationship rather than assuming more workers always mean more capacity.
Fifth, make overload behavior explicit.
A system should have a plan for demand exceeding available compute.
Finally, optimize the actual bottleneck.
Sometimes that means reducing computational work.
Sometimes it means tuning runtime execution.
Sometimes it means improving memory behavior.
And sometimes it means accepting that the machine has reached its practical limit and scaling accordingly.
The point is to make those decisions based on evidence.
Closing thoughts
What I find interesting about CPU-bound inference workloads is how quickly they expose assumptions that are easy to overlook in other systems.
Concurrency feels like capacity.
CPU utilization feels like productivity.
A faster individual operation feels like guaranteed throughput improvement.
And a successful benchmark feels like proof that production will behave exactly the same way.
None of those assumptions is automatically true.
The performance of a system depends on how work interacts with finite resources.
At low load, inefficient concurrency settings can appear harmless.
As utilization increases, those decisions become much more visible.
And once the system approaches saturation, adding more work can make everything slower.
The goal of performance engineering isn’t to make the machine work harder. It’s to make the machine complete more useful work within the required latency budget.
Sometimes that means more concurrency.
Sometimes it means better algorithms, better scheduling, or more compute.
And sometimes the most effective optimization is telling your application to do fewer things at once.
Which is a rather humbling conclusion after spending an afternoon increasing worker counts.
I write about performance engineering, reliability, databases, Kubernetes, and the infrastructure decisions that become interesting under load.
More engineering notes at advaitkeskar.tech.