[Qt-interest] QTcpSocket performance over long, fat networks

Stephen Collyer scollyer at netspinner.co.uk
Fri Aug 7 11:27:26 CEST 2009


I've been investigating poor performance with QTcpSocket over long
fat networks i.e. those with a large bandwidth-delay products and have
found the problem.

For some reason, all Qt explicitly sets the send and receive buffers to
48K bytes in src/network/socket/qnativesocketengine.cpp:

    // Set the send and receive buffer sizes to a magic size, found
    // most optimal for our platforms.
    setReceiveBufferSize(49152);
    setSendBufferSize(49152);

I would guess that this code has been present from very early
versions of Qt, since it's sub-optimal nowadays. Modern TCP stacks
perform auto-tuning of the socket send and receive buffers automatically,
in order to achieve maximum throughput on LFNs. However, this
is disabled if the buffers are set explicitly, which means that all
QTcpSocket
based programs are going to demonstate poor performance over LFNs.

In addition, the Qt API provides no way to disable the code shown above
on a socket-by-socket basis, and the API doesn't expose the
setReceiveBufferSize/setSendBufferSize methods, so the only way
to work around the problem is by platform specific calls to setsockopt
to set SO_SNDBUF and SO_RCVBUF.

For example, in a class derived from QTcpSocket, I do something like
the following:

listen(our_host_, our_port_);

int socket = socketDescriptor();
int send_buffer_size = <some big value>;
int send_err = setsockopt(socket, SOL_SOCKET, SO_SNDBUF, (char
*)&send_buffer_size, (int)sizeof(send_buffer_size));

int receive_buffer_size = <some big value>;
int receive_err = setsockopt(socket, SOL_SOCKET, SO_RCVBUF, (char
*)&receive_buffer_size, (int)sizeof(receive_buffer_size));

-- 
Stephen Collyer
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090807/bacbd37b/attachment.html 


More information about the Qt-interest-old mailing list