The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
SDL_net setting TCP_NODELAY / removing latency
Juha Laitinen
Guest

Hi!

I have been working with a distributed rendering library, BGL. The
lib distributes OpenGL API calls to multiple rendering slaves using
UDP broadcasts and the slaves send small ack packets back to the host
using TCP. Previously a proprietary tcp socket implementation was
used but we wanted to make the impl as portable as possible so we
decided to replace that with SDL_net.

The problem is that there seems to be no way to set delay options for
TCP sockets, to remove the buffering of the small replies and reduce
latency.

By examining the source code (SDL_net 1.2.5 release) we found that
there is code in place for setting the TCP_NODELAY sockets by default:

SDLnetTCP.c:
#ifdef TCP_NODELAY
...
setsockopt(sock->channel, IPPROTO_TCP, TCP_NODELAY, (char*)&yes,
sizeof(yes));

Obviously there has been discussion about the option since the
CHANGES file suggested setting TCP_NODELAY by default for version
1.1.0. But the build does not include the code (no -DTCP_NODELAY).
Well, I resolved this by removing the ifdefs and recompiling the
library =) Could there be a configure option for this? Would be more
convenient I guess.

To resolve this issue for both sides (throughput vs. latency), could
there be an API function to enable/disable the TCP_NODELAY flag for
sockets, where possible?

At least for linux systems, there seems to be alternative way to
configure the behavior of TCP sockets: tuning tcp options in the
kernel directly. Check out http://www.psc.edu/networking/projects/
tcptune/#Linux or your kernel sourcecode documentation typically at /
usr/src/linux-<version>/Documentation/networking/ip-sysctl.txt .. For
at least in kernel 2.6.13 there is a option:

tcp_low_latency - BOOLEAN
If set, the TCP stack makes decisions that prefer lower
latency as opposed to higher throughput. By default, this
option is not set meaning that higher throughput is preferred.
An example of an application where this default should be
changed would be a Beowulf compute cluster.
Default: 0

It is possible to set this option with command:
sysctl -w net.ipv4.tcp_low_latency=1

I have no idea that does the kernel option behave like setting
TCP_NODELAY. Worth to try anyways, I guess.

--
Juha