...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package raft
16
17 import (
18 "context"
19 "testing"
20 "time"
21 )
22
23 func BenchmarkOneNode(b *testing.B) {
24 ctx, cancel := context.WithCancel(context.Background())
25 defer cancel()
26
27 s := newTestMemoryStorage(withPeers(1))
28 rn := newTestRawNode(1, 10, 1, s)
29 n := newNode(rn)
30 go n.run()
31
32 defer n.Stop()
33
34 n.Campaign(ctx)
35 go func() {
36 for i := 0; i < b.N; i++ {
37 n.Propose(ctx, []byte("foo"))
38 }
39 }()
40
41 for {
42 rd := <-n.Ready()
43 s.Append(rd.Entries)
44
45 time.Sleep(1 * time.Millisecond)
46 n.Advance()
47 if rd.HardState.Commit == uint64(b.N+1) {
48 return
49 }
50 }
51 }
52
View as plain text