Serve tenants in turn, or a small one waits 20 minutes
Ten replicas are free for batch. A sends 100,000 requests at 9:00, and B sends 100 at 9:05.
| Queueing | A | B |
|---|---|---|
| one FIFO queue | runs to about 9:25 | waits until A is done, then starts |
| a sub-queue per tenant, served in turn | done about 1.5 s later than alone | done about 13 s after 9:05 |
First come, first served sounds fair. Run the numbers.
Tenant A submits 100,000 requests at 9:00, 15,000 replica-seconds of work. Ten replicas have room for batch, so A takes 15,000 ÷ 10 = 1,500 seconds, 25 minutes.
Tenant B submits 100 requests at 9:05. Under one FIFO queue, first in, first out, B waits until A drains at 9:25. That's 20 minutes of waiting for 100 × 0.15 = 15 replica-seconds of work.
Now give each tenant a sub-queue, and serve them in turn.
Assume each replica decodes 128 sequences at once. Then each sequence gets 4,000 ÷ 128 = 31 tokens a second, and a 400-token answer takes 400 ÷ 31, about 13 seconds.
B's requests start within a step or two and finish about 13 seconds later. A finishes 15 ÷ 10 = 1.5 seconds later than it would have.
Fairness costs the big tenant almost nothing and saves the small one 20 minutes. Amazon's Builders' Library makes the general point: in some ways, a single queue and many tenants are at odds.
In the editor, write round_robin(queues). queues maps each tenant to its requests, in order. Serve one request from each tenant that has work, round after round, until every queue is empty.