A policer drops, a shaper waits
Both tools compare traffic with a token bucket that fills at the configured rate. Traffic that finds enough tokens is conforming. What happens to the rest is the difference. A policer drops it or re-marks it, at once, with no queue. A shaper puts it in a queue and sends it when tokens are available. The shaper therefore turns an excess into delay, and the policer turns it into loss.
Traffic above the rate is dropped or re-marked by a policer, which adds no delay. A shaper holds it in a queue and sends it later, which adds delay and loses fewer packets.
| Property | Policer | Shaper |
|---|---|---|
| Excess traffic | Dropped, or re-marked | Held in a queue |
| Delay added | None | Up to the queue depth |
| Output | Bursts pass if tokens allow | Smoothed toward the rate |
| Works on | Input or output | Output only |
| Typical use | A provider enforcing a contract | A customer holding to the contract |
The bucket and the interval
A shaper is defined by its rate, called the committed rate, and its burst, the committed burst. The interval is the burst divided by the rate. In each interval the shaper may send up to one burst of bits, and it sends them at the speed of the port, not at the shaped rate, then waits for the rest of the interval. A circuit shaped to 95 Mbps on a 1 Gbps port therefore sends in short bursts at 1 Gbps with gaps between them.
A burst of 475,000 bits at a shaped rate of 95 megabits gives an interval of 5 milliseconds. The burst leaves the port in 0.475 milliseconds at 1 gigabit, and the shaper then waits 4.525 milliseconds until the next interval.
- Burst475,000 bits
- Rate95 Mbps
- Intervalburst / rate= 5 ms
- On the wire0.475 msat 1 Gbps
- Gap4.525 msof silence
| Burst | Interval | Burst on the wire | Gap until the next |
|---|---|---|---|
| 475,000 bits (59,375 bytes) | 5 ms | 0.475 ms at 1 Gbps | 4.525 ms |
| 95,000 bits (11,875 bytes) | 1 ms | 0.095 ms at 1 Gbps | 0.905 ms |
Worked example: shaped to the rate, still dropped
The contract is 100 Mbps and the edge shapes to 95 Mbps, which is under the rate. A transfer that fills the shaper still sees heavy loss on the circuit. The reason is the shape of the traffic, not its average. Suppose the provider polices at 100 Mbps with a committed burst of 15,000 bytes, which is 120,000 bits. This value is an assumption for the example. Contracts vary widely, and the way to find yours is to ask.
| Step | Interval 5 ms | Interval 1 ms |
|---|---|---|
| Burst sent by the shaper | 475,000 bits | 95,000 bits |
| Time on the wire at 1 Gbps | 0.475 ms | 0.095 ms |
| Tokens added by the policer meanwhile | 47,500 bits | 9,500 bits |
| Policer's bucket plus tokens added | 167,500 bits | 129,500 bits |
| Excess the policer drops | 307,500 bits | 0 bits |
| Share of the burst lost | 64.7 percent | 0 percent |
The edge shapes to 95 megabits on a 100 megabit contract and still loses packets. The average is under the rate, but each burst is 475,000 bits against a provider bucket of 120,000 bits plus the tokens added during the burst. The excess is dropped. A smaller burst fits inside the bucket.
- SymptomLoss on the circuit at busy timesthough the shaper is below the rate
- Average95 Mbps against a 100 Mbps contractthe average fits
- Burst475,000 bits sent in 0.475 msagainst 167,500 bits of allowance
- Loss307,500 bits dropped per burst64.7 percent of the burst
- FixA smaller burst, or more headroom,and ask the provider for its burst
The repair has three parts. Ask the provider for the committed burst of the contract, in writing. Choose a shaper burst, or an interval, that fits inside it, which here means the 1 ms setting. And if the platform derives the burst by itself and does not let you set it, shape further below the contracted rate and test with a bulk transfer. A test at a quiet hour proves nothing, because a burst needs traffic to fill it.
The two settings above are only two points. The table sweeps the burst to find where the edge of what fits lies, using the same assumed bucket.
| Shaper burst | Interval at 95 Mbps | Lost at the policer | Result |
|---|---|---|---|
| 95,000 bits | 1.0 ms | 0 bits | Fits |
| 120,000 bits | 1.3 ms | 0 bits | Fits |
| 133,333 bits | 1.4 ms | 0 bits | The largest that fits |
| 200,000 bits | 2.1 ms | 60,000 bits (30 percent) | Drops |
| 300,000 bits | 3.2 ms | 150,000 bits (50 percent) | Drops |
| 475,000 bits | 5.0 ms | 307,500 bits (64.7 percent) | Drops |
Buffers turn packets into delay
A queue's length in packets looks harmless until it is converted to time. The delay a full queue adds is its size in bits divided by the rate that drains it. For 1,200-byte packets at 95 Mbps the figures grow fast.
| Queue length | Bits queued | Delay when full |
|---|---|---|
| 64 packets of 1,200 bytes | 614,400 | 6.5 ms |
| 1,000 packets of 1,200 bytes | 9,600,000 | 101 ms |
| 4,000 packets of 1,200 bytes | 38,400,000 | 404 ms |
Take the packets in the queue, multiply by the packet size in bits, and divide by the rate that drains the queue.
- Packetsin the queue
- Bitsx size x 8
- Divideby the rate
- Delaywhen full
What counts toward the contracted rate
A rate is counted over some number of bytes per packet, and the choice changes the answer for small packets. A provider may count the Ethernet frame only, or the frame plus the 8-byte preamble and the 12-byte gap that follows it. The edge's shaper may count another way again. Compute the difference for the packets you carry.
One way counts only the frame bytes. The other counts the frame plus the 8-byte preamble and the 12-byte gap that follows it, which is what the line really carries.
| Frame | Size | Bytes on the wire | Extra for preamble and gap |
|---|---|---|---|
| Smallest Ethernet frame | 64 bytes | 84 | 31.3 percent |
| G.711 voice with encapsulation | 288 bytes | 308 | 6.9 percent |
| Largest standard frame | 1,518 bytes | 1,538 | 1.3 percent |
On a link full of small packets, the difference between the two ways of counting is large. On a link of large packets it is small. That is one more reason for shaping a few percent below the contracted rate and for confirming with the provider which bytes they count.
The difference bites hardest when the two sides count differently. Suppose the provider counts the preamble and gap against a 100 Mbps contract, and the edge's shaper counts frame bytes only, at 95 Mbps. The table shows the rate the provider sees for three frame sizes.
| Frame size | Rate the provider sees | Fits a 100 Mbps contract? | Highest shaper rate that fits |
|---|---|---|---|
| 64 bytes | 124.7 Mbps | No | 76.2 Mbps |
| 288 bytes (G.711 voice) | 101.6 Mbps | No | 93.5 Mbps |
| 1,518 bytes | 96.3 Mbps | Yes | 98.7 Mbps |
Learn more: QoS Counters and Queue-Drop TroubleshootingQoS Concepts: Marking, Queueing and Shaping
Test yourself
What is the main difference between a policer and a shaper?
A shaper is set to 95 Mbps with a burst of 475,000 bits. What is its interval?
The edge is shaped to 95 Mbps on a 100 Mbps contract, yet bursts are dropped. Which cause fits?
A queue holds 1,000 packets of 1,200 bytes and drains at 95 Mbps. How much delay does a full queue add?
Why does counting preamble and gap matter more for voice than for bulk data?
The provider polices at 100 Mbps with an assumed bucket of 120,000 bits, on a 1 Gbps port. A shaper burst of 200,000 bits arrives at full port speed. What share of the burst is dropped?
A shaper counts frame bytes only and is set to 95 Mbps. The provider counts frame plus preamble and gap against a 100 Mbps contract. All the traffic is 288-byte voice frames. What rate does the provider see?
Which shaper burst fits an assumed provider bucket of 120,000 bits on a 100 Mbps policer, with the shaper's port at 1 Gbps?