a0a502a091 Concurrency enables parallelism The load balancer is implicitly parallel and scalable. // Receive will block until timerChan delivers. w.requests <- req // One more in its work queue. timerChan := make(chan time.Time) go func() { time.Sleep(deltaT) timerChan <- time.Now() // send time on timerChan }() // Do something else; when ready, receive. Goroutines A goroutine is a function running independently in the same address space as other goroutines f("hello", "world") // f runs; we wait go f("hello", "world") // f starts running g() // does not wait for f to return Like launching a function with shell's & notation. Concurrency Programming as the composition of independently executing processes. Our technology should help. The slides are available at talks.golang.org (use the left and right arrow keys to navigate). Communication is the means to coordinate the independent executions.
Worker Balancer sends request to most lightly loaded worker func (w *Worker) work(done chan *Worker) { for { req := <-w.requests // get Request from balancer req.c <- req.fn() // call fn and send result done <- w // we've finished this request } } The channel of requests (w.requests) delivers requests to each worker. Requester function An artificial but illustrative simulation of a requester, a load generator. Lesson There are many ways to break the processing down. Concurrency enables parallelism. completedAt := <-timerChan . Concurrency vs. Or a different way Bring the staging pile to the multi-gopher concurrent model: . That's where concurrency comes in.
Gerwiunce replied
455 weeks ago