[issue3766] socket.socket.recv broken (unbearably slow)

Antoine Pitrou report at bugs.python.org
Thu Sep 11 18:25:32 CEST 2008

Antoine Pitrou <pitrou at free.fr> added the comment:

You can use setsockopt() to set the TCP_NODELAY flag and see if that
improves things; sending thousands of 4-bytes packets isn't exactly the
expected utilization of TCP.

As I said, socket.recv() is just a thin wrapper above the same-named C
library function. Your code expects the kernel's TCP stack to send
things as soon as you ask it to, but TCP is a high-level stream protocol
and implementations usually have sophisticated algorithms in order to
minimize the number of individual packets sent over the wire.

By the way, if you want to build network applications (clients and
servers), I suggest you take a look at the Twisted framework. It will
free you from many low-level issues, although it won't prevent you from
shooting yourself in the foot :-)

Python tracker <report at bugs.python.org>

More information about the Python-bugs-list mailing list