[En-Nut-Discussion] New TCP output buffering
Oliver Schulz
olischulz at web.de
Wed Jan 14 21:46:57 CET 2004
Hi,
I commited some changed files in CVS, which implement a new TCP output
buffering (based on the idea of Dusan Ferbas).
Like before, buffering is used in 'NutTcpWriteDevice'. This function is
called, if you use file streaming with TCP sockets (fdopen (sock,..)).
In general, the internal output buffer is now ALWAYS filled, until it is
full. Then it will be send to the nic.
The buffer size can be configured by calling NutTcpSetSockOpt with new
option type SO_SNDBUF.
Please be aware, that this buffer is taken from heap memory! If no data is
in buffer the reserved heap memory is freed.
If not configured, the default buffer size is set to TCP_MSS, which is
defined as 536 bytes.
If using ip sockets on ethernet hardware, I suggest to adjust the buffer
size and maximum segment size (MSS). The maximum transfer unit (MTU) on
ethernet LAN is 1514 bytes (without crc). Subtracting the overhead for
ethernet, ip and tcp frame, the maximum segment size is 1460 bytes on a LAN.
Configuring could be read like this:
u_short us = 1460;
NutTcpSetSockOpt (sock, TCP_MAXSEG, &us, sizeof(us));
NutTcpSetSockOpt (sock, SO_SNDBUF, &us, sizeof(us));
Note: After connection has established, the buffer size is always limited to
the maximum segment size, because a bigger buffer size than maximum transfer
size doesn't make sense and will track down performance.
Here some performance values:
I testet the new code with Ethernut 2 connected to a ethernet switch. I
established a TCP connection port 9 (discard) to a Win2k server connected to
the same switch. Then exacly 8MB (8*1024*1024) of random data were
transmitted to the PC. I measured the time with MS Network Monitor supplied
with Win2K server.
Without any buffer configuration, I reached a transfer rate of 269,4 KB/s
including SYN and FIN packets.
With buffer configuration like above, I noticed a transfer rate of 343,8
KB/s.
This are of course the maximum transfer rates reached by a short testing
program, which does nothing else than this TCP transfer.
If any problems with this new code appear, please discuss it in this list.
Thanks and regards,
Oliver.
More information about the En-Nut-Discussion
mailing list