import (
"container/heap"
+ "flag"
"fmt"
"rand"
"time"
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)
}
func (b *Balancer) dispatch(req Request) {
- if false {
+ if *roundRobin {
w := b.pool[b.i]
w.requests <- req
w.pending++
}
func (b *Balancer) completed(w *Worker) {
- if false {
+ if *roundRobin {
w.pending--
return
}
}
func main() {
+ flag.Parse()
work := make(chan Request)
for i := 0; i < nRequester; i++ {
go requester(work)