01/04 · ml serving at samsung ads
Unjustified timeouts
This seemed correct: a few milliseconds before the client's timeout, we would return an empty response, which was preferred to a timeout. But during spikes the client still reported many timeouts. I ran a broad investigation to find out why, and fixed it.
I tested multiple ideas in a shadow environment, with rich Grafana dashboards around it. Three of them proved useful, and my fixes mitigated the problem:
- I made worker pools pick up requests by urgency, rather than arrival order.
- Bursts of deadlines stopped choking the Go scheduler when I introduced a jitter around them.
- The deadline countdown no longer ignores the network: I nudged the clients to send their timestamp with each request, instead of relying on the time we received it.
Others were ruled out in experiments: for example, a suspected mutex congestion on response flush turned out to be a dead end.
goal 99% of requests answered in time. An empty response is an answer; a timeout is not. served ✓ empty ✓ timed out ✗
before first come, first served
- served
- 0
- empty, in time
- 0
- timed out
- 0
after least time left goes first
- served
- 0
- empty, in time
- 0
- timed out
- 0
Same requests in both lanes; the bar in each one is the time it has left. An illustration of the mechanism with an example goal, not production data.
client timeouts at peak traffic
Illustration. Only 10% and < 1% are real; the size and order of the steps and the noise are made up.
| fix | hypothesis | verdict | change |
|---|---|---|---|
| – | lock contention writing responses | ruled out | none: batches held one response |
| 1 | requests waiting past their deadline | cause | deadline-ordered queue |
| 2 | deadlines piling up on the Go scheduler | cause | jitter on timeouts |
| 3 | responses written in arrival order | cause | written as they are ready |
| 4 | countdown from the TCP reader, missing network time | cause | clients send their timestamp; alerts on clock sync |