Sample Python Project for creating a new Python Module
Project description
Sawtooth 🪚
Sawtooth is a utility for congestion control using additive increase and multiplicative backoff. The algorithm is based on this blog post.
Getting started
pip install sawtooth
Basic usage
from sawtooth import Sawtooth, SawtoothBackpressure
import asyncio
from aiohttp import ClientSession
from aiohttp.web_exceptions import HTTPTooManyRequests
async def main():
session = ClientSession()
sawtooth = Sawtooth(session)
with open('urls.txt') as f:
urls = f.readlines()
async def get_url(url: str):
async with sawtooth.resource() as s:
res = await s.get(url)
# Raise backpressure on 429
if res.status == HTTPTooManyRequests.status_code:
raise SawtoothBackpressure()
await asyncio.gather(*[get_url(url) for url in urls])
await session.close()
Configuration
A Sawtooth
instance can be configured by passing an instance of SawtoothConfig
as its second parameter.
sawtooth = Sawtooth(resource, SawtoothConfig(max_concurrency=100, min_concurrency=50))
The following options are available:
Name | Description | Default |
---|---|---|
max_concurrency | The maximum value we can increase concurrency to | 1000 |
min_concurrency | The minimum value we can reduce concurrency to | 1 |
step_size | The amount to increase concurrency by on a successful response | 1 |
backoff_factor | Reduce concurrency to concurrency * backoff_factor upon receiving backpressure |
0.95 |
starting_concurrency | Starting concurrency. | (max_concurrency - min_concurrency) / 2 |
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
sawtooth-0.1.0rc23.post1.tar.gz
(59.0 kB
view hashes)
Built Distribution
Close
Hashes for sawtooth-0.1.0rc23.post1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e3cb2d10e35cd4f413d7b1d76c4edaa03ae8a4f07bb38afe3a2858916c2568d4 |
|
MD5 | 1922f9739bf35a782682de0324535632 |
|
BLAKE2b-256 | d761c3d6e52067859a8c2b155fd20f87420b01ff7d9181b2463f36eeab716984 |