> For the complete documentation index, see [llms.txt](https://seekspeed.gitbook.io/seekspeed-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://seekspeed.gitbook.io/seekspeed-docs/benchmarking/concurrency.md).

# Concurrency Sweeps

Single-request benchmarks tell you the best case. Production tells you the worst case. The gap between the two is where SLAs die.

A concurrency sweep runs the same prompt set at `concurrency ∈ {1, 4, 16, 32}` (configurable) and plots:

* Mean total latency vs concurrency
* p95 latency vs concurrency
* Effective throughput (completed\_tokens / wall\_clock) vs concurrency
* Error rate vs concurrency

The shape of the p95 curve tells you the breaking point. A healthy endpoint stays flat until a knee, then climbs sharply. A misconfigured one starts climbing at concurrency 2.

## What to do with the result

| Curve shape                          | Likely cause                                | Action                                                          |
| ------------------------------------ | ------------------------------------------- | --------------------------------------------------------------- |
| Flat through 32                      | Endpoint over-provisioned for your workload | Reduce replicas, save cost.                                     |
| Knee at 4-8                          | Batch size or KV-cache limit reached        | Tune `--max-num-seqs` (vLLM) or replicas.                       |
| Linear climb from 1                  | No batching at all                          | Check that requests are being scheduled in the same batch step. |
| Error rate spike before latency knee | Backpressure / 429                          | Add a retry policy with jitter; the engine generates this rule. |

## Limiting in-flight requests

The runner uses a small async semaphore to keep concurrency at the exact configured value rather than blasting all requests at once:

```ts
class Semaphore {
  private q: (() => void)[] = [];
  constructor(private n: number) {}
  async acquire(): Promise<void> {
    if (this.n > 0) { this.n--; return; }
    return new Promise(r => this.q.push(() => { this.n--; r(); }));
  }
  release() {
    this.n++;
    const next = this.q.shift();
    if (next) next();
  }
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://seekspeed.gitbook.io/seekspeed-docs/benchmarking/concurrency.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
