Worker pools
Generally speaking, a worker pool is a set of threads that are about to process jobs assigned to them. The Apache web server and the net/http package of Go more or less work this way: the main process accepts all incoming requests, which are forwarded to the worker processes to get served. Once a worker process has finished its job, it is ready to serve a new client.
Nevertheless, there is a central difference here because our worker pool is going to use goroutines instead of threads. Additionally, threads do not usually die after serving a request because the cost of ending a thread and creating a new one is too high, whereas goroutines do die after finishing their job. As you will see shortly, worker pools in Go are implemented ...
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