Cap the number of concurrent requests #41
Merged
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.
Added
Maximum number of concurrent requests can be limited by
jobtype_extra.max_concurrency
field:By default, concurrent requests are unlimited. Setting
max_concurrency
to1
will make the jobprocess requests one by one. Overdue requests will be queued and processed in order.
Having such concurrency limits may cause some requests to wait in a queue.
If a throughput is higher than the job can handle, the queue will grow indefinitely.
To prevent that, you can also set
jobtype_extra.max_concurrency_queue
to limit the queue size.When the queue is full, the job will return
429 Too Many Requests
status code.Example (1 request at a time, with up to 10 requests waiting in a queue):
Without this setting, FastAPI uses a threadpool of 40 threads internally to handle requests using non-async endpoints.
FastAPI uses Startlette's concurrency support to run requests in a threadpool. Starlette uses anyio, which in turn has 40 as the default