A simple throttling package
Project description
This library is inspired by this book and this implementation https://github.com/vostok/throttling.
Features:
- Set capacity(max parallel requests) and queue(max queued requests) limits.
- Per-consumer limits. For instance, to not allow any consumer to use more than 70% of service's capacity.
- Per-request priorities. For instance, to not allow requests with lowest priority to be queued or to now allow requests with normal priority to use more than 90% of service's capacity.
Example:
from aio_throttle import Throttler, MaxFractionCapacityQuota, ThrottlePriority, ThrottleResult
capacity_limit = 100
queue_limit = 200
consumer_quotas = [MaxFractionCapacityQuota(0.7)]
priority_quotas = [MaxFractionCapacityQuota(0.9, ThrottlePriority.NORMAL)]
throttler = Throttler(capacity_limit, queue_limit, consumer_quotas, priority_quotas)
async with throttler.throttle(consumer, priority) as result:
... # check if result is ThrottleResult.ACCEPTED or not
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
aio-throttle-1.3.0.tar.gz
(4.7 kB
view hashes)
Built Distribution
Close
Hashes for aio_throttle-1.3.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5020d8007a80fbaac537e8532329a157655e59bfd436821834a2c63a69c2e3a3 |
|
MD5 | 68512e06e74b0cb74d154de468267383 |
|
BLAKE2b-256 | 117dc2391dc769a881f1d1f1e7f1a9eeb828065695aa4ee593256b0e4ce137e2 |