Documentation
¶
Overview ¶
Package benchmarks provides a shared benchmark suite for EventStoreAdapter implementations.
This package operates at the adapter level with pre-serialized EventRecord values, measuring pure adapter I/O throughput without importing the root mink package (which would cause an import cycle).
Usage:
func BenchmarkAdapter(b *testing.B) {
benchmarks.Run(b, benchmarks.AdapterBenchmarkFactory{
Name: "memory",
CreateAdapter: func() (adapters.EventStoreAdapter, func(), error) {
a := memory.NewAdapter()
return a, func() { a.Close() }, nil
},
})
}
Index ¶
- Constants
- func MakeBatch(size int) []adapters.EventRecord
- func MakeStreamID(prefix string, i int) string
- func MediumEventRecord() adapters.EventRecord
- func MetadataEventRecord() adapters.EventRecord
- func Run(b *testing.B, factory AdapterBenchmarkFactory)
- func RunScale(t *testing.T, factory AdapterBenchmarkFactory)
- func SmallEventRecord() adapters.EventRecord
- type AdapterBenchmarkFactory
- type LatencyCollector
- type LatencyReport
- type ScaleConfig
Constants ¶
const AnyVersion = adapters.AnyVersion
AnyVersion is an alias for adapters.AnyVersion, used to skip version checks.
Variables ¶
This section is empty.
Functions ¶
func MakeBatch ¶
func MakeBatch(size int) []adapters.EventRecord
MakeBatch creates a batch of EventRecords with the specified size. All records share the same "OrderEvent" type with unique JSON payloads.
func MakeStreamID ¶
MakeStreamID creates a unique stream ID for benchmarks using the given index.
func MediumEventRecord ¶
func MediumEventRecord() adapters.EventRecord
MediumEventRecord returns a pre-serialized event record with ~500 bytes of JSON payload.
func MetadataEventRecord ¶
func MetadataEventRecord() adapters.EventRecord
MetadataEventRecord returns a pre-serialized event record with rich metadata.
func Run ¶
func Run(b *testing.B, factory AdapterBenchmarkFactory)
Run executes the full Go benchmark suite against the given adapter factory.
func RunScale ¶
func RunScale(t *testing.T, factory AdapterBenchmarkFactory)
RunScale executes scale tests that measure throughput and latency at high event counts.
func SmallEventRecord ¶
func SmallEventRecord() adapters.EventRecord
SmallEventRecord returns a pre-serialized event record with ~100 bytes of JSON payload.
Types ¶
type AdapterBenchmarkFactory ¶
type AdapterBenchmarkFactory struct {
// Name identifies the adapter (e.g., "memory", "postgres").
Name string
// CreateAdapter returns a new adapter instance, a cleanup function, and any error.
// Each benchmark gets a fresh adapter to avoid cross-contamination.
CreateAdapter func() (adapters.EventStoreAdapter, func(), error)
// Skip returns a non-empty reason to skip benchmarks (e.g., missing env var).
// Return "" to run benchmarks.
Skip func() string
// Scale overrides the default event count for scale tests.
// nil uses defaults (1,000,000 for memory, configurable per adapter).
Scale *ScaleConfig
}
AdapterBenchmarkFactory defines how to create an adapter for benchmarking.
type LatencyCollector ¶
type LatencyCollector struct {
// contains filtered or unexported fields
}
LatencyCollector records durations and computes percentile statistics.
func NewLatencyCollector ¶
func NewLatencyCollector(capacity int) *LatencyCollector
NewLatencyCollector creates a collector pre-allocated for the expected number of samples.
func (*LatencyCollector) Record ¶
func (lc *LatencyCollector) Record(d time.Duration)
Record adds a duration sample.
func (*LatencyCollector) Report ¶
func (lc *LatencyCollector) Report() LatencyReport
Report computes percentile statistics from recorded samples. The collector must have at least one sample; otherwise Report returns a zero LatencyReport.
type LatencyReport ¶
type LatencyReport struct {
Count int
P50 time.Duration
P90 time.Duration
P95 time.Duration
P99 time.Duration
Max time.Duration
}
LatencyReport contains percentile latency statistics.
func (LatencyReport) String ¶
func (r LatencyReport) String() string
String returns a human-readable summary of the latency report.
type ScaleConfig ¶
type ScaleConfig struct {
EventCount int // Number of events for scale tests.
}
ScaleConfig overrides scale test parameters.