Proxy Bandwidth Limiting and Shaping: How to Measure Your Ceiling and Write Code for Saturation
Table of contents
- Introduction: why bandwidth on a proxy matters more than you think
- The basics: a vocabulary you can't skip
- Deep dive: what happens at the moment of saturation
- Method 1: correctly measuring the bandwidth ceiling
- Method 2: identifying the limiter type and its parameters
- Method 3: writing a client that cooperates with the limiter
- Method 4: traffic budget and load architecture
- Common mistakes: what definitely not to do
- Tools and resources
- Case studies and results
- Faq: hard questions about bandwidth and shaping
- Conclusion: from guesswork to managed bandwidth
Introduction: Why Bandwidth on a Proxy Matters More Than You Think
Most conversations about proxies revolve around anonymity, geolocation, and "will I get banned." Bandwidth stays in the shadows. Yet it's exactly what determines how many hours your scraper will take to finish, how many accounts a single channel can handle, and why a script that worked perfectly on your test bench started throwing timeouts every ten minutes in production.
We're going to dig into a topic that rarely gets covered systematically: how bandwidth limiting works on a proxy, what shaping and policing actually mean, what a channel's ceiling looks like in real numbers, and, most importantly, how your client code behaves when it hits that ceiling. We deliberately won't rehash general proxy quality assessment methodologies. This is only about bandwidth, its limit, and what happens to your application at the moment of saturation.
Why is this relevant right now? By 2026, the average web page with all its resources has blown past three megabytes, APIs are returning ever-heavier JSON responses, and the mobile channels that mobile proxies run on physically share radio resources with regular subscribers in the same cell. At the same time, carriers and proxy providers are more aggressively applying session-level shaping to keep one client from devouring the whole channel. A developer who doesn't understand how a limiter works is doomed to write code by trial and error.
From this guide, you'll learn: how to tell a shaper from a policer by the shape of the graph, how to correctly measure the ceiling of a single stream and of an aggregate, how to estimate the bucket size and queue depth, why latency grows and efficiency drops under saturation, how to write a client with backpressure and adaptive concurrency, and how to budget traffic in bytes rather than requests. At the end, you'll find checklists, tools, three case studies with real numbers, and an FAQ covering the trickiest questions.
The Basics: A Vocabulary You Can't Skip
Bandwidth, Throughput, and Goodput
People mix these up constantly, but the difference is fundamental. Bandwidth is the nominal ceiling of a channel — how many bits per second it can carry in ideal conditions. Throughput is how many bits actually moved per unit of time, including all overhead: TCP and IP headers, retransmissions, encryption. Goodput is only the bytes that made it to your application and were actually used. If a 100-megabyte file downloads in 20 seconds, your goodput is 5 megabytes per second, even though the channel could have carried 8–12 percent more if not for protocol overhead.
The practical takeaway: limiters on proxies almost always count throughput at the packet level, while you see goodput. There will always be a gap between them.
Channel Ceiling and Limiting Levels
The ceiling is the maximum speed the limiter permits at a given level of aggregation. There are usually several levels, stacked like nesting dolls:
- per TCP connection — each individual stream can't exceed, say, 2 megabits per second, but ten streams will deliver twenty;
- per session or proxy port — all connections through one port share a common limit;
- per account — the sum across all of a client's ports;
- per node — the physical limit of the modem, server, or uplink;
- per carrier channel — what the cell gives you at a particular moment, factoring in radio network load.
The real ceiling is the minimum across all levels. And that minimum fluctuates throughout the day, because the bottom level — the radio channel — depends on how many subscribers are near the modem.
Token Bucket: The Mechanics Behind Almost Every Limiter
Imagine a bucket that tokens drip into at a constant rate. Every byte passing through the limiter takes one token. If the bucket is empty, the byte either waits (shaping) or gets dropped (policing). The drip rate is the rate — the target speed. The bucket size is the burst — the allowable spike. While the bucket is full, you can send a batch of data faster than the nominal rate. Then the speed levels off to the rate.
This model explains a surprising amount. Why do the first two seconds of a download go faster than the rest? The bucket was full. Why do short requests almost never hit the limit? They fit within the bucket capacity. Why does a long download suddenly "sag" to one flat number? The bucket emptied, and now it's pure rate.
Shaping vs. Policing
A shaper queues excess packets and releases them at a set speed. Traffic smooths out, losses are low, but latency grows: packets wait their turn. A policer doesn't hold a queue — it simply drops everything that exceeds the limit. Latency doesn't grow, but TCP sees losses, sharply cuts its window, then ramps back up, and the speed graph turns into a sawtooth.
An analogy: a shaper is a traffic light with adjustable green time — everyone gets through, just slower. A policer is a tow truck that removes every car over the quota. The flow of cars lurches. For your code, this difference is enormous, and we'll come back to it.
The Specifics of Mobile Channels
A mobile proxy sits on a cellular carrier's channel. Here the ceiling is set not just by server settings but by physics: the modem's category, frequency bands, the number of subscribers in the cell, signal quality. On top of that, the carrier applies its own traffic prioritization at the quality-of-service class level. The result: mobile channel bandwidth is an order of magnitude less stable than a server's, and any measurement methodology must account for the time factor.
Deep Dive: What Happens at the Moment of Saturation
The Moment of Truth: The Queue Grows
As long as your traffic stays below the ceiling, the limiter is essentially invisible. Problems start when the sum of your streams exceeds the rate. With a shaper, the queue begins to grow. Each packet waits in a buffer before moving on. If the buffer is deep — and deep buffers are beloved by cheap network gear and software limiters with generous settings — latency can balloon from 60 milliseconds to a second and a half. This is called bufferbloat: an inflated buffer turns a fast channel into a slow, sticky one.
To the application, it looks like this: download speed seems fine, but every new request starts with monstrous latency. Small API calls that used to take 100 milliseconds now take a second. Timeouts set "with a margin" start firing. And the most insidious part: you won't see packet loss. Everything just gets slow.
TCP's Reaction: Why the Congestion Control Algorithm Matters
TCP itself tries to feel out the channel's ceiling. The classic CUBIC algorithm ramps up its send window until it sees loss, then cuts speed and ramps up again. With a policer, CUBIC performs poorly: losses are frequent and abrupt, and average speed can end up 30–40 percent below the ceiling. With a shaper, CUBIC fills the queue to the brim because there's no loss for a long time — it becomes the main culprit behind bufferbloat.
The BBR algorithm, increasingly common on servers, behaves differently: it estimates bandwidth and minimum RTT and tries not to overflow the queue. Through a shaper, BBR delivers steady speed and moderate latency. But remember: the algorithm on your client's side only controls the outbound stream. The inbound stream from proxy to you is governed by the proxy server's and target site's settings, which you don't control.
One Tunnel, Many Streams: Head-of-Line Blocking
When you work through an HTTP proxy via CONNECT or through SOCKS5, each of your TCP connections to a target site is wrapped in a separate connection to the proxy. If you use HTTP/2 to the target site within a single tunnel, all requests multiplex into one TCP stream. Under saturation, this creates head-of-line blocking: one heavy response occupies the window, and light requests wait behind it. With a per-connection limiter, this is especially painful: the entire multiplex shares one limit.
The practical conclusion that many reach too late: concurrency through a proxy should be built on multiple TCP connections, not on multiplexing within one. We'll factor this into the code section.
Fairness Between Streams
How does the limiter divide bandwidth among your ten connections? If the limit is shared and there's one queue, the more aggressive streams with more data in flight grab more bandwidth. Small requests systematically lose to large ones. If the limiter runs a fair queue, each stream gets roughly an equal share. You can only figure out which scenario you're in through experimentation, and it determines whether you should split heavy downloads and light API calls across different connections or even ports.
Slow Start and Short Requests
TCP starts with a small window and doubles it every RTT. Over a mobile channel with an RTT around 80 milliseconds, ramping up to, say, 20 megabits takes several hundred milliseconds. A 50-kilobyte request finishes before TCP can even accelerate. That's why short requests never hit the bandwidth ceiling — but they're extremely sensitive to latency. This splits your traffic into two classes with different rules: heavy streams where rate matters, and light ones where RTT matters. A single limit strangles the former, and bufferbloat from the former kills the latter.
Signatures on the Graph
If you plot speed per second, limiters will give themselves away by shape:
- a flat plateau with a smooth ramp-up and rising RTT — a shaper with a deep queue;
- a plateau with a hump at the start — a shaper or policer with a noticeable burst bucket;
- a sawtooth with 30–50 percent dips, stable RTT, retransmissions present — a policer;
- chaotic fluctuations with no clear plateau — you've hit not a limiter but the radio channel or a congested node.
Reading these signatures saves hours of debugging. Next up — how to capture them correctly.
Method 1: Correctly Measuring the Bandwidth Ceiling
Why You Need a Methodology, Not a Single Check
Anyone can fire off a download and read a number. The problem is that one number means nothing: it depends on the time of day, the source, your own channel, and the slow-start phase. We need a reproducible protocol whose results can be compared across channels and across days.
Preparing a Reference Source
Rule one: measure bandwidth against a source that's guaranteed faster than any proxy. Otherwise you'll measure the source, not the proxy. The ideal setup is your own server on a location with a guaranteed gigabit uplink, hosting test files of 20, 100, and 500 megabytes generated from random data. Random data matters: a compressible file could be compressed somewhere along the way, and you'd get an inflated number.
You can use public test files from popular CDNs, but with a caveat: the CDN serves from the node nearest the proxy, so you're effectively measuring the bandwidth between the proxy and the CDN, not between the proxy and an arbitrary site. For ceiling estimation that's acceptable; for estimating real goodput to your target resources, it isn't.
Eliminating Your Own Bottleneck
The machine you're measuring from should have a channel at least three times wider than the expected proxy ceiling. Verify this with a separate direct download of the same file. Turn off background downloads, cloud sync, updates. If you're running measurements from a container or VM, make sure the virtual network isn't throttling you on its own.
Single-Stream Protocol
- Start downloading a 100-megabyte file through the proxy with one connection, recording speed every second. With curl, this is done using progress flags; it's easier to write a small script that reads the body in a streaming fashion and logs bytes per second.
- Discard the first three seconds — that's slow start and bucket drain.
- Stop measuring after 40–60 seconds or when the file finishes. Less than 20 seconds isn't enough to see a steady state.
- From the remaining seconds, compute the median, the 10th and 90th percentiles, and the coefficient of variation (standard deviation divided by the mean).
- Repeat three times with a one-minute pause.
The median is your steady-state single-stream ceiling. The gap between the 10th and 90th percentiles tells you about stability. A coefficient of variation below 0.15 means a smooth channel; above 0.4 means either a policer or a congested radio network.
Aggregate Protocol
Now do the same, but with 2, 4, 8, and 16 parallel connections to the same file or to multiple files. Sum the speeds per second. You get aggregated speed as a function of stream count. It comes in three types:
- linear growth to a plateau — per-connection limit, aggregate ceiling is higher; the plateau reveals the next limiting level;
- plateau from the very first stream — shared per-session limit; additional streams give nothing and only increase latency;
- growth then decline — with many streams, losses and overhead grow, and the channel degrades. The optimum is where growth stopped.
A quick orientation with a single curl looks like this: curl -x http://user:pass@host:port -o /dev/null -w "%{speed_download} %{time_total}" https://your-server/100mb.bin. It gives average speed over the whole file, which is fine for a first estimate, but signatures require per-second logging.
Time-of-Day Sweep
For a mobile channel, measuring in four windows is mandatory: night, morning, afternoon, evening. The evening ceiling in a residential area can be half the night one. If you plan around-the-clock load, your code has to live with the evening ceiling, not the night one.
Ceiling Measurement Checklist
- Reference source is guaranteed faster than the proxy, files generated from random data.
- Your own channel verified separately and at least three times wider.
- Per-second byte logging, first three seconds discarded.
- Steady-state duration of at least 20 seconds.
- Three repeats, median and percentiles, coefficient of variation.
- Series across stream counts: 1, 2, 4, 8, 16.
- Four time-of-day windows for mobile channels.
- Results recorded in a single format with timestamp, port, and source.
Method 2: Identifying the Limiter Type and Its Parameters
Why You Need to Know What You're Facing
The same 10-megabit ceiling requires different code depending on whether it's a shaper or a policer, whether there's a burst bucket and how big it is, and whether latency grows under load. This method turns a speed graph into a set of parameters you can drop straight into your client's config.
Burst Test: Measuring the Bucket
- Give the channel a 30-second rest with no traffic so the bucket fills.
- Start a download and record speed at 100–200 millisecond resolution for the first five seconds.
- Find the moment speed drops to the steady-state value from Method 1.
- Estimate the bucket size as the total bytes transferred before that moment, minus what would have passed at steady-state speed over the same time.
Example: the first 1.5 seconds run at 40 megabits, then exactly 10. The bucket is roughly 40 minus 10, times 1.5 seconds, divided by 8 — about 5.6 megabytes. This means requests up to 5 megabytes, spaced apart with pauses, will go through at "fast" speed. A great planning tool if your workload consists of medium-sized responses.
If there's no burst and speed immediately settles onto a plateau with a smooth ramp, the bucket is small or absent, and the limiter is probably a shaper with a hard rate.
Latency Under Load Test
This is the key test for distinguishing a shaper from a policer. In parallel with a long download, fire a series of light requests through the same proxy port: for example, a HEAD to your server every 500 milliseconds. Record response time before, during, and after the load.
- Latency grew several times over, into the hundreds of milliseconds or seconds, while speed stays flat — a shaper with a deep queue. Record the depth: the latency increase multiplied by the rate gives you an approximate buffer size in bytes.
- Latency barely changed, but the connection stats show retransmissions and the speed is sawtoothing — a policer.
- Latency grew moderately, by 50–150 milliseconds, speed is smooth — a shaper with managed queueing, the most comfortable option.
On Linux, you can check retransmission stats with ss -ti on the relevant connection: it shows retrans counters and current RTT. This is a free and precise way to see whether packets are being lost.
Aggregation Test: Per-Connection or Per-Session
You already have the curve from Method 1. Refine it: start one connection at full speed and a second one with a client-side cap at 10 percent of the ceiling. If the first barely slows down, the limits are separate per connection. If the first lost exactly as much as the second took, the limit is shared. This test is cheaper than a 16-stream series and gives an unambiguous answer.
Separating the Limiter from the Radio Channel
How do you tell that a plateau is a setting and not cell physics? Three signs point to a setting: the plateau holds within a few percent at different times of day, the number is "round" (5, 10, 20, 50 megabits), and the ramp-up shape is identical on every repeat. A radio channel gives "non-round" and fluctuating values that depend on time. You can also measure a second port on the same node at the same moment: if two ports together deliver more than one, the limit is per port, not per modem.
Classification Framework
Compile your results into a channel card:
- Single-stream ceiling: median, coefficient of variation.
- Aggregate ceiling: value and the stream count at which it was reached.
- Limit level: connection, session, node.
- Type: shaper or policer.
- Bucket: size in megabytes, or "none."
- Queue depth: latency increase under load.
- Time-of-day profile: ceilings across four windows.
This card is a direct input into your client configuration. Without it, you'll be tuning parameters by feel.
Method 3: Writing a Client That Cooperates with the Limiter
Philosophy: Don't Fight, Negotiate
The key insight that arrives after a dozen tuned systems: you cannot "break through" a limiter with more streams. You can only fill its queue and get bufferbloat, or provoke a policer into mass drops. An efficient client holds its speed slightly below the ceiling so the limiter's queue stays nearly empty and latency stays low. The paradox that surprises newcomers: by cutting speed 10 percent, you often increase goodput, because timeouts and retries disappear.
Component 1: Client-Side Token Bucket
Implement the same kind of bucket your limiter uses, but with a rate at 85–90 percent of the measured steady-state ceiling and a bucket size no larger than half the proxy's measured bucket. Apply the limiter to reading the response body: before reading each chunk, request tokens equal to the bytes you're about to read, and wait if there aren't enough. The logic step by step:
- Store two numbers: current token balance and last refill time.
- When N tokens are requested, first refill:
tokens = min(burst, tokens + (now - last) * rate). - If tokens suffice, subtract and proceed. If not, compute the wait time
(N - tokens) / rateand sleep asynchronously. - One bucket per proxy port, shared across all connections through that port if the limit is per session. If the limit is per connection, one bucket per connection plus a shared one per node.
Why limit reads and not requests? Because reads determine how fast data is pulled out of the limiter's queue. If you read slower than the proxy delivers, TCP itself will tell the sender to shrink its window, and data stops piling up in intermediate buffers. This is backpressure in its purest form.
Component 2: Concurrency Semaphore
Cap the number of simultaneous connections per port with a semaphore. Start with a value from the aggregate curve in Method 1: the stream count where growth stopped, minus one. For a typical mobile channel, that's 4–8. More only adds latency.
Component 3: Streaming Reads and Progress Timeout
Never set a single timeout for the whole request. A 50-megabyte file at a 5-megabit ceiling will honestly take 80 seconds, and a 30-second timeout will kill it halfway through, wasting half the bandwidth. The right approach: a connect timeout (5–10 seconds), a first-byte timeout (10–20 seconds, accounting for possible bufferbloat), and a progress timeout — the maximum interval between two successfully read chunks, typically 15–30 seconds. Read the body in chunks of 32–64 kilobytes, updating the progress marker after each chunk.
Component 4: Adaptive Concurrency via AIMD
A mobile channel's ceiling fluctuates, and a static semaphore doesn't track it. The solution is to manage concurrency dynamically on the additive-increase, multiplicative-decrease principle, exactly as TCP does:
- Every 10 seconds, compute goodput over the window and median first-byte latency.
- If latency is below 1.5× baseline and there are no errors, increase the semaphore limit by one, up to a ceiling.
- If latency grew more than 2× baseline or progress timeouts appeared, halve the limit, but not below one.
- Measure the baseline latency at startup with a single connection and recalculate once an hour.
Such a controller finds a comfortable point within a couple of minutes and holds near it, automatically shrinking in the evening and expanding at night. We've seen it lift daily goodput by 20–35 percent with zero change to the ceiling.
Component 5: Retries with Exponential Backoff and Jitter
A timeout is a congestion signal, not an invitation to retry immediately. An immediate retry makes the queue worse. The rule: first retry after 1–2 seconds, each subsequent one twice as long, max 5 attempts, with random jitter up to 50 percent added to each delay so ten streams don't wake up simultaneously. On a progress timeout for a large file, it's worth resuming from the break point with a Range request if the server supports it: bandwidth spent on the first half isn't lost.
Component 6: Priority Queues
Split tasks into classes: interactive (light API calls where latency matters) and background (heavy downloads). Background gets a share of the bucket, say 70 percent, while interactive gets a guaranteed reserve. If the limit is per connection rather than per session, put classes on separate connections. If possible, on separate proxy ports. That way one heavy file won't block a hundred small requests.
Component 7: Counting Bytes, Not Requests
Count every byte read per port, per class, and per target domain. Export to metrics. These are exactly the numbers that will show you where bandwidth goes and let you budget it — which brings us to the next method.
A Mini-Framework in Python
A reference implementation with asyncio and any async HTTP client looks like this:
- A
TokenBucketclass with anasync def take(n)method following Component 1's logic. - A
Channelclass: proxy address, bucket, semaphore, counters, AIMD controller. - An
async def fetch(channel, url)function: under the semaphore, opens a request through the proxy, waits for headers with the first-byte timeout, then loops readingchunk = await resp.content.read(65536), callingawait channel.bucket.take(len(chunk))beforehand, updating the progress marker and byte counters. - A background task
async def tune(channel): reads metrics every 10 seconds and adjusts the semaphore size. - A retry wrapper with exponential backoff and Range support.
An important Python detail: default clients buffer the entire response in memory. Make sure you use streaming mode, or there'll be no backpressure and the read limiter will be useless. In Go, the equivalent is built on io.Reader with a limiter wrapper and golang.org/x/time/rate; in Node.js, on pausing and resuming the response stream.
Client Checklist
- Client-side bucket with a rate at 85–90 percent of the ceiling.
- Streaming reads in chunks, limiter applied on reads.
- Three separate timeouts: connect, first byte, progress.
- Semaphore with latency-driven adaptive control.
- Retries with exponential backoff, jitter, and Range.
- Separation of interactive and background tasks.
- Concurrency on multiple TCP connections, not on a multiplex within a single tunnel.
- Byte accounting per port, class, and domain.
Method 4: Traffic Budget and Load Architecture
Think in Bytes
Most systems plan load in requests per second. But a bandwidth limiter counts bytes. A 4-kilobyte API call and a 3-megabyte page load differ by a factor of 750. The first step of this method is to convert your plan into bytes: how many responses of what size do you get per hour, and does the daily ceiling profile from your channel card cover it.
A simple formula: daily channel capacity in bytes equals the sum across the four windows of ceiling times window duration, multiplied by a factor of 0.8 for overhead and headroom. For a channel with a night ceiling of 20 megabits and an evening ceiling of 8, daily capacity is around 120–130 gigabytes. If your plan requires 300, no amount of code optimization will help — you need more channels.
Reducing Volume per Request
- Compression: always send an Accept-Encoding header with gzip and br. Text responses shrink by 4–8×. If your client doesn't decompress responses automatically, turn that on.
- Dropping unnecessary resources: with browser automation, block images, fonts, and media if they're not needed for the task. This saves 60–80 percent of page traffic.
- Conditional requests: store ETags and Last-Modified, send If-None-Match. A 304 response weighs hundreds of bytes instead of megabytes.
- HEAD before GET: if you need to check a resource's existence or size, don't download it.
- Range requests: when you only need part of a file — for example, metadata at the start — request a range.
- API fields: many APIs support field selection. Request only what you need.
Distribution Across Channels
If you have several channels, don't divide tasks evenly. Divide proportionally to the current ceiling, measured live via each channel's goodput. The scheduler holds a task queue and hands the next task to the channel with the emptier bucket and lower latency. A channel in degradation automatically gets less work, with no manual intervention.
Scheduling Over Time
Move bulk background tasks to nighttime windows when the ceiling is higher. Spread interactive and urgent tasks evenly, but with a bandwidth reserve. Sounds obvious, but in practice few build schedulers that account for a channel's daily profile. The difference in daily goodput with such scheduling runs up to 40 percent on the same set of channels.
Circuit Breaker
Build a hard circuit breaker into the client: if a channel's goodput over the last two minutes falls below 20 percent of the card's median while latency grows more than 4×, temporarily drop the channel from rotation for 5 minutes. This protects against a situation where a congested cell or a problematic node drags the whole system into endless retries.
Budget Checklist
- Plan converted into bytes by task class.
- Daily channel capacity computed from the profile with 20 percent headroom.
- Compression, blocking unnecessary resources, conditional requests, Range all applied.
- Scheduler distributes by current goodput, not evenly.
- Bulk tasks shifted into high-ceiling windows.
- Circuit breaker on goodput and latency configured.
Common Mistakes: What Definitely Not to Do
Adding Streams Until It Gets Faster
The most common mistake. With a shared per-session limit, extra streams only lengthen the shaper's queue. Speed doesn't rise, latency does, timeouts pour in. With a policer, losses grow and the aggregate may even drop. More concurrency only makes sense up to the point where the aggregate curve plateaus.
One Timeout for the Whole Request
Kills honestly progressing large downloads halfway and wastes bandwidth. Use a progress timeout.
Instant Retries
Under congestion, an immediate retry doubles the pressure on the queue. Ten streams retrying simultaneously create a small storm. Exponential backoff and jitter are mandatory.
Measuring the Ceiling with a Single Check
One number at 2 PM on a Tuesday tells you nothing about the channel at 8 PM on a Friday. Without a daily profile, you'll either underuse the channel or build a system on nonexistent bandwidth.
Measuring Against a Slow Source
A public server with a congested uplink will show you its own ceiling, not the proxy's. Verify the source directly.
Buffering the Whole Response
Without streaming reads, there's no backpressure. The client gulps down whatever the proxy delivers, and your client-side limiter does nothing. Plus memory for large responses.
Multiplexing Everything into One Tunnel
HTTP/2 inside a single CONNECT with a per-connection limit divides bandwidth across all requests and creates head-of-line blocking. Multiple TCP connections are almost always more efficient through a proxy.
Ignoring Compression
A disabled Accept-Encoding means you're paying bandwidth for uncompressed text. A fivefold difference for nothing.
Confusing Bandwidth with Latency
A 50-megabit channel with 400-millisecond RTT is slower for a hundred small API calls than a 10-megabit channel with 60-millisecond RTT. Evaluate both parameters against your traffic profile.
Counting Requests, Not Bytes
Planning in requests per second ignores response sizes and leads to unexpected ceiling hits.
Tools and Resources
For Measurements
- curl — the universal tool for quick measurements through a proxy. The format-variables output flag gives average speed, time to first byte, connect time. For per-second logging, it's easier to write ten lines of Python.
- iperf3 — for measuring raw bandwidth between your machine and your server directly, to rule out your own bottleneck. It doesn't work through an HTTP proxy, but as a source control it's irreplaceable.
- ss with -ti — TCP connection stats on Linux: RTT, congestion window, retransmissions, congestion control algorithm. The best free policer detector.
- tcpdump and Wireshark — when you need to see exactly what's happening at the packet level: loss patterns, ACK delays, window behavior.
- mtr — traceroute with per-hop loss, helping identify where exactly losses occur on the path to the proxy.
For Local Emulation
Before testing code against a real proxy, build a test bench. On Linux, the tc utility with the tbf (token bucket filter) and netem disciplines lets you emulate a shaper with a given rate and burst, a policer, latency, and loss. You can reproduce a channel card locally and run your client against it as much as you like, without spending traffic or depending on the time of day. Developers who set up such a bench debug their clients twice as fast.
For Code
- Python: asyncio, aiohttp or httpx in streaming mode, your own 20-line token bucket. Ready-made limiter libraries exist, but most throttle requests rather than bytes, so your own implementation is more reliable.
- Go: the rate package from the extended standard library, a wrapper over io.Reader for read rate limiting, a context with deadlines for timeouts.
- Node.js: a streaming response with manual pause and resume control, libraries for semaphores and retries.
For Observability
Export goodput, first-byte latency, active connection count, timeout, and retry metrics per proxy port into your metrics system and build dashboards. Limiter signatures show up on graphs within a minute, and channel anomalies long before they bring down a job. Without observability, an adaptive controller can be neither tuned nor verified.
What to Read
The RFC specifications on TCP congestion control and active queue management algorithms give a deep understanding of why shapers behave the way they do. Linux documentation on tc queueing disciplines is a practical reference for emulation. Articles on bufferbloat explain why deep buffers are harmful and how it's being tackled at the network equipment level.
Case Studies and Results
Case 1: A Marketplace Catalog Parser That "Died" in the Evening
The task: a daily crawl of a catalog, roughly 400,000 pages, through eight mobile channels. Symptoms: at night the system finished in five hours, in the evening it timed out on every third request, and the daily plan wasn't being met.
A Method 1 measurement showed: nighttime channel ceiling around 18 megabits, evening 6–7. Method 2: a shaper with a deep queue, latency under load growing from 90 to 1,400 milliseconds, limit shared per session. The client used 32 streams per channel and a single 20-second timeout.
What we did: introduced a client bucket at 85 percent of the current ceiling, dropped starting concurrency to 6 with an adaptive controller, replaced the timeout with a three-tier one, enabled compression and image blocking (pages dropped from 1.4 megabytes to 180 kilobytes). Result: the evening timeout rate fell from 33 to 0.4 percent, daily goodput rose 41 percent on the same set of channels, and the crawl started fitting into 7 hours at any time of day. The most telling part: reducing concurrency from 32 to 6 increased useful speed rather than decreasing it.
Case 2: Media File Downloads and a Policer
The task: downloading 40–200-megabyte videos from a public host through a proxy, about 2 terabytes a month. Symptoms: erratic speed, average half of advertised, frequent mid-file breaks.
Measurement revealed a classic sawtooth: 40–50 percent dips every few seconds, stable RTT, retransmission counters climbing by tens per second. A per-connection policer at around 12 megabits, aggregate growing almost linearly up to 4 streams.
What we did: split each file into four Range parts and downloaded them in parallel over four connections, each with a client bucket at 10 megabits — just below the policer limit, so losses wouldn't be provoked. Added Range-based resumption on progress timeout. Result: average per-file speed rose from 5.5 to 36 megabits, breaks stopped causing loss of downloaded data, and the monthly volume finished in 12 days instead of 30. You can't fool a policer, but you can avoid giving it a reason to drop packets.
Case 3: Mixed API and Download Workload
The task: simultaneous work with a social platform API (thousands of small requests) and background media download through the same channels. Symptoms: API calls periodically went into 3–5-second latency, and the platform began treating the client as slow.
Diagnosis: per-session shaper, background downloads filling the queue, small requests stuck behind them. Classic bufferbloat within a single session.
What we did: split classes across different proxy ports on the same node; background ports got a bucket at 70 percent of their ceiling, API ports got concurrency capped at 3 with latency priority. Result: the 90th-percentile API latency dropped from 3.8 seconds to 210 milliseconds, background downloads slowed by 12 percent, which was acceptable. Overall system efficiency, measured in successful operations per hour, rose 27 percent.
FAQ: Hard Questions About Bandwidth and Shaping
Why is speed 8 megabits with one stream, and still 8 with ten, but everything got slower?
The limit is per session, not per connection. Ten streams share one rate and fill the shaper's queue. Bandwidth doesn't rise, but latency grows in proportion to queue depth. Optionally, hold 2–4 streams and rate-limit reads on the client.
How do I know I've hit the radio channel and not a proxy setting?
A setting gives a stable plateau with a "round" number at different times of day and an identical ramp-up shape. A radio channel gives fluctuating non-round values and a high coefficient of variation, especially in the evening. Additionally, compare two ports on the same node simultaneously: if the sum exceeds one port, the limit is per port, not per modem.
Should I put BBR on my server if I work through a proxy?
BBR affects the outbound stream from your server. If you're serving data through a proxy, it helps keep the shaper's queue empty and reduces latency. It doesn't affect the inbound stream from target sites to you: the sender governs that. On the client side, a read limiter is more important.
How far below the ceiling should I keep my client bucket?
For a shaper — 85–90 percent of the steady-state ceiling: queue nearly empty, latency low, bandwidth loss minimal. For a policer — 80–85 percent of the per-connection limit, to avoid provoking drops. For an unstable radio channel, better to let an adaptive controller find the point, and set the bucket from the evening profile.
Can I use HTTP/2 through a proxy to speed things up?
HTTP/2 to the target site works through a CONNECT tunnel, but all streams share one TCP connection and one limit if it's per connection. Plus head-of-line blocking under saturation. For heavy tasks, several HTTP/1.1 connections through a proxy usually deliver better goodput and predictable latency.
How do I measure the burst bucket size more precisely?
Give the channel a 30–60-second pause, log bytes at 100-millisecond resolution, find the break point to steady-state speed, and compute the excess over the steady-state line. Repeat five times, take the median. About 15 percent accuracy is enough for planning.
What if timeouts only appear on specific domains?
Most likely the bottleneck isn't the proxy but the path from the proxy to that domain, or the domain itself. Measure the ceiling against your reference source at the same moment: if it's normal, the constraint is external. In code, give such a domain its own class with lower concurrency and a longer first-byte timeout.
How do I know the adaptive controller is working correctly?
On graphs, concurrency should smoothly decrease in the evening and grow at night, first-byte latency should stay within 1.5–2× baseline, and the timeout rate should be under one percent. If concurrency bounces between minimum and maximum every minute, the evaluation window is too short or the reaction threshold is too sensitive.
Should I account for encryption when calculating bytes?
TLS adds 2–5 percent overhead for record headers and handshakes. For budget planning, a coefficient of 0.8 covering everything along with TCP/IP is sufficient. For precise accounting, count bytes at the socket level, not at the response body level.
Conclusion: From Guesswork to Managed Bandwidth
We've gone from basic concepts to a client architecture that doesn't fight the limiter but cooperates with it. Let's recap the essentials.
- The ceiling is the minimum across several levels, and for mobile channels it fluctuates through the day. One number means nothing; you need a profile.
- Shapers and policers require different code. A shaper punishes with latency, a policer with losses. You can tell them apart in ten minutes with a latency-under-load test and retransmission stats.
- Saturation isn't about speed — it's about the queue. Bufferbloat turns a fast channel sticky and kills small requests before large ones slow down.
- The client should read in a streaming fashion, rate-limit reads just below the ceiling, use three separate timeouts, adaptively manage concurrency, and retry with backoff.
- Plan in bytes, not requests. Compression, dropping unnecessary resources, and conditional requests often deliver more than any concurrency tricks.
What to do next? Today: stand up a reference source and take a channel card via Methods 1 and 2 for at least one port. This week: build a local tc bench, reproduce the card, and rewrite the client per the Method 3 checklist. Within a month: enable byte accounting, build dashboards, tune the adaptive controller, then recompute the traffic budget per Method 4.
Bandwidth stops being a source of surprises the moment you start measuring and respecting it. Code written with an understanding of the limiter doesn't just run faster. It runs predictably — and in infrastructure work, predictability is the main currency.