Skip to content

Shape Bandwidth

Limit upload or download throughput for matched public requests without rejecting them.

Use This When

Use traffic shaping for large uploads, public file downloads, or protecting small upstreams from bandwidth-heavy clients.

Prerequisites

  • A host/path/method match that isolates the traffic to slow.
  • A throughput budget in KiB/s for upload, download, or both.

Steps

  1. Open Traffic Policy -> Traffic Shaper and select Add Traffic Shaper.

    p2pstream Traffic Policy Traffic Shaper page showing its separate tab, rule filters, and compact rule table
    Traffic Shaper and Cache are separate Traffic Policy tabs. The execution-order strip shows shaping before route resolution and cache after route-target selection.
  2. Match the traffic. Example for a downloads path:

    FieldValue
    Namedownloads-shaper
    Priority20
    EnabledOn
    ProtocolsHTTPS
    Host patternsfiles.example.com
    Path prefixes/download
  3. Choose which request protocols the rule applies to:

    Applies toUse when
    All requestsHTTP responses and upgraded WebSocket connections should use this rule. This is the default.
    WebSockets onlyLong-lived WebSocket traffic needs its own upload and download rates.
    Exclude WebSocketsOrdinary HTTP traffic should be shaped while WebSockets use a separate rule.

    A WebSocket-only rule and a WebSocket-excluded rule can use different rates even when their CEL match is otherwise identical.

  4. Choose budget scope:

    ScopeUse when
    Per keyAll requests for the same key should share one budget.
    Per requestEvery request should get an independent budget.

    For public downloads, use per key and key by remote IP. For one-off large imports, per request may be simpler.

  5. Set the KiB budgets:

    FieldValue
    Download KiB/s1024
    Upload KiB/s0
    Burst KiB2048
    Request free KiB0
    Response free KiB64

    0 means unlimited for an upload or download rate. Free KiB are sent without delay and do not consume the shaper budget.

    Burst KiB

    Burst allows a connection to temporarily exceed the configured rate by up to this many KiB before the token bucket enforces the limit. Use it to absorb the initial burst of a download without throttling the entire transfer from byte one. Set it to 0 to disable burst.

p2pstream Edit Traffic Shaper drawer showing WebSocket request scope, per-key scope, KiB bandwidth budgets, CEL match, and key parts
The traffic-shaper drawer defines which request protocols are slowed, whether budgets are shared per key or per request, and the upload, download, burst, and free-data amounts in KiB.

Verification

Download a large matching file and watch transfer speed. Use Monitor -> Traffic tracing to confirm the shaper rule is selected.

Troubleshooting

SymptomCheck
Small responses appear unshapedThey may fit within the configured free KiB or finish before the rate is visible.
Clients share bandwidth unexpectedlyReview key parts and budget scope.
WebSocket uses the HTTP rateAdd a higher-priority WebSockets-only rule and exclude WebSockets from the HTTP rule.
WebSocket rule does not matchConfirm the request uses a valid version 13 handshake with Connection, Upgrade, and Sec-WebSocket-Key headers.
Rule does not matchConfirm host, path, protocol, method, and priority.

Next Steps

Operations documentation for self-hosted p2pstream deployments.