SocketServer and makefile()

Donn Cave donn at u.washington.edu
Thu Aug 31 12:31:18 EDT 2000


Quoth "Andy Bond" <bond at dstc.edu.au>:
| I've been working with BaseHTTPServer which in turn uses SocketServer to
| write a little web server.  It is used to accept PUT requests of 30MB chunks
| of data.  I was having a problem where data was flowing at the rate of
| something like 64K per second over a 100MB network.  Weird.  Further tracing
| showed that the rfile variable from SocketServer (used to suck in data to
| the http server) was created using makefile on the original socket
| descriptor.  It was created with an option of zero for buffering (see
| SocketServer.py) which means unbuffered.
|
| Now some separate testing with socket.py showed that I could whip a 30MB
| file across using plain sockets and send/recv but if I made the receivor use
| makefile on the socket and then read, it slowed down to my 1 sec per 64K.
| If I specify a buffer (something big but less than 64K ... IP packet size?)
| then I am back in speedy territory.  The unbuffered mode seems almost like
| it is sending the data 1 char at a time AND this is the default mode used in
| SocketServer and subsequently BaseHTTPServer ...
|
| This is on solaris 7, python 1.5.2.  Anyone else found this to be a problem
| or am I doing something wrong?

A simple test program running under "truss" bears out your surmise.
Here it is, reading your one byte at a time.

  read(0x7,0x2820027b,0x1)                         = 1 (0x1)
  read(0x7,0x2820027b,0x1)                         = 1 (0x1)
  read(0x7,0x2820027b,0x1)                         = 1 (0x1)
  read(0x7,0x2820027b,0x1)                         = 1 (0x1)
  read(0x7,0x2820027b,0x1)                         = 1 (0x1)
  ... etc. ad gross waste of timum.

	Donn Cave, donn at u.washington.edu



More information about the Python-list mailing list