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 ...

Get Mastering Go - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.