Client-side TCP socket receiving "Address already in use" upon connect

Alex Martelli aleax at mac.com
Sun Sep 3 15:19:58 EDT 2006


Felipe Almeida Lessa <felipe.lessa at gmail.com> wrote:

> 2006/9/3, Alex Martelli <aleax at mac.com>:
> > Reflecting on the OP's use case, since all connections are forever being
> > made to the same 16 servers, why not tweak thinks a bit to hold those
> > connections open for longer periods of time, using a connection for many
> > send/receive "transactions" instead of opening and closing such
> > connections all of the time?  That might well work better...
> 
> Connecting to 16 differente servers per second gives a very poor
> performance, right? There's some overhead in creating TCP connections,
> even on fast networks and computers. Am I right?

There is some overhead, yes, but 16 connections per second are few
enough that I wouldn't expect that to be material (on networks with low
latency -- it might be different if you have "long fat pipes", networks
with huge bandwidth and thus "fast" but with high latency -- several
aspects of TCP/IP don't work all that well with those).

For example, try tweaking examples 1 and 2 for chapter 19 of "Python in
a Nutshell" (you can freely download the zipfile w/all examples from
<http://examples.oreilly.com/pythonian/pythonian-examples.zip>) and do
some experiments.  I ran the unmodified server on an iBook G4, and on a
Macbook Pro I ran a client that looped 100 times, connecting, sending
'ciao', receiving the response, and printing a timestamp and the
response just received -- with the two laptops, sitting next to each
other, connected via Ethernet (just 100 mbps on the iBook, thus the
gigabit ethernet on the MBP wasn't really being used well;-) through a
direct cable (using ifconfig by hand to make a tiny 192.168.1/24 LAN
there;-).  The 100 iterations, all together, took a bit more than half a
second (and, of course, one could try tweaking the asyncore or Twisted
examples from the same chapter to let many connections happen at once,
rather than having them "in sequence" as I just did - and many other
such small but interesting experiments).  As a further data point, I
then reran the same experiment after removing the Ethernet cable, so
that the laptops were now connecting through wi-fi (802.11g, 54mbps, the
router being an Airport Express -- everything in the same room, within a
radius of 2 meters, excellent signal reception of course;-): ran in this
way, the 100 iterations took a total of over 2 seconds.


Alex



More information about the Python-list mailing list