Skip to content

Latest commit

 

History

History
376 lines (296 loc) · 9.73 KB

File metadata and controls

376 lines (296 loc) · 9.73 KB

🚀 FreshLogger Performance Benchmark Guide

Author: Ömer Bulut
Version: 1.3.0
Last Updated: August 16, 2025


📋 Table of Contents

  1. Overview
  2. Running Performance Tests
  3. Understanding Benchmark Results
  4. Performance Metrics
  5. Benchmark Analysis
  6. Performance Optimization
  7. Regression Detection
  8. Troubleshooting

🎯 Overview

FreshLogger includes comprehensive performance testing to ensure enterprise-grade performance. This guide explains how to run benchmarks, interpret results, and optimize performance.

Performance Targets

  • Throughput: >1M messages/second
  • Latency: <1 μs average
  • Memory: <100MB overhead
  • Scalability: Linear scaling up to 16 threads

🧪 Running Performance Tests

Quick Performance Test

# Build performance tests
make performance_tests

# Run all performance tests
./performance_tests

# Run specific test
./performance_tests --gtest_filter="PerformanceTest.SynchronousThroughput"

Enterprise Performance Suite

# Run complete enterprise test suite
make enterprise-test

# Run performance regression detection
make perf-regression

# Generate performance report
make perf-report

Performance Test Categories

1. Synchronous Throughput Test

./performance_tests --gtest_filter="PerformanceTest.SynchronousThroughput"

Purpose: Measures single-threaded logging performance

2. Asynchronous Throughput Test

./performance_tests --gtest_filter="PerformanceTest.AsynchronousThroughput"

Purpose: Measures async logging performance with queue

3. Single Message Latency Test

./performance_tests --gtest_filter="PerformanceTest.SingleMessageLatency"

Purpose: Measures individual message latency

4. Memory Usage Test

./performance_tests --gtest_filter="PerformanceTest.MemoryUsageUnderLoad"

Purpose: Measures memory consumption under load

5. Multi-threaded Throughput Test

./performance_tests --gtest_filter="PerformanceTest.MultiThreadedThroughput"

Purpose: Measures concurrent logging performance


📊 Understanding Benchmark Results

Sample Output Analysis

Synchronous Throughput Test

=== SYNCHRONOUS THROUGHPUT TEST ===
Messages: 10000
Duration: 2068 μs
Throughput: 4835589.94 msg/sec
[       OK ] PerformanceTest.SynchronousThroughput (2 ms)

Interpretation:

  • Messages: 10,000 test messages
  • Duration: 2,068 microseconds (2.068 ms)
  • Throughput: 4,835,589.94 messages/second
  • Status: ✅ PASSED (exceeds 1M msg/sec target)

Asynchronous Throughput Test

=== ASYNCHRONOUS THROUGHPUT TEST ===
Messages: 100000
Duration: 23959 μs
Throughput: 4173796.90 msg/sec
[       OK ] PerformanceTest.AsynchronousThroughput (32 ms)

Interpretation:

  • Messages: 100,000 test messages
  • Duration: 23,959 microseconds (23.959 ms)
  • Throughput: 4,173,796.90 messages/second
  • Status: ✅ PASSED (exceeds 1M msg/sec target)

Single Message Latency Test

=== SINGLE MESSAGE LATENCY TEST ===
Average Latency: 0 μs
Min Latency: 0 μs
Max Latency: 6 μs
[       OK ] PerformanceTest.SingleMessageLatency (0 ms)

Interpretation:

  • Average: 0 μs (sub-microsecond performance)
  • Min: 0 μs (best case)
  • Max: 6 μs (worst case)
  • Status: ✅ PASSED (exceeds <1 μs target)

📈 Performance Metrics

Throughput Metrics

Messages per Second (msg/sec)

  • Definition: Number of log messages processed per second
  • Target: >1,000,000 msg/sec
  • Measurement: High message volume over time

Throughput Categories

Category Range Status Use Case
Low <100K msg/sec ⚠️ Needs optimization Development
Medium 100K-1M msg/sec ✅ Acceptable Testing
High 1M-10M msg/sec 🚀 Excellent Production
Extreme >10M msg/sec 🌟 Outstanding High-performance

Latency Metrics

Microsecond Latency (μs)

  • Definition: Time to process single log message
  • Target: <1 μs average
  • Measurement: Individual message timing

Latency Categories

Category Range Status Impact
Ultra-low <1 μs 🚀 Excellent Real-time systems
Low 1-10 μs ✅ Good General applications
Medium 10-100 μs ⚠️ Acceptable Non-critical systems
High >100 μs ❌ Needs optimization Performance issues

Memory Metrics

Memory Usage (KB/MB)

  • Definition: Memory consumed during logging
  • Target: <100MB overhead
  • Measurement: Before/after logging operations

Memory Categories

Category Range Status Efficiency
Excellent <10MB 🚀 Outstanding Highly efficient
Good 10-50MB ✅ Good Efficient
Acceptable 50-100MB ⚠️ Acceptable Moderate efficiency
Poor >100MB ❌ Needs optimization Inefficient

🔍 Benchmark Analysis

Performance Comparison

Synchronous vs Asynchronous

=== BENCHMARK COMPARISON ===
Sync Logging: 2544529.26 msg/sec
Async Logging: 5102040.82 msg/sec
Multi-thread Async: 3125000.00 msg/sec

Analysis:

  • Async is 2x faster than sync (5.1M vs 2.5M msg/sec)
  • Multi-thread async provides balanced performance
  • Sync logging is simpler but slower

Thread Scaling Analysis

=== MULTI-THREADED THROUGHPUT TEST ===
Threads: 8
Total Messages: 100000
Duration: 83241 μs
Throughput: 1201331.07 msg/sec

Analysis:

  • 8 threads: 1.2M msg/sec
  • Single thread: 2.5M msg/sec
  • Scaling: Not linear due to synchronization overhead

Performance Regression Detection

Regression Test Output

=== PERFORMANCE REGRESSION TEST ===
Baseline Throughput: 7936507.94 msg/sec
Iteration 1 Throughput: 6289308.18 msg/sec (Ratio: 0.792)
Iteration 2 Throughput: 6250000.00 msg/sec (Ratio: 0.787)
Iteration 3 Throughput: 6451612.90 msg/sec (Ratio: 0.813)

Analysis:

  • Baseline: 7.9M msg/sec (reference performance)
  • Current: 6.2-6.4M msg/sec
  • Regression: ~20% performance decrease
  • Status: ⚠️ Performance regression detected

Regression Thresholds

Ratio Status Action Required
>0.95 ✅ No regression Continue development
0.90-0.95 ⚠️ Minor regression Monitor closely
0.80-0.90 ❌ Moderate regression Investigate cause
<0.80 🚨 Major regression Immediate fix required

⚡ Performance Optimization

Configuration Optimization

High-Throughput Configuration

Logger::Config config;
config.asyncLogging = true;           // Enable async logging
config.queueSize = 100000;            // Large queue for bursts
config.flushInterval = 1;             // Frequent flushing
config.maxFileSize = 100 * 1024 * 1024; // 100MB files
config.maxFiles = 3;                  // Fewer files for speed

Low-Latency Configuration

Logger::Config config;
config.asyncLogging = false;          // Synchronous for low latency
config.consoleOutput = false;         // Disable console for speed
config.maxFileSize = 10 * 1024 * 1024; // 10MB files
config.maxFiles = 2;                  // Minimal file rotation

Memory-Efficient Configuration

Logger::Config config;
config.asyncLogging = true;           // Async reduces memory pressure
config.queueSize = 10000;             // Smaller queue
config.flushInterval = 5;             // Less frequent flushing
config.maxFileSize = 50 * 1024 * 1024; // 50MB files
config.maxFiles = 5;                  // Balanced file count

Code Optimization

String Concatenation

// ❌ Inefficient
logger.info("Processing " + std::to_string(count) + " items");

// ✅ Efficient
logger.info("Processing {} items", count);

// ✅ Most efficient
logger.info("Processing " + std::to_string(count) + " items");

Conditional Logging

// ❌ Always evaluates
logger.debug("Complex calculation: " + complexFunction());

// ✅ Conditional evaluation
if (logger.getLogLevel() <= Logger::LogLevel::DEBUG) {
    logger.debug("Complex calculation: " + complexFunction());
}

Batch Logging

// ❌ Individual calls
for (const auto& item : items) {
    logger.debug("Item: " + item.toString());
}

// ✅ Batch processing
std::string batch;
for (const auto& item : items) {
    batch += "Item: " + item.toString() + "\n";
}
logger.debug(batch);

📊 Regression Detection

Automated Regression Testing

Performance Baseline Creation

# Create performance baseline
make perf-baseline

# This creates:
# - performance_baselines/baseline_YYYYMMDD_HHMMSS.json
# - Historical performance data

Regression Detection

# Detect performance regressions
make perf-regression

# This compares current performance against baseline
# - Generates regression report
# - Alerts if performance drops below threshold

Performance Reports

# Generate detailed performance report
make perf-report

# This creates:
# - HTML performance report
# - Performance trends
# - Optimization recommendations

Manual Regression Analysis

Step 1: Establish Baseline

# Run performance tests multiple times
for i in {1..5}; do
    ./performance_tests --gtest_filter="PerformanceTest.SynchronousThroughput"
done

# Calculate average baseline
# Baseline: 4,835,589 msg/sec

Step 2: Make Changes