English 中文(简体)
阅读袖珍和下载速度
原标题:Reading from sockets and download speed
  • 时间:2009-10-08 11:16:47
  •  标签:

就数字而言,我开发一名下载主管,我很想知道,从净额的一张表上看一大批数据(即80或100KB)是否使下载速度提高,而不是每张路程读4KB?

(平均下载速度为200KBPS,例如,我下载一个带有火f的档案)

感谢Nir Tayeb。

最佳回答

答案是NO

您的网络传输率(200kbps)表明,缓冲4k或8k或200k将难以改变。 所用时间太小。 瓶颈似乎是你的转移速度。

请用stackoverflow 30.9MB mp3 podcast:

NOTE: This is a unreliable hack whose results can be affected by a lot of factors - useful for demonstration purposes only)

import urllib2
import time

def report(start, size, text):
    total = time.time() - start
    print "%s reading took %d seconds, transfer rate %.2f KBPS" % (
            text, total, (size / 1024.0) / total)

start = time.time()
url = ( http://itc.conversationsnetwork.org/audio/download/ 
        ITC.SO-Episode69-2009.09.29.mp3 )
f = urllib2.urlopen(url)
start = time.time()
data = f.read() # read all data in a single, blocking operation
report(start, len(data),  All data )
f.close()

f = urllib2.urlopen(url)
start = time.time()
while True:
    chunk = f.read(4096) # read a chunk
    if not chunk:
        break
report(start, len(data),  Chunked )
f.close()

我的制度成果:

All data reading took 137 seconds, transfer rate 230.46 KBPS
Chunked reading took 137 seconds, transfer rate 230.49 KBPS

因此,就我的系统而言,2个甚远的连接线、文件尺寸、所选择的服务器,如果我使用粗略读写法,则不会有很大差异。

问题回答

暂无回答




相关问题
热门标签