summaryrefslogtreecommitdiff
path: root/doc/talks/io2010
diff options
context:
space:
mode:
authorNigel Tao <nigeltao@golang.org>2010-08-31 11:00:43 +1000
committerNigel Tao <nigeltao@golang.org>2010-08-31 11:00:43 +1000
commit7664e35fc5c183f70662cb31892f544b3c37ca0d (patch)
tree0b57c8d7a6b26f0ea0522f27b8651aa47c430a0b /doc/talks/io2010
parentc4611c7b8bb7aabc300865751f664a044242e926 (diff)
downloadgo-7664e35fc5c183f70662cb31892f544b3c37ca0d.tar.gz
doc: add round-robin flag to io2010 balance example.
R=r CC=golang-dev http://codereview.appspot.com/2050042
Diffstat (limited to 'doc/talks/io2010')
-rw-r--r--doc/talks/io2010/balance.go8
1 files changed, 6 insertions, 2 deletions
diff --git a/doc/talks/io2010/balance.go b/doc/talks/io2010/balance.go
index 6a0713831..b01f7468c 100644
--- a/doc/talks/io2010/balance.go
+++ b/doc/talks/io2010/balance.go
@@ -6,6 +6,7 @@ package main
import (
"container/heap"
+ "flag"
"fmt"
"rand"
"time"
@@ -14,6 +15,8 @@ import (
const nRequester = 100
const nWorker = 10
+var roundRobin = flag.Bool("r", false, "use round-robin scheduling")
+
// Simulation of some work: just sleep for a while and report how long.
func op() int {
n := rand.Int63n(1e9)
@@ -125,7 +128,7 @@ func (b *Balancer) print() {
}
func (b *Balancer) dispatch(req Request) {
- if false {
+ if *roundRobin {
w := b.pool[b.i]
w.requests <- req
w.pending++
@@ -144,7 +147,7 @@ func (b *Balancer) dispatch(req Request) {
}
func (b *Balancer) completed(w *Worker) {
- if false {
+ if *roundRobin {
w.pending--
return
}
@@ -156,6 +159,7 @@ func (b *Balancer) completed(w *Worker) {
}
func main() {
+ flag.Parse()
work := make(chan Request)
for i := 0; i < nRequester; i++ {
go requester(work)