Using the template provided in main.go
build a worker pool using what you learned about go channels and goroutines. This example will accept a number of workers as a flag --workers
and then use the workers to perform a task. It should take between 10-15 min?
Fill in the func (wp *workerPool) run()
to queue up the amount of workers input via command line arguments.
You can run the following exercise code locally with the following command.
go run main.go --workers=2
Follow-up questions:
- is this a parallel or concurrent process?
- do we need channels and go routines to write this program? What are advantages and disadvantages?
- did you notice any changes in your pprof metrics?
- do multiple routines give you any advantage?