Conversation
Limit the number of ongoing downloads and use AIMD to adjust window size
- store each running request or its error in the slot - allocate all the workers for the slot in advance - if all attempts failed, correctly form the error msg - improve readability of retries logic - decouple idle pending state and waiting for queries state
Simplifies lease tracking and makes it more robust
|
I reviewed the overload-control changes and found a few correctness issues that look worth fixing before merge:
|
Did you or did AI review it? |
Goal
When the portal is overloaded, it breaks. E.g., it starts overusing its own network link and bans workers for considering them too slow.
This PR aims to keep it running at capacity.
Approach
Two resources are mainly limiting the capacity:
This PR addresses both
Changes
Congestion control
All ongoing downloads are going through the global scheduler now. To read the next chunk of data, you wait for a permit from the semaphore. The semaphore capacity is adjusted over time (AIMD) but can be configured to be constant.
Downloads are also prioritized — the query that started earlier gets the permit first. It allows sending more fetch-ahead queries without stalling more important downloads.
Worker reservation
Previously:
The problem is that if the buffer size is high, we allocate too many workers for the future. But when a query fails, we can't find a worker for a retry, and the stream is interrupted.
Now:
This way buffers just become shorter under the load, but problematic retries are avoided. Slower syncing is better than interrupting running streams.
The code became much simpler. It also allowed forming error messages that explain why each query attempt failed, not just the last one.
Priorities
Workers are now prioritized based on the observed throughput (keeping the backoff on hard errors). Throughput is measured only at time periods when the download was actively running. Thanks to the limited number of parallel downloads, I don't expect it to be too noisy. It may still highly depend on the response size, though.
Connections
Previously:
Now:
Remaining issues