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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sawtooth-0.1.0rc25.post1.tar.gz.
File metadata
- Download URL: sawtooth-0.1.0rc25.post1.tar.gz
- Upload date:
- Size: 59.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.28.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a9594b15bb3e2ccb2f83794a11aaff4ce1b73cdbaf5dd261beda2d996e9acecf
|
|
| MD5 |
5dc158dd1f3aa3e99573ad335f1e2dee
|
|
| BLAKE2b-256 |
2a1acd52bc96124ed7e43e766e7f48a384ca33f977c3c8935a4b5950e9cb0933
|
File details
Details for the file sawtooth-0.1.0rc25.post1-py3-none-any.whl.
File metadata
- Download URL: sawtooth-0.1.0rc25.post1-py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.28.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2522afa93321a7571d49a96f45e0494d11c6db5c580dad6a0f8445efb6ff97da
|
|
| MD5 |
c22c48628477ff15a9539afa38a2922d
|
|
| BLAKE2b-256 |
512566dbf04d9429d82d70ab55046030ec877c20b56d09e3f9214c9d8693c659
|