Repository navigation
reqstorm 2.5.0: concurrency="auto" and the open file limit - #21
Merged
Merged
Conversation
concurrency="auto" A fixed concurrency has to be guessed: too high floods a busy API with rejected attempts, too low wastes time. AutoConcurrency finds it from the responses, the way TCP congestion control does: - It limits attempts on the wire, not requests: an attempt takes a place just before it is sent and gives it back when the response arrives, so a request sleeping before a retry does not count. Limiting whole requests made retries look like server load and kept the limit wrong. - Backoff to 3/4 when more than 5 % of recent attempts met 429/502/503/ 504, a timeout or a dropped connection. It does not wait for the window to end: a quarter of the limit in rejections is enough, otherwise a server that rejects instantly sees hundreds of attempts per window. - Each backoff starts an epoch; attempts sent before it are ignored afterwards, so one burst is not punished three times (16 -> 12 -> 9 -> 6 in the first version). - Ease off to 9/10 when the median response takes twice the host's normal (its fastest typical time, tracked per host and drifting up slowly), so mixed fast and slow hosts are not confused. - Growth once per window (>= 0.25 s and 3x the recent response time), only when the whole limit was in use: doubling until the first backoff, then +10 %. The level that caused pushback is kept as a ceiling; growth stops just below it and probes it after 8 healthy windows (CUBIC-like), instead of hitting a hard capacity every window. - DNS, SSL and invalid-URL errors are not load signals. Measured against a local server that 503s anything over its capacity (600 requests, retries=3), fixed 100 vs auto: capacity 3: 494/600 ok, +105 % attempts vs 600/600, +2 % capacity 12: 600, +46 % vs 600, +1 %, faster capacity 40: 600, +20 % vs 600, +6 % capacity 100: 600, 0.2 s vs 600, 1.0 s (warm-up) and against a server that only slows down: 100 vs 9 in flight. The numbers were stable over three runs. Open file limit Each connection is a file descriptor, so concurrency=1000 in a shell with ulimit -n 256 failed with "Too many open files". fit_concurrency compares concurrency x pools (+64 reserved) with RLIMIT_NOFILE before anything is sent, raises the soft limit as far as allowed (trying OPEN_MAX on macOS), and otherwise lowers the concurrency with a warning that names the ulimit to use. SOCKS proxies count as extra pools. Skipped on Windows. Also - ProgressInfo.concurrency and "active 12/16" in the progress line; changes logged at DEBUG, a summary at INFO. - CLI: -c auto, --max-concurrency; --estimate uses the maximum. - The built-in TimeoutError is retryable and a load signal on Python 3.9/3.10, where it differs from asyncio.TimeoutError. Tests: controller units with a fake clock (slow start, fast pushback, epochs, per-host slowness, utilization, ceiling probe, bounds, gate), end to end against capacity-limited and congestion-slowed routes, the file limit raised/lowered/Windows paths plus a real subprocess with a lowered soft limit, and the CLI. Version 2.5.0.
- Rate limits and concurrency guide: why concurrency does not depend on
CPU cores, how concurrency="auto" decides, the measured comparison with
a fixed 100 including where a fixed number is faster, and how the open
file limit is handled.
- README, home page card, progress line ("active 12/16"), command line
options and the 2.5.0 changelog entry.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
concurrency="auto": finds how many attempts at once the servers handle well (TCP-style: slow start, fast backoff on 429/5xx/timeouts, ease off on slowdowns, per-host normal latency, epochs, growth only when used, ceiling + probe). Retry waits don't hold a place.Measured against a local server that 503s anything over its capacity (600 requests,
retries=3):concurrency=100concurrency="auto"Open file limit: concurrency is checked against
ulimit -nbefore sending; the soft limit is raised if possible, otherwise concurrency is lowered with a warning (instead of "Too many open files").Also:
active 12/16in the progress line,-c auto/--max-concurrencyin the CLI, built-inTimeoutErrorretryable on 3.9/3.10. Docs updated (guide, README, CLI, home page). 301 tests passing on 3.9, 3.12, 3.13.