benchmarks

package
v0.20.2 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2025 License: Apache-2.0 Imports: 11 Imported by: 0

README ΒΆ

Engine-CI Performance Benchmarks

This directory contains comprehensive performance benchmarks and regression testing infrastructure for the engine-ci project, designed to support Issue #196 performance optimizations.

🎯 Performance Targets

Based on the analysis, we're targeting the following improvements:

Container Operations (pkg/container/container.go)
  • Target: 25-40% reduction in container operation time
  • Key Areas:
    • Container creation and initialization
    • Image tag parsing
    • Checksum computation
    • Tar directory operations
Log Aggregation (pkg/logger/terminal.go)
  • Target: 30-50% reduction in memory usage for large builds
  • Key Areas:
    • Log message buffering and aggregation
    • Concurrent log processing
    • String manipulation operations
Build Configuration (pkg/container/build.go)
  • Target: 60% reduction in string operation allocations
  • Key Areas:
    • Flag string building
    • Configuration serialization
    • Custom map operations
Container Runtime Management (pkg/cri/manager.go)
  • Target: 2-3x improvement in concurrent operation throughput
  • Key Areas:
    • Runtime detection
    • Manager initialization
    • Singleton access patterns

πŸ“ Directory Structure

benchmarks/
β”œβ”€β”€ README.md                 # This file
β”œβ”€β”€ benchmark_runner.go       # Main benchmark execution and analysis tool
β”œβ”€β”€ regression_tests.go       # Performance regression testing framework
β”œβ”€β”€ results/                  # Benchmark results storage
β”‚   β”œβ”€β”€ baseline.json        # Performance baseline for comparisons
β”‚   β”œβ”€β”€ benchmark_*.json     # Individual benchmark runs
β”‚   └── regression_*.json    # Regression test results
└── scripts/
    └── run_benchmarks.sh    # Convenience script for running benchmarks

πŸš€ Quick Start

1. Create Performance Baseline

First, establish a baseline of current performance:

# Run from project root
./scripts/run_benchmarks.sh --baseline

This will:

  • Run all benchmark suites
  • Generate performance analysis
  • Save baseline results for future comparisons
2. Run Full Benchmark Suite
# Run comprehensive benchmarks with analysis
./scripts/run_benchmarks.sh

# Or explicitly
./scripts/run_benchmarks.sh --full
3. Run Regression Tests

After making performance changes:

./scripts/run_benchmarks.sh --regression

This will compare current performance against the baseline and flag any regressions.

πŸ“Š Benchmark Categories

Container Operations Benchmarks
  • New Container Creation: Tests container initialization overhead
  • Parse Image Tag: Benchmarks image string parsing efficiency
  • Checksum Computation: Tests cryptographic operations on various data sizes
  • Tar Operations: Benchmarks directory archiving with different file sizes/counts
  • String Operations: Tests frequently-called string manipulation functions
  • Concurrent Operations: Benchmarks thread-safe operations under load
Logger Benchmarks
  • LogAggregator Creation: Tests singleton initialization overhead
  • Message Logging: Benchmarks single vs. multiple routine logging
  • Progress Format: Tests real-time log display performance
  • LogEntry Operations: Benchmarks message buffering and overflow handling
  • Concurrent Logging: Tests thread-safe logging under high concurrency
  • I/O Operations: Benchmarks write and copy operations with various data sizes
Build Configuration Benchmarks
  • Build Creation: Tests build configuration initialization
  • String Building: Benchmarks AsFlags() and similar operations
  • Custom Map Operations: Tests configuration parameter access
  • Type Conversions: Benchmarks string-to-type conversions
  • Complex Build Operations: Tests full build configuration scenarios
Container Runtime Manager Benchmarks
  • Runtime Detection: Tests container runtime discovery
  • Manager Initialization: Benchmarks singleton initialization patterns
  • Concurrent Access: Tests thread-safe manager access
  • Factory Operations: Benchmarks manager creation patterns

πŸ” Benchmark Analysis Features

Performance Metrics
  • Execution Time: Nanoseconds per operation
  • Memory Allocations: Allocations per operation
  • Memory Usage: Bytes allocated per operation
  • Throughput: Operations per second (where applicable)
Automated Analysis
  • Performance Flags: Automatically flags operations exceeding thresholds:
    • Slow operations (>1ms per operation)
    • High allocation operations (>1000 allocs/op)
    • High memory operations (>10KB per operation)
  • Top Performers: Identifies slowest operations and highest allocators
  • Regression Detection: Compares against baseline with configurable thresholds
Reporting
  • JSON Output: Machine-readable results for CI/CD integration
  • Human-Readable Reports: Formatted console output with summaries
  • Historical Tracking: Maintains history of performance changes

πŸ§ͺ Regression Testing

Critical Performance Tests

The regression testing framework includes predefined tests for critical performance paths:

Container Operations (Critical)
  • New Container Creation: Max 15% performance regression
  • Parse Image Tag: Max 20% performance regression
  • Checksum Computation: No allocation increases allowed
String Operations (Critical)
  • Safe Short Operation: Max 10% performance regression, no new allocations
  • Concurrent Image Tag Parsing: Max 15% performance regression
Logger Operations (Critical)
  • Single Routine Logging: Max 15% performance regression
  • Multiple Routine Logging: Max 25% performance regression
  • Singleton Access: Max 5% performance regression, no new allocations
Customizable Thresholds

Each regression test can be configured with:

  • Max Performance Drop: Percentage threshold for acceptable regression
  • Max Allocation Increase: Absolute increase in allocations per operation
  • Max Memory Increase: Absolute increase in bytes per operation
  • Critical Flag: Whether failures should cause CI/CD pipeline failures

πŸ“ˆ Performance Optimization Workflow

1. Establish Baseline
./scripts/run_benchmarks.sh --baseline
2. Make Performance Changes

Implement optimizations targeting specific bottlenecks identified in the analysis.

3. Run Benchmarks
./scripts/run_benchmarks.sh
4. Analyze Results

Review the automated analysis for:

  • Performance improvements vs. targets
  • Any unexpected regressions
  • Memory allocation changes
5. Run Regression Tests
./scripts/run_benchmarks.sh --regression
6. Iterate

Repeat the process, using previous results to guide further optimizations.

πŸ”§ Integration with CI/CD

GitHub Actions Integration

Add to your workflow:

- name: Run Performance Benchmarks
  run: |
    ./scripts/run_benchmarks.sh --full
    
- name: Check for Performance Regressions
  run: |
    ./scripts/run_benchmarks.sh --regression
Performance Monitoring

The benchmark results can be integrated with monitoring systems:

  • Metrics: Export performance metrics to Prometheus/Grafana
  • Alerts: Set up alerts for performance regressions
  • Dashboards: Create dashboards showing performance trends over time

πŸ“‹ Benchmark Interpretation Guide

Understanding Results
BenchmarkContainerOperations/New_Container_Creation-8    5000000    292 ns/op    48 B/op    2 allocs/op
  • 5000000: Number of iterations run
  • 292 ns/op: Average nanoseconds per operation
  • 48 B/op: Average bytes allocated per operation
  • 2 allocs/op: Average number of allocations per operation
Performance Targets
  • Sub-millisecond: Critical path operations should complete in <1ms
  • Low Allocation: Frequently called functions should minimize allocations
  • Memory Efficiency: Large operations should maintain reasonable memory usage
  • Scalability: Concurrent operations should scale with available cores
Red Flags
  • High Allocation Count: >1000 allocations per operation
  • Large Memory Usage: >10KB per operation for simple functions
  • Slow Operations: >1ms for frequently called functions
  • Poor Concurrency: Performance doesn't improve with parallel execution

πŸ› οΈ Extending Benchmarks

Adding New Benchmarks
  1. Create benchmark functions in *_bench_test.go files
  2. Follow Go benchmark naming conventions: BenchmarkXxx(*testing.B)
  3. Use b.ResetTimer() and b.ReportAllocs() appropriately
  4. Add regression tests to regression_tests.go if critical
Benchmark Best Practices
  • Realistic Data: Use representative data sizes and patterns
  • Warm-up: Allow for JIT compilation and cache warming
  • Isolation: Test one thing at a time
  • Repeatability: Ensure consistent results across runs
  • Memory Profiling: Use b.ReportAllocs() for memory-sensitive operations

πŸ“š Additional Resources

🀝 Contributing

When contributing performance optimizations:

  1. Benchmark First: Always establish current performance with benchmarks
  2. Measure Changes: Use benchmarks to validate improvements
  3. Regression Test: Ensure changes don't break existing performance
  4. Document: Update benchmarks and documentation for new critical paths

πŸ“ž Support

For questions about the benchmark infrastructure or performance optimization:

  1. Check existing benchmark results in benchmarks/results/
  2. Review regression test definitions in regression_tests.go
  3. Examine benchmark implementations in *_bench_test.go files
  4. Create an issue with benchmark results and specific questions

Documentation ΒΆ

Index ΒΆ

Constants ΒΆ

View Source
const (
	// Performance thresholds for flagging
	SlowOperationThresholdNs = 1000000 // 1ms
	HighAllocationThreshold  = 1000    // 1000 allocs per op
	HighMemoryThreshold      = 10000   // 10KB per op
)

Variables ΒΆ

This section is empty.

Functions ΒΆ

func RunBenchmarkSuite ΒΆ

func RunBenchmarkSuite()

RunBenchmarkSuite runs the complete benchmark suite

func RunRegressionTestSuite ΒΆ

func RunRegressionTestSuite()

RunRegressionTestSuite runs the regression test suite

Types ΒΆ

type BenchmarkResult ΒΆ

type BenchmarkResult struct {
	Name        string  `json:"name"`
	Package     string  `json:"package"`
	Timestamp   string  `json:"timestamp"`
	Iterations  int64   `json:"iterations"`
	NsPerOp     float64 `json:"ns_per_op"`
	MBPerSec    float64 `json:"mb_per_sec,omitempty"`
	AllocsPerOp int64   `json:"allocs_per_op,omitempty"`
	BytesPerOp  int64   `json:"bytes_per_op,omitempty"`
}

BenchmarkResult represents a single benchmark result

type BenchmarkSuite ΒΆ

type BenchmarkSuite struct {
	Timestamp string            `json:"timestamp"`
	GoVersion string            `json:"go_version"`
	GitCommit string            `json:"git_commit"`
	Results   []BenchmarkResult `json:"results"`
	Summary   BenchmarkSummary  `json:"summary"`
}

BenchmarkSuite represents a collection of benchmark results

type BenchmarkSummary ΒΆ

type BenchmarkSummary struct {
	PackageBreakdown  map[string]int    `json:"package_breakdown"`
	PerformanceFlags  []string          `json:"performance_flags"`
	TopSlowestOps     []BenchmarkResult `json:"top_slowest_ops"`
	HighestAllocators []BenchmarkResult `json:"highest_allocators"`
	TotalBenchmarks   int               `json:"total_benchmarks"`
}

BenchmarkSummary provides high-level statistics

type PerformanceChanges ΒΆ

type PerformanceChanges struct {
	PerformanceChange float64 `json:"performance_change"` // % change in ns/op
	AllocationChange  int64   `json:"allocation_change"`  // absolute change in allocs/op
	MemoryChange      int64   `json:"memory_change"`      // absolute change in bytes/op
}

PerformanceChanges tracks specific performance metrics changes

type RegressionResult ΒΆ

type RegressionResult struct {
	Message  string             `json:"message"`
	Test     RegressionTest     `json:"test"`
	Current  BenchmarkResult    `json:"current"`
	Baseline BenchmarkResult    `json:"baseline"`
	Changes  PerformanceChanges `json:"changes"`
	Passed   bool               `json:"passed"`
}

RegressionResult represents the result of a regression test

type RegressionTest ΒΆ

type RegressionTest struct {
	Name                  string  `json:"name"`
	MaxPerformanceDrop    float64 `json:"max_performance_drop"`    // Maximum allowed performance regression (%)
	MaxAllocationIncrease int64   `json:"max_allocation_increase"` // Maximum allowed allocation increase
	MaxMemoryIncrease     int64   `json:"max_memory_increase"`     // Maximum allowed memory increase (bytes)
	Critical              bool    `json:"critical"`                // Is this a critical performance test?
}

RegressionTest defines performance regression thresholds

type RegressionTestSuite ΒΆ

type RegressionTestSuite struct {
	Tests []RegressionTest `json:"tests"`
}

RegressionTestSuite contains all regression tests

Jump to

Keyboard shortcuts

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