Elapsed time to download content is zero. #8054
-
As far as I know, def do_request(self):
self.headers_fetch_elapsed_time, self.text_fetch_elapsed_time = 0, 0
t1 = time.perf_counter()
async with self.session.get(self.url) as resp:
t2 = time.perf_counter()
self.headers_fetch_elapsed_time = round(1000 * (t2 - t1))
self.txt = await resp.text()
self.text_fetch_elapsed_time = round(1000 * (time.perf_counter() - t2)) I use the above function multiple times by a specific URL but most of the time So, why is this happening? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
Not exactly, that's not how HTTP works. It downloads a small amount of data (maybe 4KB or something) and parses the headers from that before returning. When you call any variation of .read() it will then continue from the buffered data and fetch anything more from the server if needed. So, if your responses are small, the network request will have been completed and the connection released before your call to .text(). |
Beta Was this translation helpful? Give feedback.
Not exactly, that's not how HTTP works. It downloads a small amount of data (maybe 4KB or something) and parses the headers from that before returning. When you call any variation of .read() it will then continue from the buffered data and fetch anything more from the server if needed. So, if your responses are small, the network request will have been completed and the connection released before your call to .text().