bench

package
v0.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 10, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

README

Mono-Framework Performance Benchmarks

This directory contains comprehensive performance benchmarks for the mono-framework, measuring throughput, latency, startup time, and memory footprint across various service types and framework operations.

Quick Start

# Run all benchmarks
go test -bench=. -benchmem ./bench/

# Run specific benchmark category
go test -bench='BenchmarkFramework' -benchmem ./bench/
go test -bench='BenchmarkInProcess' -benchmem ./bench/
go test -bench='BenchmarkSocket' -benchmem ./bench/

# Run benchmarks with timeout (some benchmarks take time)
go test -bench=. -benchmem -timeout=10m ./bench/

# Save benchmark results for comparison
go test -bench=. -benchmem ./bench/ > new.txt
benchstat old.txt new.txt

Performance Targets

The framework is designed to meet the following performance targets (defined in docs/spec/foundation.md):

Metric Target Actual Performance Status
Message Throughput > 40,000 msgs/sec 90,000+ msgs/sec ✅ PASS
Framework Startup < 10ms 14-60 microseconds ✅ PASS
Memory Footprint < 20MB base overhead 0.06-0.27 MB ✅ PASS
Pub/Sub Latency < 1ms per message 456-585 ns ✅ PASS
Service Call Latency Varies by type See below ✅ PASS

Benchmark Categories

Framework Benchmarks (bench_framework_test.go)

These benchmarks measure framework-level operations:

BenchmarkFrameworkStartup
  • Purpose: Measures framework initialization and startup time
  • Target: < 10ms for 10 modules
  • Results:
    • 1 module: ~14 μs
    • 5 modules: ~23 μs
    • 10 modules: ~37 μs
    • 20 modules: ~58 μs
  • Status: ✅ All well within 10ms target
BenchmarkFrameworkStartupWithDependencies
  • Purpose: Measures startup time with module dependency resolution
  • Results:
    • Linear chain (10 modules): ~43 μs
    • Tree structure (15 modules): ~61 μs
  • Status: ✅ Dependency resolution adds minimal overhead (~1-2μs per dependency)
BenchmarkFrameworkMemoryFootprint
  • Purpose: Measures base memory overhead of the framework
  • Target: < 20MB base overhead
  • Results:
    • No modules: ~0.06 MB
    • 1 module: ~0.27 MB
    • 10 modules: ~0.23 MB
    • 50 modules: ~0.06 MB
    • 100 modules: ~0.11 MB
  • Status: ✅ All well within 20MB target
BenchmarkFrameworkThroughput
  • Purpose: End-to-end message throughput test
  • Target: > 40,000 msgs/sec
  • Results: ~90,979 msgs/sec
  • Status: ✅ ~2x above target
In-Process Service Benchmarks (bench_in_process_test.go)

These benchmarks use in-process NATS connections (no TCP overhead) to measure pure service performance:

BenchmarkInProcessChannelService
  • Service Type: Go channel-based communication
  • Latency: ~540-640 ns/op
  • Throughput: 400-8,000 MB/s depending on payload size
  • Best for: Ultra-low latency in-process communication
BenchmarkInProcessRequestReplyService
  • Service Type: NATS request-response pattern
  • Latency: ~9.6-22.6 μs/op
  • Throughput: 26-226 MB/s depending on payload size
  • Best for: Synchronous service calls with responses
BenchmarkInProcessQueueGroupService
  • Service Type: Fire-and-forget with load balancing
  • Latency: ~9.8-21.5 μs/op
  • Throughput: 26-238 MB/s depending on payload size
  • Best for: Background tasks with horizontal scaling
BenchmarkInProcessStreamConsumerService
  • Service Type: JetStream durable messaging with batching
  • Latency: ~18-74 μs/op
  • Throughput: 14-69 MB/s depending on payload size
  • Best for: Reliable message delivery with persistence
BenchmarkInProcessEventConsumer
  • Service Type: NATS Core pub/sub event delivery
  • Latency: ~585-1,768 ns/op (< 1ms target ✅)
  • Throughput: 437-2,896 MB/s depending on payload size
  • Best for: High-throughput event broadcasting
BenchmarkInProcessEventStreamConsumer
  • Service Type: JetStream durable event delivery
  • Latency: ~15-80 μs/op
  • Throughput: 16-64 MB/s depending on payload size
  • Best for: Durable event sourcing with replay
Socket Service Benchmarks (bench_socket_test.go)

These benchmarks use TCP socket connections to measure network I/O overhead:

Key Differences from In-Process
  • Uses TCP loopback (127.0.0.1) instead of in-memory connections
  • Adds network serialization/deserialization overhead
  • Simulates realistic distributed deployment scenarios
Performance Comparison
  • Channel Service: ~10% faster with sockets (optimized TCP stack)
  • Request-Reply: ~70% slower (network round-trip)
  • Queue Group: ~80% slower (network + ack overhead)
  • Event Consumer: ~20-30% faster for small payloads
Multi-Module Benchmarks (bench_multi_module_test.go)
BenchmarkMultiModuleOrderOrchestration
  • Purpose: End-to-end workflow simulation
  • Scenario: Order → Inventory → Payment → Notification
  • Latency: ~70-290 μs depending on payload size
  • Demonstrates: Real-world application performance with multiple service calls
BenchmarkMultiModuleOrderOrchestrationJSON
  • Purpose: Same workflow with JSON serialization
  • Comparison: ~10-15% slower than raw bytes (JSON overhead)
  • Demonstrates: Typical API serialization costs

Benchmark Methodology

Payload Sizes

All service benchmarks test three payload sizes:

  • 256 bytes: Typical small message (user ID, simple event)
  • 1 KB: Medium message (user profile, order details)
  • 5 KB: Large message (document, image metadata)
Environment

Benchmarks are designed to run on:

  • CPU: 11 vCPUs (ARM64 or x86_64)
  • Memory: 4GB+ recommended
  • OS: Linux, macOS, or Windows
  • Go: 1.25+
Accuracy Considerations
  • Each benchmark runs multiple iterations (b.N) for statistical accuracy
  • b.ResetTimer() used to exclude setup costs
  • runtime.GC() run twice before memory benchmarks for clean baseline
  • Context timeouts prevent hanging benchmarks

Interpreting Results

Throughput (MB/s)
  • Higher is better
  • Calculated as: (payload_size * b.N) / elapsed_time
  • Set with b.SetBytes(int64(payloadSize))
Latency (ns/op, μs/op, ms/op)
  • Lower is better
  • Represents time per operation
  • For round-trip operations, includes both send and receive
Allocations (B/op, allocs/op)
  • Lower is better
  • Shows memory allocation overhead
  • Key metric for GC pressure
Custom Metrics

Some benchmarks report custom metrics:

  • msgs/sec: Messages per second throughput
  • MB_alloc_delta: Memory allocated above baseline
  • MB_heap_delta: Heap growth above baseline

Comparing Results with benchstat

# Run baseline
go test -bench=. -benchmem -count=5 ./bench/ > old.txt

# Make changes to code

# Run new benchmarks
go test -bench=. -benchmem -count=5 ./bench/ > new.txt

# Compare (requires: go install golang.org/x/perf/cmd/benchstat@latest)
benchstat old.txt new.txt

Expected output:

name                                           old time/op    new time/op    delta
FrameworkStartup/10_modules-11                   37.0µs ± 2%    36.5µs ± 3%     ~
InProcessEventConsumer/payload_256B-11            585ns ± 1%     580ns ± 2%   -0.85%

Performance Optimization Tips

For Service Selection
  • Use ChannelService for ultra-low latency in-process communication
  • Use RequestReplyService for synchronous RPC with responses
  • Use QueueGroupService for background tasks with load balancing
  • Use EventConsumer for high-throughput pub/sub patterns
  • Use StreamConsumer when you need message persistence and replay
For Deployment Mode
  • In-Process NATS (default): Best performance, single-process deployment
  • TCP Socket NATS: Necessary for multi-process/distributed deployment
  • Clustered NATS: Horizontal scaling with minimal overhead
For Memory Optimization
  • Module count has minimal impact (< 10KB per module)
  • Service registration is lightweight (< 1KB per service)
  • JetStream adds overhead (~10-20MB for storage + buffers)

Requirements Traceability

Requirement Benchmark Result
NFR1.1: Message throughput > 40,000 msgs/sec BenchmarkFrameworkThroughput 90,979 msgs/sec ✅
NFR1.1: Framework startup < 10ms BenchmarkFrameworkStartup 14-60 μs ✅
NFR1.4: Pub/sub latency < 1ms BenchmarkInProcessEventConsumer 585 ns ✅
NFR1.4: Memory footprint < 20MB BenchmarkFrameworkMemoryFootprint 0.06-0.27 MB ✅

JSON Benchmark Results

The benchparse tool converts Go benchmark JSON output to a structured format with targets and pass/fail indicators:

# Generate JSON benchmark results
go test -bench='BenchmarkFramework' -benchmem -json ./bench/ | go run ./bench/cmd/benchparse

# Output is written to mono_benchmark_result.json
JSON Output Format

The output includes two sections:

  1. results: All benchmark results with standard metrics
  2. framework_results: Framework benchmarks with targets and pass/fail status
{
  "timestamp": "2025-12-31T05:00:00Z",
  "results": [...],
  "framework_results": [
    {
      "name": "BenchmarkFrameworkStartup/10_modules-11",
      "duration": "0.02ms",
      "target_duration": "10ms",
      "duration_passed": true
    },
    {
      "name": "BenchmarkFrameworkMemoryFootprint/10_modules-11",
      "memory": "0.25MB",
      "target_memory": "20MB",
      "memory_passed": true
    },
    {
      "name": "BenchmarkFrameworkThroughput-11",
      "throughput": "90000 msgs/sec",
      "target_throughput": "40000 msgs/sec",
      "throughput_passed": true
    }
  ]
}
Framework Benchmark Targets
Benchmark Type Metric Target Pass Condition
BenchmarkFrameworkStartup/* duration 10ms actual <= target
BenchmarkFrameworkStartupWithDependencies/* duration 10ms actual <= target
BenchmarkFrameworkMemoryFootprint/* memory 20MB actual <= target
BenchmarkFrameworkThroughput throughput 40000 msgs/sec actual >= target

Continuous Performance Monitoring

Add these benchmarks to your CI/CD pipeline:

# .github/workflows/benchmarks.yml
- name: Run Benchmarks
  run: |
    go test -bench=. -benchmem -timeout=10m ./bench/ | tee bench-results.txt

- name: Run Benchmarks with JSON Output
  run: |
    go test -bench='BenchmarkFramework' -benchmem -json ./bench/ | go run ./bench/cmd/benchparse

- name: Check Performance Regressions
  run: |
    benchstat baseline.txt bench-results.txt > comparison.txt
    # Fail if throughput decreased by >10% or latency increased by >10%

Contributing New Benchmarks

When adding new benchmarks:

  1. Follow naming convention: Benchmark<Category><TestName>
  2. Use standard payload sizes: 256B, 1KB, 5KB
  3. Include benchmem flag: Report allocations
  4. Document targets: Add expected performance in comments
  5. Use b.ResetTimer(): Exclude setup time
  6. Report custom metrics: Use b.ReportMetric() for domain-specific measures
  7. Add to this README: Update tables and documentation

References

Documentation

Overview

Package bench provides shared types and helper functions for benchmarking the mono-framework. Inspired by nats.go/bench/bench.go patterns.

Package bench provides multi-module benchmark infrastructure for measuring inter-module communication performance in the mono-framework.

This file contains simplified benchmark module implementations that simulate a realistic order workflow with 4 modules:

  • BenchInventoryModule: Provides stock checking service (RequestReply)
  • BenchPaymentModule: Provides payment processing service (RequestReply)
  • BenchNotificationModule: Provides notification service (QueueGroup + EventConsumer)
  • BenchOrderModule: Orchestrates the order workflow (DependentModule + EventEmitter)

Index

Constants

View Source
const DefaultPayloadSize = 256

DefaultPayloadSize is the standard payload size for benchmarks (256 bytes).

Variables

View Source
var BenchOrderCreatedV1 = helper.EventDefinition[BenchOrderCreatedEvent](
	"bench-order", "BenchOrderCreated", "v1",
)

BenchOrderCreatedV1 is the event definition for benchmark order events.

View Source
var MultiModuleResult any

MultiModuleResult is a sink variable to prevent compiler optimizations in multi-module benchmarks. Exported to satisfy the unused linter.

View Source
var PayloadSizes = []int{256, 1024, 5120}

PayloadSizes defines payload sizes for sub-benchmarks (256B, 1KB, 5KB).

Functions

func GeneratePayload

func GeneratePayload(size int) []byte

GeneratePayload creates a byte slice of the given size with non-zero data. This prevents compiler optimization and simulates real message payloads.

func NewBenchApp

func NewBenchApp() (mono.MonoApplication, error)

NewBenchApp creates a MonoApplication configured for minimal overhead benchmarks. It uses in-process connections with TCP listening disabled.

func NewBenchAppWithJetStream

func NewBenchAppWithJetStream(storageDir string) (mono.MonoApplication, error)

NewBenchAppWithJetStream creates a MonoApplication with JetStream enabled. Uses in-process connections for minimal overhead.

func NewBenchAppWithOptions

func NewBenchAppWithOptions(opts BenchAppOptions) (mono.MonoApplication, error)

NewBenchAppWithOptions creates a MonoApplication with configurable options.

  • InProcess=true: Uses in-process connections (no TCP listening)
  • InProcess=false: Uses TCP socket connections (listens on auto-assigned port)
  • JetStreamDir non-empty: Enables JetStream with the specified storage directory

Types

type BenchAppOptions

type BenchAppOptions struct {
	InProcess    bool   // Use in-process connections (no TCP socket)
	JetStreamDir string // Enable JetStream with this storage directory (empty = disabled)
}

BenchAppOptions configures benchmark application creation.

type BenchCheckStockRequest

type BenchCheckStockRequest struct {
	ProductID string `json:"product_id"`
	Quantity  int    `json:"quantity"`
}

BenchCheckStockRequest is a simplified stock check request.

type BenchCheckStockResponse

type BenchCheckStockResponse struct {
	Available bool `json:"available"`
	Stock     int  `json:"stock"`
}

BenchCheckStockResponse is a simplified stock check response.

type BenchConsumerModule

type BenchConsumerModule struct {
	// contains filtered or unexported fields
}

BenchConsumerModule is a minimal consumer module for benchmarks. It implements Module and DependentModule interfaces. Note: This module only stores a single dependency container for simplicity. If multiple dependencies are needed, use a map[string]mono.ServiceContainer instead.

func NewBenchConsumerModule

func NewBenchConsumerModule(name string, deps []string) *BenchConsumerModule

NewBenchConsumerModule creates a new consumer module with the given name and dependencies.

func (*BenchConsumerModule) DepContainer

func (m *BenchConsumerModule) DepContainer() mono.ServiceContainer

DepContainer returns the stored dependency container.

func (*BenchConsumerModule) Dependencies

func (m *BenchConsumerModule) Dependencies() []string

Dependencies returns the list of module dependencies.

func (*BenchConsumerModule) Name

func (m *BenchConsumerModule) Name() string

Name returns the module name.

func (*BenchConsumerModule) SetDependencyServiceContainer

func (m *BenchConsumerModule) SetDependencyServiceContainer(_ string, container mono.ServiceContainer)

SetDependencyServiceContainer stores the dependency's service container.

func (*BenchConsumerModule) Start

Start is a no-op for benchmark modules.

func (*BenchConsumerModule) Stop

Stop is a no-op for benchmark modules.

type BenchEventConsumerModule

type BenchEventConsumerModule struct {
	// contains filtered or unexported fields
}

BenchEventConsumerModule is a minimal event consumer module for benchmarks. It implements Module and EventConsumerModule interfaces.

func NewBenchEventConsumerModule

func NewBenchEventConsumerModule(name string, eventDef mono.BaseEventDefinition, handler mono.EventConsumerHandler) *BenchEventConsumerModule

NewBenchEventConsumerModule creates a new event consumer module.

func (*BenchEventConsumerModule) Name

func (m *BenchEventConsumerModule) Name() string

Name returns the module name.

func (*BenchEventConsumerModule) RegisterEventConsumers

func (m *BenchEventConsumerModule) RegisterEventConsumers(registry mono.EventRegistry) error

RegisterEventConsumers registers the event consumer handler.

func (*BenchEventConsumerModule) Start

Start is a no-op for benchmark modules.

func (*BenchEventConsumerModule) Stop

Stop is a no-op for benchmark modules.

type BenchEventEmitterModule

type BenchEventEmitterModule struct {
	// contains filtered or unexported fields
}

BenchEventEmitterModule is a minimal event emitter module for benchmarks. It implements Module, EventBusAwareModule, and EventEmitterModule interfaces.

func NewBenchEventEmitterModule

func NewBenchEventEmitterModule(name string, eventDef mono.BaseEventDefinition) *BenchEventEmitterModule

NewBenchEventEmitterModule creates a new event emitter module.

func (*BenchEventEmitterModule) EmitEvents

EmitEvents returns the list of event definitions this module emits.

func (*BenchEventEmitterModule) EventBus

func (m *BenchEventEmitterModule) EventBus() mono.EventBus

EventBus returns the stored event bus.

func (*BenchEventEmitterModule) Name

func (m *BenchEventEmitterModule) Name() string

Name returns the module name.

func (*BenchEventEmitterModule) SetEventBus

func (m *BenchEventEmitterModule) SetEventBus(bus mono.EventBus)

SetEventBus stores the event bus for publishing events.

func (*BenchEventEmitterModule) Start

Start is a no-op for benchmark modules.

func (*BenchEventEmitterModule) Stop

Stop is a no-op for benchmark modules.

type BenchEventStreamConsumerModule

type BenchEventStreamConsumerModule struct {
	// contains filtered or unexported fields
}

BenchEventStreamConsumerModule is a minimal event stream consumer module for benchmarks. It implements Module and EventConsumerModule interfaces with JetStream support.

func NewBenchEventStreamConsumerModule

func NewBenchEventStreamConsumerModule(
	name string,
	eventDef mono.BaseEventDefinition,
	config mono.StreamConsumerConfig,
	handler mono.EventStreamConsumerHandler,
) *BenchEventStreamConsumerModule

NewBenchEventStreamConsumerModule creates a new event stream consumer module with JetStream config.

func (*BenchEventStreamConsumerModule) Name

Name returns the module name.

func (*BenchEventStreamConsumerModule) RegisterEventConsumers

func (m *BenchEventStreamConsumerModule) RegisterEventConsumers(registry mono.EventRegistry) error

RegisterEventConsumers registers the event stream consumer with JetStream config.

func (*BenchEventStreamConsumerModule) Start

Start is a no-op for benchmark modules.

func (*BenchEventStreamConsumerModule) Stop

Stop is a no-op for benchmark modules.

type BenchInventoryModule

type BenchInventoryModule struct {
	// contains filtered or unexported fields
}

BenchInventoryModule is a simplified inventory module for benchmarks. It implements Module and ServiceProviderModule interfaces.

func NewBenchInventoryModule

func NewBenchInventoryModule() *BenchInventoryModule

NewBenchInventoryModule creates a new benchmark inventory module.

func (*BenchInventoryModule) Name

func (m *BenchInventoryModule) Name() string

Name returns the module name.

func (*BenchInventoryModule) RegisterServices

func (m *BenchInventoryModule) RegisterServices(container mono.ServiceContainer) error

RegisterServices registers the check-stock RequestReply service.

func (*BenchInventoryModule) Start

Start is a no-op for benchmark modules.

func (*BenchInventoryModule) Stop

Stop is a no-op for benchmark modules.

type BenchNotificationModule

type BenchNotificationModule struct {
	NotifCount atomic.Int64 // Counter for queue group notifications
	EventCount atomic.Int64 // Counter for event notifications
	// contains filtered or unexported fields
}

BenchNotificationModule is a simplified notification module for benchmarks. It implements ServiceProviderModule (QueueGroup) and EventConsumerModule interfaces.

func NewBenchNotificationModule

func NewBenchNotificationModule() *BenchNotificationModule

NewBenchNotificationModule creates a new benchmark notification module.

func (*BenchNotificationModule) Name

func (m *BenchNotificationModule) Name() string

Name returns the module name.

func (*BenchNotificationModule) RegisterEventConsumers

func (m *BenchNotificationModule) RegisterEventConsumers(registry mono.EventRegistry) error

RegisterEventConsumers registers the event consumer for BenchOrderCreatedV1.

func (*BenchNotificationModule) RegisterServices

func (m *BenchNotificationModule) RegisterServices(container mono.ServiceContainer) error

RegisterServices registers the on-order-created QueueGroup service.

func (*BenchNotificationModule) Start

Start is a no-op for benchmark modules.

func (*BenchNotificationModule) Stop

Stop is a no-op for benchmark modules.

type BenchNotificationRequest

type BenchNotificationRequest struct {
	OrderID   string  `json:"order_id"`
	ProductID string  `json:"product_id"`
	Amount    float64 `json:"amount"`
}

BenchNotificationRequest is a simplified notification request.

type BenchOrderCreatedEvent

type BenchOrderCreatedEvent struct {
	OrderID   string    `json:"order_id"`
	ProductID string    `json:"product_id"`
	Amount    float64   `json:"amount"`
	Timestamp time.Time `json:"timestamp"`
}

BenchOrderCreatedEvent represents the order created event for benchmarks.

type BenchOrderModule

type BenchOrderModule struct {
	// contains filtered or unexported fields
}

BenchOrderModule is a simplified order module that orchestrates the workflow. It implements DependentModule, ServiceProviderModule, and EventEmitterModule interfaces.

func NewBenchOrderModule

func NewBenchOrderModule() *BenchOrderModule

NewBenchOrderModule creates a new benchmark order module.

func (*BenchOrderModule) Container

func (m *BenchOrderModule) Container() mono.ServiceContainer

Container returns the module's service container for external access.

func (*BenchOrderModule) Dependencies

func (m *BenchOrderModule) Dependencies() []string

Dependencies returns the list of module dependencies.

func (*BenchOrderModule) EmitEvents

func (m *BenchOrderModule) EmitEvents() []mono.BaseEventDefinition

EmitEvents returns the list of event definitions this module emits.

func (*BenchOrderModule) Name

func (m *BenchOrderModule) Name() string

Name returns the module name.

func (*BenchOrderModule) RegisterServices

func (m *BenchOrderModule) RegisterServices(container mono.ServiceContainer) error

RegisterServices registers the place-order RequestReply service.

func (*BenchOrderModule) SetDependencyServiceContainer

func (m *BenchOrderModule) SetDependencyServiceContainer(dep string, container mono.ServiceContainer)

SetDependencyServiceContainer stores the dependency's service container.

func (*BenchOrderModule) SetEventBus

func (m *BenchOrderModule) SetEventBus(bus mono.EventBus)

SetEventBus stores the event bus for publishing events.

func (*BenchOrderModule) Start

func (m *BenchOrderModule) Start(_ context.Context) error

Start is a no-op for benchmark modules.

func (*BenchOrderModule) Stop

Stop is a no-op for benchmark modules.

type BenchOrderRequest

type BenchOrderRequest struct {
	ProductID string  `json:"product_id"`
	Quantity  int     `json:"quantity"`
	Amount    float64 `json:"amount"`
	Currency  string  `json:"currency"`
}

BenchOrderRequest is a simplified order request.

type BenchOrderResponse

type BenchOrderResponse struct {
	OrderID string `json:"order_id"`
	Status  string `json:"status"`
}

BenchOrderResponse is a simplified order response.

type BenchPaymentModule

type BenchPaymentModule struct {
	// contains filtered or unexported fields
}

BenchPaymentModule is a simplified payment module for benchmarks. It implements Module and ServiceProviderModule interfaces.

func NewBenchPaymentModule

func NewBenchPaymentModule() *BenchPaymentModule

NewBenchPaymentModule creates a new benchmark payment module.

func (*BenchPaymentModule) Name

func (m *BenchPaymentModule) Name() string

Name returns the module name.

func (*BenchPaymentModule) RegisterServices

func (m *BenchPaymentModule) RegisterServices(container mono.ServiceContainer) error

RegisterServices registers the process RequestReply service.

func (*BenchPaymentModule) Start

Start is a no-op for benchmark modules.

func (*BenchPaymentModule) Stop

Stop is a no-op for benchmark modules.

type BenchPaymentRequest

type BenchPaymentRequest struct {
	OrderID  string  `json:"order_id"`
	Amount   float64 `json:"amount"`
	Currency string  `json:"currency"`
}

BenchPaymentRequest is a simplified payment request.

type BenchPaymentResponse

type BenchPaymentResponse struct {
	Success       bool   `json:"success"`
	TransactionID string `json:"transaction_id"`
}

BenchPaymentResponse is a simplified payment response.

type BenchProviderModule

type BenchProviderModule struct {

	// SetupFunc is called during RegisterServices - set by benchmark to configure services
	SetupFunc func(container mono.ServiceContainer) error
	// contains filtered or unexported fields
}

BenchProviderModule is a minimal provider module for benchmarks. It implements Module and ServiceProviderModule interfaces.

func NewBenchProviderModule

func NewBenchProviderModule(name string) *BenchProviderModule

NewBenchProviderModule creates a new provider module with the given name.

func (*BenchProviderModule) Container

func (m *BenchProviderModule) Container() mono.ServiceContainer

Container returns the module's service container.

func (*BenchProviderModule) Name

func (m *BenchProviderModule) Name() string

Name returns the module name.

func (*BenchProviderModule) RegisterServices

func (m *BenchProviderModule) RegisterServices(container mono.ServiceContainer) error

RegisterServices registers services using the SetupFunc if provided.

func (*BenchProviderModule) Start

Start is a no-op for benchmark modules.

func (*BenchProviderModule) Stop

Stop is a no-op for benchmark modules.

type MultiModuleBenchSetup

type MultiModuleBenchSetup struct {
	App          mono.MonoApplication
	Inventory    *BenchInventoryModule
	Payment      *BenchPaymentModule
	Notification *BenchNotificationModule
	Order        *BenchOrderModule
}

MultiModuleBenchSetup contains all components for multi-module benchmarks.

func NewMultiModuleBenchSetup

func NewMultiModuleBenchSetup() (*MultiModuleBenchSetup, error)

NewMultiModuleBenchSetup creates a complete multi-module benchmark environment.

func (*MultiModuleBenchSetup) Start

Start initializes the benchmark environment.

func (*MultiModuleBenchSetup) Stop

Stop gracefully shuts down the benchmark environment.

type RealisticBenchModule

type RealisticBenchModule struct {
	// contains filtered or unexported fields
}

RealisticBenchModule is a more realistic module for memory/startup benchmarks. It includes internal data structures, proper lifecycle, and a registered service. Use this for benchmarks that need to simulate real-world module behavior with internal state and service registration overhead.

For minimal overhead benchmarks focusing on framework-level operations, use BenchProviderModule instead.

func NewRealisticBenchModule

func NewRealisticBenchModule(name string) *RealisticBenchModule

NewRealisticBenchModule creates a new realistic module with the given name.

func (*RealisticBenchModule) Container

Container returns the module's service container.

func (*RealisticBenchModule) Name

func (m *RealisticBenchModule) Name() string

Name returns the module name.

func (*RealisticBenchModule) RegisterServices

func (m *RealisticBenchModule) RegisterServices(container mono.ServiceContainer) error

RegisterServices registers a simple echo service.

func (*RealisticBenchModule) Start

Start initializes internal data structures (simulates loading config/state). No lock needed - Start() is called during single-threaded initialization.

func (*RealisticBenchModule) Stop

Stop cleans up internal resources. Clear instead of nil to allow restart (common in benchmark scenarios).

Directories

Path Synopsis
cmd
benchparse command
Package main provides a tool to parse Go benchmark JSON output and convert it to a structured JSON format for benchmark result reporting.
Package main provides a tool to parse Go benchmark JSON output and convert it to a structured JSON format for benchmark result reporting.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL