~/lukaszbienkowski.pl

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.

GoGo schedulerpriority queuemetrics

client timeouts at peak traffic

1234 10% < 1% time, at peak traffic

Illustration. Only 10% and < 1% are real; the size and order of the steps and the noise are made up.

grep hypothesis
fixhypothesisverdictchange
–lock contention writing responsesruled outnone: batches held one response
1requests waiting past their deadlinecausedeadline-ordered queue
2deadlines piling up on the Go schedulercausejitter on timeouts
3responses written in arrival ordercausewritten as they are ready
4countdown from the TCP reader, missing network timecauseclients send their timestamp; alerts on clock sync