Fair queuingis a family ofscheduling algorithmsused in someprocessandnetwork schedulers.The algorithm is designed to achievefairnesswhen a limited resource is shared, for example to prevent flows with large packets or processes that generate small jobs from consuming more throughput or CPU time than other flows or processes.
Fair queuing is implemented in some advancednetwork switchesandrouters.
History
editThe termfair queuingwas coined by John Nagle in 1985 while proposinground-robin schedulingin the gateway between alocal area networkand theinternetto reduce network disruption from badly-behaving hosts.[1][2][3]
A byte-weighted version was proposed by Alan Demers,Srinivasan KeshavandScott Shenkerin 1989, and was based on the earlier Nagle fair queuing algorithm.[4][5]The byte-weighted fair queuing algorithm aims to mimic a bit-per-bit multiple xing by computing theoretical departure date for each packet.
The concept has been further developed intoweighted fair queuing,and the more general concept oftraffic shaping,where queuing priorities are dynamically controlled to achieve desired flowquality of servicegoals or accelerate some flows.
Principle
editFair queuing uses one queue perpacket flowand services them in rotation, such that each flow can "obtain an equal fraction of the resources".[1][2]
The advantage over conventionalfirst in first out(FIFO) orpriority queuingis that a high-data-rate flow, consisting of large packets or many data packets, cannot take more than its fair share of the link capacity.
Fair queuing is used in routers, switches, andstatistical multiplexersthat forward packets from abuffer.The buffer works as a queuing system, where the data packets are stored temporarily until they are transmitted.
With a link data-rate ofR,at any given time theNactive data flows (the ones with non-empty queues) are serviced each with an average data rate ofR/N.In a short time interval the data rate may fluctuate around this value since the packets are delivered sequentially in turn.
Fairness
editIn the context of network scheduling,fairnesshas multiple definitions. Nagel's article usesround-robin schedulingof packets,[2]which is fair in terms of the number of packets, but not on the bandwidth use when packets have varying size. Several formal notions offairness measurehave been defined includingmax-min fairness,worst-case fairness,[6]andfairness index.[7]
Generalisation to weighted sharing
editThe initial idea gives to each flow the same rate. A natural extension consists in letting the user specify the portion of bandwidth allocated to each flow leading toweighted fair queuingandgeneralized processor sharing.
A byte-weighted fair queuing algorithm
editThis algorithm attempts to emulate the fairness of bitwise round-robin sharing of link resources among competing flows. Packet-based flows, however, must be transmitted packetwise and in sequence. The byte-weighted fair queuing algorithm selects transmission order for the packets by modeling the finish time for each packet as if they could be transmitted bitwise round robin. The packet with the earliest finish time according to this modeling is the next selected for transmission.
The complexity of the algorithm isO(log(n)),wherenis the number of queues/flows.
Algorithm details
editModeling of actual finish time, while feasible, is computationally intensive. The model needs to be substantially recomputed every time a packet is selected for transmission and every time a new packet arrives into any queue.
To reduce computational load, the concept ofvirtual timeis introduced. Finish time for each packet is computed on this alternate monotonically increasing virtual timescale. While virtual time does not accurately model the time packets complete their transmissions, it does accurately model the order in which the transmissions must occur to meet the objectives of the full-featured model. Using virtual time, it is unnecessary to recompute the finish time for previously queued packets. Although the finish time, in absolute terms, for existing packets is potentially affected by new arrivals, finish time on the virtual time line is unchanged - the virtual time line warps with respect to real time to accommodate any new transmission.
The virtual finish time for a newly queued packet is given by the sum of the virtual start time plus the packet's size. The virtual start time is the maximum between the previous virtual finish time of the same queue and the current instant.
With a virtual finishing time of all candidate packets (i.e., the packets at the head of all non-empty flow queues) computed, fair queuing compares the virtual finishing time and selects the minimum one. The packet with the minimum virtual finishing time is transmitted.
Pseudocode
edit
Shared variables const N // Nb of queues queues[1..N] // queues lastVirFinish[1..N] // last virtual finish instant | |
receive(packet) queueNum:= chooseQueue(packet) queues[queueNum].enqueue(packet) updateTime(packet, queueNum) |
updateTime(packet, queueNum) // virStart is the virtual start of service virStart:= max(now(), lastVirFinish[queueNum]) packet.virFinish:= packet.size + virStart lastVirFinish[queueNum]:= packet.virFinish |
send() queueNum:= selectQueue() packet:= queues[queueNum].dequeue() returnpacket |
selectQueue()
it:= 1
minVirFinish =
whileit ≤ Ndo
queue:= queues[it]
ifnotqueue.emptyandqueue.head.virFinish < minVirFinishthen
minVirFinish = queue.head.virFinish
queueNum:= it
it:= it + 1
returnqueueNum
|
The functionreceive() is executed each time a packet is received, andsend() is executed each time a packet to send must be selected,i.e.when the link is idle and the queues are not empty. This pseudo-code assumes there is a functionnow() that returns the current virtual time, and a functionchooseQueue() that selects the queue where the packet is enqueued.
The functionselectQueue() selects the queue with the minimal virtual finish time. For the sake of readability, the pseudo-code presented here does a linear search. But maintaining a sorted list can be implemented in logarithmic time, leading to aO(log(n))complexity, but with more complex code.
See also
editReferences
edit- ^abJohn Nagle:"On packet switches with infinite storage,"RFC970,IETF,December 1985.
- ^abcNagle, J. B. (1987). "On Packet Switches with Infinite Storage".IEEE Transactions on Communications.35(4): 435–438.CiteSeerX10.1.1.649.5380.doi:10.1109/TCOM.1987.1096782.
- ^Phillip Gross (January 1986),Proceedings of the 16-17 January 1986 DARPA Gateway Algorithms and Data Structures Task Force(PDF),IETF,pp. 5, 98,retrieved2015-03-04,
Nagle presented his "fair queuing" scheme, in which gateways maintain separate queues for each sending host. In this way, hosts with pathological implementations can not usurp more than their fair share of the gateway's resources. This invoked spirited and interested discussion.
- ^Demers, Alan; Keshav, Srinivasan; Shenker, Scott (1989)."Analysis and simulation of a fair queueing algorithm".ACM SIGCOMM Computer Communication Review.19(4): 1–12.doi:10.1145/75247.75248.
- ^Demers, Alan; Keshav, Srinivasan; Shenker, Scott (1990)."Analysis and Simulation of a Fair Queueing Algorithm"(PDF).Internetworking: Research and Experience.1:3–26.
- ^Bennett, J. C. R.; Hui Zhang (1996). "WF/sup 2/Q: Worst-case fair weighted fair queueing".Proceedings of IEEE INFOCOM '96. Conference on Computer Communications.Vol. 1. p. 120.doi:10.1109/INFCOM.1996.497885.ISBN978-0-8186-7293-4.S2CID17558577.
- ^Ito, Y.; Tasaka, S.; Ishibashi, Y. (2002). "Variably weighted round robin queueing for core IP routers".Conference Proceedings of the IEEE International Performance, Computing, and Communications Conference (Cat. No.02CH37326).p. 159.doi:10.1109/IPCCC.2002.995147.ISBN978-0-7803-7371-6.S2CID60787008.