12/28
Part 4 of 6 · A pool and a coordinatorLearn and do

Why not start one thread per link and skip the pool?

The home page returns 40 links
a thread per link
40 in flight
a pool of 4
4 in flight, 36 queued

A thread per URL looks like the same thing without the bookkeeping, and on the test site it's even faster. But the number of threads has no bound, and the number of URLs isn't up to you.

Size the pool from the rate you want

Fetches in flight equal the rate you want times how long each fetch takes. That's Little's law, L=λWL = \lambda W. Here LL is the number in flight, λ\lambda (lambda) is the rate in pages a second, and WW is the seconds each fetch takes.

Predict

Each fetch takes 0.2 s, and you want 20 pages a second. How many fetches must be in flight?

Pick an answer above to see the rest