urllib slow on FreeBSD 4.7? sockets too
Jarkko Torppa
torppa at staff.megabaud.fi
Fri Nov 22 04:13:30 EST 2002
In article <3ddd8419_3 at omega.dimensional.com>, Mike Brown wrote:
> As was pointed out, all the delay is in the reading, and it really only
> happens when dealing with these file-wrapped sockets as returned by
> urlopen(). They can be on the localhost, even.
Seems that stdio is somehow confused, try this
import urllib, time, os
starttime = time.time()
u = urllib.urlopen('http://localhost/4m')
fn = u.fp.fileno()
bytea = [ ]
while 1:
bytes = os.read(fn, 16 * 1024)
if bytes == '':
break
bytea.append(bytes)
bytes = ''.join(bytea)
u.close()
endtime = time.time()
elapsed = endtime - starttime
length = len(bytes)
print "bytes: %.1fK; time: %0.3fs (%0d KB/s)" % (length / 1024.0, elapsed, length / 1024.0 / elapsed )
On my NetBSD box this gives
bytes: 4096.0K; time: 0.450s (9105 KB/s)
0.15s user 0.08s system 44% cpu 0.513 total
vs
bytes: 4096.0K; time: 14.616s (280 KB/s)
2.52s user 11.57s system 96% cpu 14.676 total
--
Jarkko Torppa, Elisa Internet
More information about the Python-list
mailing list