[Verse-dev] Server Latency

Emil Brink emil at obsession.se
Fri Mar 4 08:36:36 CET 2005


Eskil,

I talked to Marcus Hoffmann of FHG after our meeting yesterday, and he
pointed out that the current reference server has latency issues. I
didn't understand his point at first, but then later yesterday evening
it hit me... Thanks, Marcus!

Assuming the server has N clients C[0] to C[N-1] connected, the thing
the main loop does is basically this:

      forever
	for i in 0 to N
	  wait for traffic(C[i].socket, max T seconds)
	    read all available packets
	    process packets

Now, I was thinking "that wait is done by select(), it won't block for
longer than it takes for a packet to arrive", but I was completely
missing the fact that it does so only for _ONE_ socket at a time.

If the server is waiting for traffic from client C[0], and a thousand
packets arrive from client C[N-1], it won't hear about it until after
it has gone through the N-2 clients inbetween, which will take all of
T*(N-2) seconds in the worst case... Not good!

The thing that is incorrect is that the server uses select() on just
one socket at a time, thus completely missing the point of the select()
system call. It should be used by adding _all_ interesting sockets to
the fd_set, then waiting, then reading from all sockets that signalled
they receive something.

I looked at the code for Verse1, and that is how it's done there, too.

Now, am I (and Marcus?) still misunderstanding this, or is it in fact
very latency-prone with more than one client connected?

Regards,

/Emil


More information about the Verse-dev mailing list