[zeromq-dev] patch: handle idle connections

Dhammika Pathirana dhammika at gmail.com
Thu Mar 26 16:38:48 CET 2009

Yes, this is way better.
But we'll have inserts/deletes in the middle.

1. New connections going directly to active, we can work around this.
    pipes.push_back (pipe);
    std::swap (pipes[pipes.end () - 1], pipes[active]);

2. Connection shutdown, this'll shift later elements.
    pipes.erase (it)

Would this be a problem for short lived connections?


On Thu, Mar 26, 2009 at 6:16 AM, Martin Sustrik <sustrik at fastmq.com> wrote:
>> Here's a diagram of flipping active to passive (or vice versa)...
> The same thing in pseudocode:
> vector <pipe_t*> pipes;
> int active; // number of active pipes
> int current; // index of the current pipe in the array
> To get next active pipe:
> current = (current + 1) % active;
> return pipes [current];
> To flip pipe x from active to passive state:
> std::swap (pipes [x], pipes [active - 1]);
> active--;
> To flip pipe x from passive to active state:
> std::swap (pipes [x], pipes [active]);
> active++;
> A side note: I've did an analysis of the algorithm and although it looks
> kind of strange it actually turns out that it provides fairness guarantee in
> the presence of network hickups (connections flipped to passive and then to
> active almost immediately). Interestingly enough, obvious solutions (like
> maintaining two linked lists or having a single array with each element
> flagged as active/passive) don't provide this guarantee. If anyone is
> interested in the math, I can provide it.
> Martin

More information about the zeromq-dev mailing list