[ANN] wfq - an implementation of the weighted fair queue algorithm

554 views
Skip to first unread message

Tad Glines

unread,
Oct 22, 2014, 6:53:49 PM10/22/14
to golang-nuts
So I need to mux data over a single connection and wanted to prevent one flow from hogging the link. The weighted fair queue algorithm seems like a good solution.

I've implemented the algorithm in this package:

I welcome comments and suggestions.

One potential comment I'll address up front.
I chose not to use channels for two reasons:
1. Entry into the queue cannot be assessed pre-consumption when using channels.
2. While go routines are cheep, they are not free. The stack cost of 8K per goroutine adds up when you get in the 10's/100's of thousands of goroutines.

I find it easy to reason about conditionals so that's what I chose to use. I'm not opposed to channel based implementation suggestions as long as those suggestions would not lead to a loss of performance or an increase increase in complexity.

My primary concern is making sure that the queue actually behaves like a weighted fair queue. I'm fairly certain that it does in the case where all flows have the same weight. But, the one test that uses mixed weights only goes so far as to test that the higher priority flow finishes first. I'm also not entirely happy with TestMultiFlow because there is an element of probability to it seems unavoidable.

-Tad

Job van der Zwan

unread,
Oct 23, 2014, 3:32:13 AM10/23/14
to golan...@googlegroups.com
> type Interface interface

Having trouble coming up with an appropriate name?

Caleb Spare

unread,
Oct 23, 2014, 3:42:38 AM10/23/14
to Job van der Zwan, golang-nuts
Presumably it's a queue interface in the vein of sort.Interface[0] or heap.Interface[1].


On Thu, Oct 23, 2014 at 12:32 AM, Job van der Zwan <j.l.van...@gmail.com> wrote:
> type Interface interface

Having trouble coming up with an appropriate name?

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Tad Glines

unread,
Oct 23, 2014, 10:14:18 AM10/23/14
to Caleb Spare, Job van der Zwan, golang-nuts
Correct. I thought of names like "Weighter" or "Classifier", or "Helper" but in the end I figured that the most idiomatic choice would be to do the same as the sort and heap packages.

Job van der Zwan

unread,
Oct 23, 2014, 3:41:28 PM10/23/14
to golan...@googlegroups.com, ces...@gmail.com, j.l.van...@gmail.com
Huh, wasn't aware of that. Thanks for the explanation!
Reply all
Reply to author
Forward
0 new messages