Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
724b66fb
Commit
724b66fb
authored
Aug 31, 2010
by
Nigel Tao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
doc: add round-robin flag to io2010 balance example.
R=r CC=golang-dev
https://golang.org/cl/2050042
parent
7a2daa7d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
2 deletions
+6
-2
balance.go
doc/talks/io2010/balance.go
+6
-2
No files found.
doc/talks/io2010/balance.go
View file @
724b66fb
...
...
@@ -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
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment