【发布时间】:2015-02-26 08:09:07
【问题描述】:
我正在使用这段代码下载 mp3 播客。
req = urllib2.urlopen(item)
CHUNK = 16 * 1024
with open(local_file, 'wb') as fp:
while True:
chunk = req.read(CHUNK)
if not chunk: break
fp.write(chunk)
哪个效果很好 - 但我想知道最佳下载性能的最佳块大小是多少?
如果有什么不同,我使用的是 6mbit adsl 连接。
【问题讨论】:
-
这是一个很好的问题,但不是 urllib2/python 特定的。请参阅stackoverflow.com/a/2811047/98057 以获得很好的答案。你确定这需要优化吗?尝试基准测试。比较 wget:ing 文件。