Conditions
Now that you are able to launch scraper tasks into multiple threads, some controls will need to be put into place so things don't get too out of hand. It is very simple in Go to launch 1,000 goroutines to scrape 1,000 pages simultaneously from a single program. However, your machine most likely cannot handle the same load. The sync package provides a few utilities to help maintain order in your web scraper.
One common control that you will want to put into place is the number of active concurrent scraping threads. Before you launch a new goroutine, you will need to satisfy a certain condition, being that the number of active threads is less than some value. If this condition fails the check, your new goroutine will have to wait, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access