Course contentsShow
← Linux
Lesson 1102 of 1,81910. Network Administration and Kernel StacksFree lesson

Traffic Shaping and Queuing Disciplines

Apply traffic control algorithms to prioritize bandwidth for critical services.

In this lesson, you will learn how to orchestrate the Linux kernel’s queuing disciplines (qdiscs) to prioritize critical network services over background traffic.

The Problem of Bufferbloat

When your network interface becomes saturated, the kernel buffers packets before sending them out. If left unmanaged, these buffers fill up, leading to high latency (bufferbloat) where critical traffic—like a heartbeat signal for a trading engine or an API response—gets stuck behind bulk data transfers. To solve this, we use Traffic Control (tc) to attach queuing disciplines to our interfaces.

Implementing a Priority Queue

The most common approach for prioritizing traffic is the prio qdisc. It functions by creating multiple "bands" (queues) with different priority levels. The kernel always drains the highest priority band first; as long as there is data in Band 0, lower-priority bands will not be touched.

You can configure this using the tc command. Here is how you might set up a simple priority structure on eth0:

# Add a priority qdisc with 3 bands
tc qdisc add dev eth0 root handle 1: prio bands 3

# Attach a Token Bucket Filter (TBF) to band 0 to rate-limit or shape critical traffic
tc qdisc add dev eth0 parent 1:1 handle 10: tbf rate 100mbit burst 32kbit latency 400ms

By default, the kernel maps traffic to these bands using the Type of Service (ToS) bits in the IP header. If you are running a microservice or an AI-heavy workload, you can configure your application to set specific DSCP values, which the prio qdisc will automatically map to the high-priority queues.

Why this matters

By shaping traffic at the egress point, you ensure that even during network congestion, your critical services maintain the low-latency guarantees required for high-frequency operations. Instead of letting the "best effort" delivery model of standard Ethernet decide which packet leaves first, you are forcing the kernel to respect your business logic at the hardware interface level.

Key Takeaway: Queuing disciplines allow you to bypass standard "first-come, first-served" network behavior, ensuring critical traffic is prioritized via kernel-level scheduling.