name: 性能基准测试 on: push: tags: - 'v*' workflow_dispatch: inputs: benchtime: description: '基准测试运行时间' required: false default: '10s' count: description: '基准测试运行次数' required: false default: '5' jobs: benchmark: name: 完整性能基准测试 runs-on: ubuntu-latest steps: - name: 检出代码 uses: actions/checkout@v4 - name: 设置 Go 环境 uses: actions/setup-go@v4 with: go-version: 1.24.x - name: 系统信息 run: | echo "=== 系统信息 ===" uname -a cat /proc/cpuinfo | grep "model name" | head -1 cat /proc/meminfo | grep MemTotal df -h / - name: Go 环境信息 run: | echo "=== Go 环境信息 ===" go version go env - name: 预热系统 run: | echo "=== 系统预热 ===" go test -bench=BenchmarkPipelineDBOpen -benchtime=100ms -run=^$ ./... - name: 数据库核心功能基准测试 run: | echo "=== 数据库核心功能基准测试 ===" go test -bench=BenchmarkPipelineDB -benchmem -count=${{ github.event.inputs.count || '5' }} -benchtime=${{ github.event.inputs.benchtime || '2s' }} -run=^$ ./... | tee core_bench.txt - name: 并发性能基准测试 run: | echo "=== 并发性能基准测试 ===" go test -bench=BenchmarkConcurrent -benchmem -count=${{ github.event.inputs.count || '5' }} -benchtime=${{ github.event.inputs.benchtime || '2s' }} -run=^$ ./... | tee concurrent_bench.txt - name: 存储引擎基准测试 run: | echo "=== 存储引擎基准测试 ===" go test -bench=BenchmarkStorage -benchmem -count=${{ github.event.inputs.count || '5' }} -benchtime=${{ github.event.inputs.benchtime || '2s' }} -run=^$ ./... | tee storage_bench.txt - name: 缓存系统基准测试 run: | echo "=== 缓存系统基准测试 ===" go test -bench=BenchmarkCache -benchmem -count=${{ github.event.inputs.count || '5' }} -benchtime=${{ github.event.inputs.benchtime || '2s' }} -run=^$ ./... | tee cache_bench.txt - name: 索引管理基准测试 run: | echo "=== 索引管理基准测试 ===" go test -bench=BenchmarkIndex -benchmem -count=${{ github.event.inputs.count || '5' }} -benchtime=${{ github.event.inputs.benchtime || '2s' }} -run=^$ ./... | tee index_bench.txt - name: 组管理基准测试 run: | echo "=== 组管理基准测试 ===" go test -bench=BenchmarkGroup -benchmem -count=${{ github.event.inputs.count || '5' }} -benchtime=${{ github.event.inputs.benchtime || '2s' }} -run=^$ ./... | tee group_bench.txt - name: Handler 处理器基准测试 run: | echo "=== Handler 处理器基准测试 ===" go test -bench=BenchmarkHandler -benchmem -count=${{ github.event.inputs.count || '5' }} -benchtime=${{ github.event.inputs.benchtime || '2s' }} -run=^$ ./... | tee handler_bench.txt - name: 高并发压力测试 run: | echo "=== 高并发压力测试 ===" go test -bench=BenchmarkHighConcurrency -benchmem -count=3 -benchtime=5s -run=^$ ./... | tee high_concurrency_bench.txt - name: 内存分析 run: | echo "=== 内存分析 ===" go test -bench=BenchmarkConcurrentAcceptData -benchmem -memprofile=mem.prof -run=^$ ./... go tool pprof -text mem.prof | head -20 - name: CPU 分析 run: | echo "=== CPU 分析 ===" go test -bench=BenchmarkConcurrentAcceptData -cpuprofile=cpu.prof -run=^$ ./... go tool pprof -text cpu.prof | head -20 - name: 生成性能报告 run: | echo "=== 性能基准测试报告 ===" > benchmark_report.md echo "**测试时间:** $(date)" >> benchmark_report.md echo "**Go 版本:** $(go version)" >> benchmark_report.md echo "**系统信息:** $(uname -a)" >> benchmark_report.md echo "" >> benchmark_report.md echo "## 📊 核心功能性能" >> benchmark_report.md echo "\`\`\`" >> benchmark_report.md cat core_bench.txt | grep "Benchmark" >> benchmark_report.md echo "\`\`\`" >> benchmark_report.md echo "" >> benchmark_report.md echo "## 🚀 并发性能" >> benchmark_report.md echo "\`\`\`" >> benchmark_report.md cat concurrent_bench.txt | grep "Benchmark" >> benchmark_report.md echo "\`\`\`" >> benchmark_report.md echo "" >> benchmark_report.md echo "## 💾 存储引擎性能" >> benchmark_report.md echo "\`\`\`" >> benchmark_report.md cat storage_bench.txt | grep "Benchmark" >> benchmark_report.md echo "\`\`\`" >> benchmark_report.md echo "" >> benchmark_report.md echo "## ⚡ 缓存系统性能" >> benchmark_report.md echo "\`\`\`" >> benchmark_report.md cat cache_bench.txt | grep "Benchmark" >> benchmark_report.md echo "\`\`\`" >> benchmark_report.md echo "" >> benchmark_report.md echo "## 🔍 索引管理性能" >> benchmark_report.md echo "\`\`\`" >> benchmark_report.md cat index_bench.txt | grep "Benchmark" >> benchmark_report.md echo "\`\`\`" >> benchmark_report.md echo "" >> benchmark_report.md echo "## 📁 组管理性能" >> benchmark_report.md echo "\`\`\`" >> benchmark_report.md cat group_bench.txt | grep "Benchmark" >> benchmark_report.md echo "\`\`\`" >> benchmark_report.md echo "" >> benchmark_report.md echo "## 🔧 Handler 处理器性能" >> benchmark_report.md echo "\`\`\`" >> benchmark_report.md cat handler_bench.txt | grep "Benchmark" >> benchmark_report.md echo "\`\`\`" >> benchmark_report.md echo "" >> benchmark_report.md echo "## 💥 高并发压力测试" >> benchmark_report.md echo "\`\`\`" >> benchmark_report.md cat high_concurrency_bench.txt | grep "Benchmark" >> benchmark_report.md echo "\`\`\`" >> benchmark_report.md cat benchmark_report.md - name: 性能趋势分析 run: | echo "=== 性能趋势分析 ===" # 提取关键性能指标 ACCEPT_DATA_QPS=$(cat core_bench.txt | grep "BenchmarkAcceptData" | awk '{print $3}' | tail -1) QUERY_QPS=$(cat concurrent_bench.txt | grep "BenchmarkConcurrentQuery" | awk '{print $3}' | tail -1) CACHE_OPS=$(cat cache_bench.txt | grep "BenchmarkCacheOperations" | awk '{print $3}' | tail -1) echo "关键性能指标:" echo "- AcceptData QPS: $ACCEPT_DATA_QPS" echo "- 并发查询 QPS: $QUERY_QPS" echo "- 缓存操作 QPS: $CACHE_OPS" # 性能阈值检查 if [ ! -z "$ACCEPT_DATA_QPS" ] && [ "$ACCEPT_DATA_QPS" -lt 1000 ]; then echo "⚠️ AcceptData 性能低于预期阈值 (1000 ops/sec)" fi if [ ! -z "$CACHE_OPS" ] && [ "$CACHE_OPS" -lt 5000000 ]; then echo "⚠️ 缓存操作性能低于预期阈值 (5M ops/sec)" fi - name: 上传基准测试结果 uses: actions/upload-artifact@v3 with: name: benchmark-results-${{ github.run_number }} path: | *_bench.txt benchmark_report.md *.prof - name: 上传性能分析文件 uses: actions/upload-artifact@v3 with: name: performance-profiles-${{ github.run_number }} path: | mem.prof cpu.prof stress_test: name: 压力测试 runs-on: ubuntu-latest needs: benchmark steps: - name: 检出代码 uses: actions/checkout@v4 - name: 设置 Go 环境 uses: actions/setup-go@v4 with: go-version: 1.24.x - name: 长时间压力测试 timeout-minutes: 30 run: | echo "=== 长时间压力测试 (20分钟) ===" timeout 1200s go test -bench=BenchmarkHighConcurrencyWrite -benchtime=20m -run=^$ ./... || true - name: 内存泄漏检测 run: | echo "=== 内存泄漏检测 ===" go test -bench=BenchmarkConcurrentAcceptData -benchtime=30s -memprofile=leak_test.prof -run=^$ ./... go tool pprof -alloc_space -text leak_test.prof | head -20 - name: 竞态条件检测 run: | echo "=== 竞态条件检测 ===" go test -race -bench=BenchmarkConcurrent -benchtime=10s -run=^$ ./... - name: 上传压力测试结果 uses: actions/upload-artifact@v3 if: always() with: name: stress-test-results-${{ github.run_number }} path: | leak_test.prof