-
Notifications
You must be signed in to change notification settings - Fork 995
/
bench_test.go
46 lines (39 loc) · 1.06 KB
/
bench_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package raft
import (
"testing"
"time"
"github.com/hashicorp/go-hclog"
)
func BenchmarkStoreLogInMem(b *testing.B) {
conf := DefaultConfig()
conf.LocalID = "first"
conf.HeartbeatTimeout = 50 * time.Millisecond
conf.ElectionTimeout = 50 * time.Millisecond
conf.LeaderLeaseTimeout = 50 * time.Millisecond
conf.CommitTimeout = 5 * time.Millisecond
conf.SnapshotThreshold = 100
conf.TrailingLogs = 10
conf.LogLevel = "OFF"
raft := MakeRaft(b, conf, true)
raft.logger.SetLevel(hclog.Off)
NoErr(WaitFor(raft, Leader), b)
applyAndWait := func(leader *RaftEnv, n, sz int) {
// Do some commits
var futures []ApplyFuture
for i := 0; i < n; i++ {
futures = append(futures, leader.raft.Apply(logBytes(i, sz), 0))
}
for _, f := range futures {
NoErr(WaitFuture(f), b)
leader.logger.Debug("applied", "index", f.Index(), "size", sz)
}
}
for i := 0; i < b.N; i++ {
// Do some commits
applyAndWait(raft, 100, 10)
// Do a snapshot
NoErr(WaitFuture(raft.raft.Snapshot()), b)
}
}