liveBook · Manning

Traffic-shaping algorithm

As explained in Python Concurrency with asyncio

Traffic shaping is the control of network traffic volume or rate to conform to specified limits.

A traffic-shaping algorithm controls request volume or rate so network activity conforms to specified limits. A semaphore can keep at most 10 requests running, but requests may still arrive in a burst; traffic shaping addresses that timing problem. section 11.3

Use the distinction to choose the right control:

  • Use a semaphore to limit concurrent requests and start a replacement when one finishes. section 11.3
  • Add a leaky-bucket or token-bucket implementation when bursts must also be limited over time. section 11.3

How Python Concurrency with asyncio covers it

How deep it goes
Contrasts concurrency limiting with rate shaping and names two algorithms, but stops short of implementing either.
Examples
Uses ten concurrent requests as a semaphore example and identifies simultaneous bursts as the problem to shape.
What you can do after
Evaluate whether a semaphore is sufficient or whether a leaky-bucket or token-bucket design is needed.
How it connects
Connects semaphores, concurrency, API requests, leaky buckets, and token buckets.

Also explained in

Compare how 2 books explain traffic-shaping algorithm →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Python Concurrency with asyncio. The section links point to the parts of the book it draws on.