Skip to content

Instantly share code, notes, and snippets.

@benbjohnson
Created August 29, 2014 20:32
Show Gist options
  • Save benbjohnson/62faf4d1750b440409e2 to your computer and use it in GitHub Desktop.
Save benbjohnson/62faf4d1750b440409e2 to your computer and use it in GitHub Desktop.
raft benchmark
... append to the end of raft_test.go ...
func BenchmarkRaftTripleNode(b *testing.B) {
b.ReportAllocs()
// Make the cluster
c := MakeCluster(3, b, nil)
defer c.Close()
// Should be one leader
leader := c.Leader()
c.EnsureLeader(b, leader.localAddr)
b.ResetTimer()
startTime := time.Now()
for i := 0; i < b.N; i++ {
cmd := make([]byte, 32)
binary.BigEndian.PutUint64(cmd, uint64(i))
leader.Apply(cmd, 0)
}
fmt.Printf("++++\nELAPSED: %d cmds in %.03f\n++++", b.N, time.Since(startTime).Seconds())
b.StopTimer()
time.Sleep(2000 * time.Millisecond)
// Check that it is applied to the FSM
for i, fsm := range c.fsms {
fsm.Lock()
num := len(fsm.logs)
fsm.Unlock()
if num != b.N {
b.Fatalf("fsm(%d): num: exp=%d, got=%d", i, b.N, num)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment