Skip to content
Athrael.net logoAthrael.net

Introduction to GPU InferenceChapter 1: Foundations

Serving multiple requests

Lesson 2 of 4 · about 6 min

What this lesson covers

Previously we looked at how a GPU answers a single prompt. A real server handles many prompts at once, and each one is called a request. This lesson explains how one GPU serves several requests together and how that affects the speed of each.

Batching

The simplest way to serve several requests is one at a time, where the GPU generates the first reply in full, then the second, and so on.

Each request gets the GPU’s full speed while its reply is generated, but the last one waits for every reply ahead of it, so its delay grows with the queue.

Serving requests one at a time and as a batch
One GPUClock
GPU cores in use
Request 1
Request 2
Request 3
Request 4
Each square beside a request is one token of its reply. The times and the share of cores in use are illustrative.

One request usually uses only part of a GPU’s capacity. A server uses the rest by computing the next token for several waiting requests in the same step, and the requests it processes together are called a batch.

A step for four requests takes slightly longer than one for a single request, since there is more to compute, but it advances all four replies. In the diagram the first request finishes slightly later than it did when served alone, and the other three finish much sooner.

Adding more requests

Each request in a batch gets fewer tokens per second than it would with the GPU to itself, and the figure drops as the batch grows. The GPU’s total output across all requests, known as throughput, rises at the same time.

Batch size and throughput
One GPU
Each request's speed
Total output (throughput)
Total output at every batch size
1 request16 requests
The numbers are illustrative, and real servers show a similar shape.

Throughput stops rising once the GPU is fully used, because the same output is then divided among more requests and every reply slows down.

Continuous batching

A server sets how many requests a GPU processes at once, and each one occupies a slot. Replies differ in length, so a server that started a new batch only when the previous one had finished would leave slots empty until the longest reply finished, while new requests waited.

Continuous batching avoids this by giving a free slot to the next waiting request as soon as any reply finishes.

Continuous batching
Waiting
Slot 1
Slot 2
Slot 3
Each numbered column is one step and each letter is a reply, while a hatched square is an empty slot.

The time a request spends waiting for a slot is part of its time to first token, and it grows when more requests arrive than the GPU has slots for.

The number of slots depends mostly on the GPU’s memory, because every reply in progress needs room for its text so far, as a later lesson explains.

Recap

A GPU that serves requests one at a time makes each wait for those ahead of it, so a server computes the next token for several requests in one step, which is called a batch. A bigger batch raises throughput and slows each request slightly, until the GPU is fully used and throughput stops rising. With continuous batching, a waiting request takes a slot as soon as one becomes free.

An assistant can feel slower at busy times because more requests share each GPU, so tokens arrive more slowly and requests wait longer for a slot.