6/30
Part 1 of 7 · Two clocksLearn and do
Report each clock as percentiles
This is a simulated day of 1,000 requests, not a measured one: a random queue wait, and one customer in five pastes a 9,000-token order history into the chat.
import random
rng = random.Random(7)
# seconds, one per request
ttfts = []
for _ in range(1000):
# time in the queue, 50 ms on average
wait = rng.expovariate(1 / 0.05)
# one in five pastes an order history
prompt = rng.choice([1860, 1860, 1860, 1860, 9000])
# prefill: 30 microseconds a prompt token
ttfts.append(wait + prompt * 0.00003)
mean = sum(ttfts) / len(ttfts)
print(f"mean {mean:.3f} s")
print(f"p50 {percentile(ttfts, 50):.3f} s, p95 {percentile(ttfts, 95):.3f} s, p99 {percentile(ttfts, 99):.3f} s")
The median TTFT comes out near 0.1 s. Where does the mean land?
Pick one to see what it prints.
Pick an answer above to see the rest