- Clear out misunderstandings in the challenge. Questions about the task.
- Single process prototype. Spawn single worker and send get request
- Make it concurrent
- Check whether it satisfies the requirements
- Optimize
- Create worker pool size of 16. Whenever there is an idle worker in the pool we can start task for our 150 data sample.
Spawns 16 workers with different workerID
and port
to get numbers from. Consumers are goroutines
, called right after spawning the worker with same port
then send requests and processes response. The ratio is 1:1.
main
function spawns a worker(spawnWorker
) and a consumer(callEndpoint
as a goroutine) total of 16 of them.- Workers does not have to be goroutines because
cmd.Start
function does not wait for the process to finish. - Consumer calls the endpoint then reads from response body until it reaches
EOF
or error happens(in our case it means worker has crashed) - Writes total numbers read by current consumer to a channel
- At the end ranging through the channel calculate the sum of all read numbers
Note: sync.WaitGroup
is used for waiting all goroutines to finish