liveBook · Manning

Load balancing

As explained in Learn Concurrent Programming with Go

Load balancing is the distribution of work across multiple workers or processing resources to avoid concentrating demand on one worker.

Load balancing distributes incoming work across multiple workers so additional processing resources can be used effectively. In Go, a channel can act as a shared work queue: several goroutines receive tasks from it, spreading demand instead of concentrating it on one worker. section 1.0 section 10.2.3

Figure 10.8 Using a worker pool in an HTTP server

Figure 10.8 shows the flow from an HTTP server’s accepting goroutine, through a channel-based work queue, to several worker goroutines. section 10.2.3

A small HTTP server demonstrates the pattern:

  • Create an incoming-connections channel and start a fixed number of workers. Each worker ranges over the channel and handles one connection before waiting for another. section 10.2.3

Payroll processing

Divide payroll into employee groups, process the groups concurrently with multiple goroutines, distribute them through a channel, and collect results through another channel. Simulations report at least a fivefold speed improvement on the same multicore hardware, although race-condition testing remains necessary. section 1.0

How Learn Concurrent Programming with Go covers it

How deep it goes
Explains shared work queues, worker lifecycles, overload rejection, and HTTP implementation, but defers detailed race analysis.
Examples
Uses payroll groups and a static-file HTTP server with three workers, busy responses, and parallel curl load.
What it assumes
Assumes basic Go networking and concurrency syntax while introducing channel queues and worker-pool coordination through examples.
What you can do after
Build it from scratch with Go goroutines, channels, worker pools, and bounded-load rejection.
How it connects
Connects load balancing with concurrency, goroutines, channels, worker pools, multicore processing, and race conditions.

Also explained in

Compare how 14 books explain load balancing →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Concurrent Programming with Go. The section links point to the parts of the book it draws on.