Queue Types
Queue Types
Section titled “Queue Types”Queue types define the packet scheduling algorithm (also known as queueing discipline or qdisc) that determines how packets are transmitted when bandwidth becomes available. Selecting the appropriate queue type is fundamental to implementing effective Quality of Service (QoS) on your MikroTik router.
RouterOS provides several built-in queue types, each designed for specific traffic management scenarios. Understanding the characteristics and trade-offs of each queue type enables you to implement bandwidth controls that match your network requirements.
Overview
Section titled “Overview”Queue types operate at the heart of RouterOS traffic shaping infrastructure. They determine the order in which packets leave the interface queue, how bandwidth is distributed among multiple traffic flows, and how the router responds to congestion.
When packets arrive faster than they can be transmitted, they accumulate in a queue. The queue type defines the algorithm that decides which packet gets transmitted next. This choice directly impacts latency, jitter, throughput, and fairness of bandwidth distribution among your users and applications.
The choice of queue type depends on your specific requirements:
| Requirement | Recommended Queue Type |
|---|---|
| Simple packet buffering | PFIFO/BFIFO |
| Equal bandwidth sharing among users | PCQ |
| Fairness among concurrent connections | SFQ |
| Congestion control with early drops | RED |
| Hierarchical bandwidth shaping | HTB |
| Bufferbloat elimination (AQM only) | FQ-CoDel |
| Bufferbloat elimination with integrated shaping | CAKE |
Queue Types at a Glance
Section titled “Queue Types at a Glance”RouterOS supports the following queue type kinds:
| Kind | Description | Best For |
|---|---|---|
| bfifo | Byte-based FIFO | Byte-level buffer limits |
| pfifo | Packet-based FIFO | Simple packet buffering |
| pcq | Per Connection Queue | Equal bandwidth distribution |
| sfq | Stochastic Fairness Queuing | Fairness among connections |
| red | Random Early Detection | Active Queue Management |
| htb | Hierarchical Token Bucket | Hierarchical traffic shaping |
| fq-codel | Fair Queuing Controlled Delay | Bufferbloat elimination with per-flow fairness |
| cake | Common Applications Kept Enhanced | Integrated AQM + shaping for WAN links |
FIFO Queue Types
Section titled “FIFO Queue Types”PFIFO (Packet First-In, First-Out) and BFIFO (Byte First-In, First-Out) are the simplest queue types available. Both implement basic FIFO logic where the first packet to arrive is the first packet transmitted.
PFIFO (Packet First-In, First-Out)
Section titled “PFIFO (Packet First-In, First-Out)”PFIFO manages queue capacity based on the number of packets waiting for transmission. Each packet occupies one queue slot regardless of its size. This provides predictable memory usage but can lead to inefficient bandwidth utilization when packet sizes vary significantly.
Key characteristics:
- Queue limit measured in packet count
- Predictable memory usage
- No prioritization capability
- Minimal CPU overhead
Configuration:
/queue type add name="PFIFO-100" kind=pfifo fifo-limit=100BFIFO (Byte First-In, First-Out)
Section titled “BFIFO (Byte First-In, First-Out)”BFIFO operates identically to PFIFO but measures queue fullness in bytes rather than packets. This provides more accurate bandwidth control when packets vary significantly in size.
Key characteristics:
- Queue limit measured in bytes
- Better bandwidth control with variable packet sizes
- Slightly higher CPU overhead than PFIFO
- No prioritization capability
Configuration:
/queue type add name="BFIFO-500KB" kind=bfifo bfifo-limit=500000When to use FIFO:
- Simple traffic buffering without QoS requirements
- Situations where downstream devices handle all prioritization
- Memory-constrained environments requiring predictable buffer usage
For detailed configuration and parameter explanations, see the PFIFO, BFIFO documentation.
PCQ (Per Connection Queue)
Section titled “PCQ (Per Connection Queue)”PCQ is one of the most powerful and frequently used queue types in RouterOS. It dynamically divides traffic among multiple sub-streams based on a classifier, making it ideal for equal bandwidth sharing among multiple users or connections.
How PCQ Works
Section titled “How PCQ Works”When you configure a PCQ queue type, the router automatically creates separate sub-queues for each unique value of the configured classifier. For example, if you use dst-address as the classifier, PCQ creates a separate sub-queue for each destination IP address, ensuring each user receives equal bandwidth.
Key characteristics:
- Automatic per-user/connection bandwidth distribution
- Dynamic sub-queue creation based on traffic classifiers
- Configurable maximum rate limits
- Supports burst for temporary speed increases
Common classifiers:
| Classifier | Creates Sub-queue For |
|---|---|
| dst-address | Each destination IP (download) |
| src-address | Each source IP (upload) |
| dst-port | Each destination port |
| src-port | Each source port |
| src-and-dst-address | Each unique IP pair |
Configuration example:
/queue type add name="PCQ_download" kind=pcq pcq-rate=10M pcq-classifier=dst-address/queue type add name="PCQ_upload" kind=pcq pcq-rate=2M pcq-classifier=src-addressWhen to use PCQ:
- Equal bandwidth sharing among multiple users
- Per-IP bandwidth limiting in shared networks
- Hotspot bandwidth management
- Guest network bandwidth control
For detailed configuration examples and deployment scenarios, see the PCQ Example documentation.
SFQ (Stochastic Fairness Queuing)
Section titled “SFQ (Stochastic Fairness Queuing)”SFQ (Stochastic Fairness Queuing) attempts to provide fair bandwidth distribution among multiple TCP/IP flows by hashing packet addresses and ports into a limited number of sub-queues. This approach ensures that no single connection can dominate the queue.
How SFQ Works
Section titled “How SFQ Works”SFQ uses a hashing algorithm to categorize packets into a configurable number of sub-queues (buckets). The hash is calculated from source and destination IP addresses and port numbers. Each sub-queue is then serviced in round-robin fashion, ensuring that all flows get equal opportunity to transmit.
Key characteristics:
- Fair distribution among concurrent connections
- Reduces head-of-line blocking
- Uses hashing (not perfect fairness)
- Configurable queue depth
Configuration:
/queue type add name="SFQ-default" kind=sfq sfq-allows=128 sfq-flows=128 sfq-hash=algo/ipParameters:
| Parameter | Description | Default |
|---|---|---|
| sfq-allows | Number of sub-queues | 128 |
| sfq-flows | Number of flows per sub-queue | 128 |
| sfq-hash | Hash algorithm | algo/ip |
When to use SFQ:
- Fair distribution among concurrent connections
- P2P traffic management
- Situations where you want rough fairness without PCQ complexity
- When you need to prevent single connections from monopolizing bandwidth
RED (Random Early Detection)
Section titled “RED (Random Early Detection)”RED (Random Early Detection) is an Active Queue Management (AQM) technique that proactively drops packets before the queue becomes full. This helps prevent TCP congestion avoidance algorithms from triggering globally synchronized drops across all connections.
How RED Works
Section titled “How RED Works”RED monitors average queue size and begins randomly dropping packets when the average exceeds a minimum threshold. As the average queue size approaches the maximum threshold, the drop probability increases. This approach signals congestion to TCP senders before queue overflow occurs, resulting in smoother, more gradual congestion response.
Key characteristics:
- Proactive packet dropping before queue overflow
- Prevents global TCP synchronization
- Configurable min/max thresholds and drop probabilities
- Works only with TCP traffic (primarily)
Configuration:
/queue type add name="RED-default" kind=red red-limit=128 red-min-threshold=10 red-max-threshold=50 red-burst=20 red-avg-packet=1000Parameters:
| Parameter | Description | Typical Range |
|---|---|---|
| red-limit | Maximum queue size (packets) | 64-256 |
| red-min-threshold | Minimum queue threshold | 10-30 |
| red-max-threshold | Maximum queue threshold | 40-100 |
| red-burst | Burst allowance | 10-40 |
| red-avg-packet | Average packet size | 1024-1500 |
When to use RED:
- Reducing latency variance during congestion
- Preventing TCP global synchronization
- Bulk transfer optimization
- Networks with varying congestion levels
HTB (Hierarchical Token Bucket)
Section titled “HTB (Hierarchical Token Bucket)”HTB (Hierarchical Token Bucket) is the fundamental queueing discipline underlying all RouterOS queuing. It implements hierarchical token bucket shaping that allows you to create complex bandwidth allocation structures with parent and child queues.
How HTB Works
Section titled “How HTB Works”HTB organizes queues in a hierarchy where parent queues can borrow bandwidth from their siblings when available. Each queue operates based on token bucket principles - packets wait for tokens to become available before transmission. This approach enables sophisticated bandwidth sharing where different classes of traffic can be guaranteed minimum bandwidth while sharing unused capacity.
Key characteristics:
- Hierarchical queue structure
- Guaranteed minimum bandwidth (CIR)
- Bandwidth borrowing between queues
- Priority-based servicing
Configuration:
/queue type add name="HTB-parent" kind=htb/queue tree add parent=global queue=HTB-parentWhen to use HTB:
- Hierarchical QoS implementations
- Complex bandwidth allocation schemes
- Traffic classification with guaranteed minimums
- When you need parent queues to manage child queue relationships
HTB is used implicitly in all RouterOS queue trees and simple queues. For detailed HTB configuration, see the HTB documentation.
Choosing the Right Queue Type
Section titled “Choosing the Right Queue Type”Selecting the appropriate queue type requires understanding your specific requirements and the characteristics of each option.
Decision Framework
Section titled “Decision Framework”- Simple buffering only? → Use PFIFO or BFIFO
- Equal sharing among users? → Use PCQ
- Fairness among connections? → Use SFQ
- Proactive congestion management? → Use RED
- Complex hierarchical shaping? → Use HTB
Common Combinations
Section titled “Common Combinations”Often, you will combine queue types in hierarchical structures:
- HTB parent with PCQ children - Hierarchical bandwidth allocation with per-user fairness
- HTB parent with SFQ children - Traffic classes with connection-level fairness
- HTB parent with RED children - Traffic classes with proactive congestion management
- PCQ for user fairness within traffic classes - Most common production configuration
Production Example
Section titled “Production Example”A typical ISP or enterprise configuration might look like:
/queue typeadd name=PCQ_download kind=pcq pcq-rate=10M pcq-classifier=dst-addressadd name=PCQ_upload kind=pcq pcq-rate=2M pcq-classifier=src-address
/queue treeadd parent=global queue=PCQ_download packet-mark=downloadadd parent=global queue=PCQ_upload packet-mark=uploadThis provides 10Mbps download and 2Mbps upload shared equally among all users.
Queue Type Parameters Reference
Section titled “Queue Type Parameters Reference”Common Parameters
Section titled “Common Parameters”| Parameter | Description | Applies To |
|---|---|---|
| kind | Queue type algorithm | All |
| name | Unique identifier | All |
| queue | Parent queue reference | Tree queues |
FIFO Parameters
Section titled “FIFO Parameters”| Parameter | Description | Range |
|---|---|---|
| fifo-limit | Max packets in queue | 0-65535 |
| bfifo-limit | Max bytes in queue | 0-4294967295 |
PCQ Parameters
Section titled “PCQ Parameters”| Parameter | Description | Range |
|---|---|---|
| pcq-rate | Maximum total bandwidth | 0-100000000000 |
| pcq-classifier | Traffic classifier | dst-address, src-address, ports |
| pcq-limit | Max sub-queues | 1-100000 |
| pcq-burst-rate | Burst data rate | 0-100000000000 |
| pcq-burst-threshold | Burst threshold | 0-100000000000 |
| pcq-burst-time | Burst time window | 1s-60s |
SFQ Parameters
Section titled “SFQ Parameters”| Parameter | Description | Range |
|---|---|---|
| sfq-allows | Number of sub-queues | 1-128 |
| sfq-flows | Flows per sub-queue | 1-128 |
| sfq-hash | Hash algorithm | algo/ip |
RED Parameters
Section titled “RED Parameters”| Parameter | Description | Range |
|---|---|---|
| red-limit | Max queue size | 0-4294967295 |
| red-min-threshold | Min threshold | 0-4294967295 |
| red-max-threshold | Max threshold | 0-4294967295 |
| red-burst | Burst allowance | 0-4294967295 |
| red-avg-packet | Average packet size | 0-4294967295 |
HTB Parameters
Section titled “HTB Parameters”| Parameter | Description | Range |
|---|---|---|
| htb-rate | Guaranteed rate | 0-100000000000 |
| htb-ceil | Maximum rate | 0-100000000000 |
| htb-priority | Queue priority | 1-8 |
| htb-burst-rate | Burst rate | 0-100000000000 |
| htb-burst-threshold | Burst threshold | 0-100000000000 |
| htb-burst-time | Burst time | 1s-60s |
Related Resources
Section titled “Related Resources”- PFIFO, BFIFO Documentation - Detailed FIFO queue type configuration
- PCQ Example - Per Connection Queue implementation guide
- CAKE and FQ-CoDel - FQ-CoDel, CAKE algorithm details and bufferbloat setup
- Queue Tree - Hierarchical queue configuration
- Simple Queues - Easy-to-use queue configuration
- Queue Size - Understanding and configuring queue buffers
- Official MikroTik Queueing Documentation