Python socket performance testing

Bruce Fletcher befletch at my-deja.com
Sat Jun 26 01:53:53 EDT 1999


I have Python 1.5.1 on a Mac (G3/233) and a Linux box (Celeron/366).
These are connected by 10BT ethernet, and I get good speed with normal
HTTP and FTP clients/servers.  Curiously, I can't seem to get good speed
(yet) in transfering data from Python to Python on the two machines.

Here's some excerpts from my client/server code:

#client: (Mac)
	data = 'a' * 1024

	sock = socket( AF_INET, SOCK_STREAM )
	sock.connect( SERVER, DATA_PORT )

	loops = 1024
	t1 = time.clock()
	while loops > 0:
		sock.send( data )
		loops = loops - 1
	reply = sock.recv(128)
	t2 = time.clock()
	sock.close()

	print 'Test time:', t2 - t1, 'seconds.'

#server: (Linux)
	sock = socket( AF_INET, SOCK_STREAM )
	sock.bind( '', DATA_PORT )
	sock.listen(1)

	conn, addr = sock.accept()

	loops = 1024

	while loops > 0:
		data = conn.recv(1024)
		loops = loops - 1

	conn.send('ok')
	conn.close()

This 1 meg transfer takes 73 seconds!  That works out to 14 kb/sec or so,
which isn't exactly blinding.  Am I doing something silly in my test?  I
suppose I should go test this just on the Linux box, just on the Mac,
etc. but I'm not too confident in my Python code yet so I thought I'd ask
for pointers.

Something else interesting; time.clock() doesn't seem to work on Linux
(RedHat 6.0) in either 1.5.1 or 1.5.2.  The time is always < 1, and it
doesn't change.

Thanks,
- Bruce


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.




More information about the Python-list mailing list