tweak
This commit is contained in:
parent
287decabfd
commit
65949e3684
@ -13,18 +13,18 @@ import "sync/atomic"
|
|||||||
// e.g. routing table
|
// e.g. routing table
|
||||||
|
|
||||||
type readOp struct {
|
type readOp struct {
|
||||||
key string
|
key int
|
||||||
resp chan int
|
resp chan int
|
||||||
}
|
}
|
||||||
|
|
||||||
type writeOp struct {
|
type writeOp struct {
|
||||||
key string
|
key int
|
||||||
val int
|
val int
|
||||||
resp chan bool
|
resp chan bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func randKey() string {
|
func randKey() int {
|
||||||
return []string{"a", "b", "c"}[rand.Intn(3)]
|
return rand.Intn(10)
|
||||||
}
|
}
|
||||||
|
|
||||||
func randVal() int {
|
func randVal() int {
|
||||||
@ -32,7 +32,7 @@ func randVal() int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func manageState(reads chan *readOp, writes chan *writeOp) {
|
func manageState(reads chan *readOp, writes chan *writeOp) {
|
||||||
data := make(map[string]int)
|
data := make(map[int]int)
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case read := <- reads:
|
case read := <- reads:
|
||||||
@ -75,10 +75,11 @@ func main() {
|
|||||||
writes := make(chan *writeOp)
|
writes := make(chan *writeOp)
|
||||||
|
|
||||||
go manageState(reads, writes)
|
go manageState(reads, writes)
|
||||||
|
|
||||||
for r := 0; r < 100; r++ {
|
for r := 0; r < 100; r++ {
|
||||||
go generateReads(reads)
|
go generateReads(reads)
|
||||||
}
|
}
|
||||||
for w := 0; w < 5; w++ {
|
for w := 0; w < 10; w++ {
|
||||||
go generateWrites(writes)
|
go generateWrites(writes)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user