2/28
Part 1 of 6 · Why threadsLearn and do

A crawler spends its time waiting

Start with where a crawler's time goes.

One page at a time, almost all the time is waiting

Twelve fetches of 50 ms, nearly all of it waitingInteractive
runs Python, holds the GIL waits on the network, GIL let go
Total
600 ms
Speedup
1.0×
Peak in flight
1
One page at a time: 12 pages × 50 ms = 600 ms, and almost all of it is waiting.

A crawler fetches a page, reads the links on it, and then fetches those pages. Each fetch(url) sends a request and then sits idle until the server answers. Your own code does very little for each page.

The practice tests fake the network with time.sleep. Their bigger site has 41 pages, and every fetch sleeps 50 ms. That came to 58 ms on average on the machine these numbers come from.

Predict

41 bare sleeps of 50 ms took 2.36 s. How long did the whole crawl take, one page at a time?

Pick an answer above to see the rest