getresponse many recv calls when reading the header of an HTML request. It actually produces recv for each byte, which leads to many system calls. How can it be optimized?
I checked on an Ubuntu machine with a strace dump.
code example:
conn = httplib.HTTPConnection("www.python.org") conn.request("HEAD", "/index.html") r1 = conn.getresponse()
strace dump:
sendto(3, "HEAD /index.html HTTP/1.1\r\nHost:"..., 78, 0, NULL, 0) = 78 recvfrom(3, "H", 1, 0, NULL, NULL) = 1 recvfrom(3, "T", 1, 0, NULL, NULL) = 1 recvfrom(3, "T", 1, 0, NULL, NULL) = 1 recvfrom(3, "P", 1, 0, NULL, NULL) = 1 recvfrom(3, "/", 1, 0, NULL, NULL) = 1 ...