나는 urllib3을 발견했으며 기존 TCP 연결을 재사용한다고 주장합니다.
나는 클레임에 동의하지 않는다는 의견에 이미 언급했듯이 큰 차이를 만들지는 않을 것이다. TCP Slow Start 새로 생성 된 모든 연결은 처음에는 느릴 것이기 때문이다. 데이터가 큰 경우 동일한 TCP 소켓을 재사용하면 차이가 발생합니다. 그리고 나는 100에 대한 데이터가 10과 100 MB 사이라고 생각합니다.
import httplib
images = ['img1.png', 'img2.png', 'img3.png']
conn = httplib.HTTPConnection('www.example.com')
for image in images:
conn.request('GET', '/images/%s' % image)
resp = conn.getresponse()
data = resp.read()
with open(image, 'wb') as f:
f.write(data)
conn.close()
이 여러 (순차적)를 발행 할 목록에서 이미지에 대한 요청을 GET 다음 : 당신은 HTTPLIB 조각을 요구하기 때문에 여기에
는
http://code.google.com/p/urllib3/source/browse/test/benchmark.py
TO_DOWNLOAD = [
'http://code.google.com/apis/apps/',
'http://code.google.com/apis/base/',
'http://code.google.com/apis/blogger/',
'http://code.google.com/apis/calendar/',
'http://code.google.com/apis/codesearch/',
'http://code.google.com/apis/contact/',
'http://code.google.com/apis/books/',
'http://code.google.com/apis/documents/',
'http://code.google.com/apis/finance/',
'http://code.google.com/apis/health/',
'http://code.google.com/apis/notebook/',
'http://code.google.com/apis/picasaweb/',
'http://code.google.com/apis/spreadsheets/',
'http://code.google.com/apis/webmastertools/',
'http://code.google.com/apis/youtube/',
]
from urllib3 import HTTPConnectionPool
import urllib
pool = HTTPConnectionPool.from_url(url_list[0])
for url in url_list:
r = pool.get_url(url)
일반적으로 이미지의 크기에 비해 네트워크 오버 헤드가 거의 없다고 생각합니다. 당신이 반대되는 증거가 없다면 문제의 가치가 없을 것입니다. – Thomas
[Dive into Python] (http://diveintopython.org/http_web_services/index.html)도 비슷한 작업을 수행했습니다. –
나는 네트워크 오버 헤드가 큰 차이를 내지 않는다는 것에 동의하지 않는다. TCP Slow Start (http://en.wikipedia.org/wiki/Slow-start) 때문에 새로 생성 된 모든 연결은 처음에는 느려질 것입니다. 따라서 동일한 TCP 연결을 재사용하면 데이터가 충분히 크면 차이가 발생합니다 (100 장의 사진은 10 ~ 100MB가됩니다) –