Skip to content

Commit 2ac9a22

Browse files
committed
test(epaxos): resident-state conflict benchmarks
Add pre-grown resident attrs/step/retire benchmarks so D1 costs are visible without fresh-node-per-iteration holes.
1 parent f15cda1 commit 2ac9a22

1 file changed

Lines changed: 80 additions & 0 deletions

File tree

epaxos/performance_benchmark_test.go

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,3 +328,83 @@ func residentInstanceBytes(inst *instance) uintptr {
328328
}
329329
return bytes
330330
}
331+
332+
333+
func growResidentNode(b *testing.B, n int) *RawNode {
334+
b.Helper()
335+
rn, err := NewRawNode(Config{ID: 1, Voters: makeIDs(3)})
336+
if err != nil {
337+
b.Fatal(err)
338+
}
339+
key := []byte("bench-key")
340+
for i := 1; i <= n; i++ {
341+
ref := InstanceRef{Conf: 1, Replica: 1, Instance: InstanceNum(i)}
342+
rec := InstanceRecord{
343+
Ref: ref, Status: StatusCommitted, Seq: uint64(i), Ballot: Ballot{Replica: 1},
344+
Deps: rn.q.deps(), Command: Command{Payload: []byte("x"), ConflictKeys: [][]byte{key}},
345+
}
346+
rec.Checksum = ChecksumRecord(rec)
347+
rn.installInstance(&instance{rec: rec, phase: phaseCommitted})
348+
}
349+
return rn
350+
}
351+
352+
func BenchmarkComputeAttrsResident1k(b *testing.B) {
353+
rn := growResidentNode(b, 1000)
354+
cmd := Command{Payload: []byte("y"), ConflictKeys: [][]byte{[]byte("bench-key")}}
355+
exclude := InstanceRef{Conf: 1, Replica: 1, Instance: 1001}
356+
b.ReportAllocs()
357+
b.ResetTimer()
358+
for i := 0; i < b.N; i++ {
359+
_ = rn.computeAttrs(cmd, exclude)
360+
}
361+
}
362+
363+
func BenchmarkComputeAttrsResident100k(b *testing.B) {
364+
if testing.Short() {
365+
b.Skip("100k resident bench")
366+
}
367+
rn := growResidentNode(b, 100000)
368+
cmd := Command{Payload: []byte("y"), ConflictKeys: [][]byte{[]byte("bench-key")}}
369+
exclude := InstanceRef{Conf: 1, Replica: 1, Instance: 100001}
370+
b.ReportAllocs()
371+
b.ResetTimer()
372+
for i := 0; i < b.N; i++ {
373+
_ = rn.computeAttrs(cmd, exclude)
374+
}
375+
}
376+
377+
func BenchmarkStepPreAcceptGrown(b *testing.B) {
378+
rn := growResidentNode(b, 1000)
379+
b.ReportAllocs()
380+
b.ResetTimer()
381+
for i := 0; i < b.N; i++ {
382+
ref := InstanceRef{Conf: 1, Replica: 2, Instance: InstanceNum(i + 1)}
383+
cmd := Command{ID: CommandID{Client: 9, Sequence: uint64(i + 1)}, Payload: []byte("z"), ConflictKeys: [][]byte{[]byte("bench-key")}}
384+
msg := Message{Type: MsgPreAccept, From: 2, To: 1, Ref: ref, Ballot: Ballot{Replica: 2}, Command: cmd}
385+
_ = rn.Step(msg)
386+
}
387+
}
388+
389+
func BenchmarkRetireExecuted(b *testing.B) {
390+
b.ReportAllocs()
391+
for i := 0; i < b.N; i++ {
392+
b.StopTimer()
393+
rn, err := NewRawNode(Config{ID: 1, Voters: makeIDs(3), RetainExecutedPerLane: 8})
394+
if err != nil {
395+
b.Fatal(err)
396+
}
397+
for j := 1; j <= 64; j++ {
398+
ref := InstanceRef{Conf: 1, Replica: 1, Instance: InstanceNum(j)}
399+
rec := InstanceRecord{
400+
Ref: ref, Status: StatusExecuted, Seq: uint64(j), Ballot: Ballot{Replica: 1},
401+
Deps: rn.q.deps(), Command: Command{Payload: []byte("x"), ConflictKeys: [][]byte{[]byte("k")}},
402+
}
403+
rec.Checksum = ChecksumRecord(rec)
404+
rn.installInstance(&instance{rec: rec, phase: phaseCommitted})
405+
rn.executed.add(ref)
406+
}
407+
b.StartTimer()
408+
rn.retireExecuted()
409+
}
410+
}

0 commit comments

Comments
 (0)