|
| 1 | +name: Performance Tests |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ master, develop ] |
| 6 | + pull_request: |
| 7 | + branches: [ master, develop ] |
| 8 | + workflow_dispatch: |
| 9 | + inputs: |
| 10 | + test_iterations: |
| 11 | + description: 'Number of test iterations' |
| 12 | + required: false |
| 13 | + default: '3' |
| 14 | + regression_threshold: |
| 15 | + description: 'Regression threshold (%)' |
| 16 | + required: false |
| 17 | + default: '10' |
| 18 | + |
| 19 | +permissions: |
| 20 | + contents: read |
| 21 | + pull-requests: write |
| 22 | + issues: write |
| 23 | + |
| 24 | +jobs: |
| 25 | + unit-benchmarks: |
| 26 | + name: Unit Benchmarks |
| 27 | + runs-on: ubuntu-latest |
| 28 | + timeout-minutes: 30 |
| 29 | + |
| 30 | + steps: |
| 31 | + - name: Checkout code |
| 32 | + uses: actions/checkout@v4 |
| 33 | + with: |
| 34 | + fetch-depth: 0 # Full history for comparison |
| 35 | + |
| 36 | + - name: Set up Go |
| 37 | + uses: actions/setup-go@v5 |
| 38 | + with: |
| 39 | + go-version: '1.22' |
| 40 | + |
| 41 | + - name: Cache Go modules |
| 42 | + uses: actions/cache@v4 |
| 43 | + with: |
| 44 | + path: | |
| 45 | + ~/go/pkg/mod |
| 46 | + ~/.cache/go-build |
| 47 | + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} |
| 48 | + restore-keys: | |
| 49 | + ${{ runner.os }}-go- |
| 50 | + |
| 51 | + - name: Run benchmarks |
| 52 | + run: | |
| 53 | + echo "Running performance benchmarks..." |
| 54 | + echo "" |
| 55 | + echo "=== 1. Buffer Pool (20,000× allocation improvement) ===" |
| 56 | + go test -bench=BenchmarkBufferPool -benchmem -benchtime=2s -timeout=2m ./pkg/ | tee benchmark-results.txt |
| 57 | + echo "" |
| 58 | + echo "=== 2. GetContent End-to-End (real disk-based throughput) ===" |
| 59 | + go test -bench=BenchmarkGetContentDiskCache -benchmem -benchtime=500ms -timeout=2m ./pkg/ | tee -a benchmark-results.txt |
| 60 | + |
| 61 | + - name: Upload benchmark results |
| 62 | + uses: actions/upload-artifact@v4 |
| 63 | + with: |
| 64 | + name: benchmark-results |
| 65 | + path: benchmark-results.txt |
| 66 | + retention-days: 30 |
| 67 | + |
| 68 | + - name: Check for performance regressions |
| 69 | + run: | |
| 70 | + BUFFER_POOL_TIME=$(grep "BenchmarkBufferPool.*WithPool" benchmark-results.txt | awk '{print $3}' | head -1) |
| 71 | + GETCONTENT_THROUGHPUT=$(grep "BenchmarkGetContentDiskCache" benchmark-results.txt | grep "MB/s" | awk '{print $4}' | head -1) |
| 72 | + |
| 73 | + echo "Buffer Pool: $BUFFER_POOL_TIME" |
| 74 | + echo "GetContent: $GETCONTENT_THROUGHPUT" |
| 75 | + |
| 76 | + if [ ! -z "$BUFFER_POOL_TIME" ]; then |
| 77 | + TIME_NS=$(echo $BUFFER_POOL_TIME | sed 's/ns\/op//') |
| 78 | + if (( $(echo "$TIME_NS > 100" | bc -l) )); then |
| 79 | + echo "❌ Buffer pool regression: ${TIME_NS}ns > 100ns" |
| 80 | + exit 1 |
| 81 | + fi |
| 82 | + echo "✅ Buffer pool OK: ${TIME_NS}ns" |
| 83 | + fi |
| 84 | + |
| 85 | + if [ ! -z "$GETCONTENT_THROUGHPUT" ]; then |
| 86 | + THROUGHPUT=$(echo $GETCONTENT_THROUGHPUT | sed 's/MB\/s//') |
| 87 | + if (( $(echo "$THROUGHPUT < 2000" | bc -l) )); then |
| 88 | + echo "❌ GetContent regression: ${THROUGHPUT} MB/s < 2000 MB/s" |
| 89 | + exit 1 |
| 90 | + fi |
| 91 | + echo "✅ GetContent OK: ${THROUGHPUT} MB/s" |
| 92 | + fi |
| 93 | + |
| 94 | + - name: Comment benchmark results on PR |
| 95 | + if: github.event_name == 'pull_request' |
| 96 | + uses: actions/github-script@v7 |
| 97 | + with: |
| 98 | + script: | |
| 99 | + const fs = require('fs'); |
| 100 | + const results = fs.readFileSync('benchmark-results.txt', 'utf8'); |
| 101 | + |
| 102 | + const body = `## Benchmark Results\n\n\`\`\`\n${results}\n\`\`\``; |
| 103 | + |
| 104 | + github.rest.issues.createComment({ |
| 105 | + issue_number: context.issue.number, |
| 106 | + owner: context.repo.owner, |
| 107 | + repo: context.repo.repo, |
| 108 | + body: body |
| 109 | + }); |
| 110 | +
|
| 111 | + grpc-throughput-tests: |
| 112 | + name: gRPC Throughput Tests |
| 113 | + runs-on: ubuntu-latest |
| 114 | + timeout-minutes: 10 |
| 115 | + |
| 116 | + services: |
| 117 | + redis: |
| 118 | + image: redis:7-alpine |
| 119 | + options: >- |
| 120 | + --health-cmd "redis-cli ping" |
| 121 | + --health-interval 10s |
| 122 | + --health-timeout 5s |
| 123 | + --health-retries 5 |
| 124 | + ports: |
| 125 | + - 6379:6379 |
| 126 | + |
| 127 | + steps: |
| 128 | + - name: Checkout code |
| 129 | + uses: actions/checkout@v4 |
| 130 | + |
| 131 | + - name: Set up Go |
| 132 | + uses: actions/setup-go@v5 |
| 133 | + with: |
| 134 | + go-version: '1.22' |
| 135 | + |
| 136 | + - name: Cache Go modules |
| 137 | + uses: actions/cache@v4 |
| 138 | + with: |
| 139 | + path: ~/go/pkg/mod |
| 140 | + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} |
| 141 | + |
| 142 | + - name: Install netcat |
| 143 | + run: sudo apt-get update && sudo apt-get install -y netcat-openbsd |
| 144 | + |
| 145 | + - name: Run gRPC performance tests |
| 146 | + run: | |
| 147 | + chmod +x bin/run_grpc_performance_tests.sh |
| 148 | + ./bin/run_grpc_performance_tests.sh |
| 149 | + |
| 150 | + - name: Upload results |
| 151 | + if: always() |
| 152 | + uses: actions/upload-artifact@v4 |
| 153 | + with: |
| 154 | + name: grpc-performance-results |
| 155 | + path: performance-results/ |
| 156 | + retention-days: 30 |
| 157 | + |
| 158 | + integration-tests: |
| 159 | + name: Integration Tests |
| 160 | + runs-on: ubuntu-latest |
| 161 | + timeout-minutes: 10 |
| 162 | + |
| 163 | + steps: |
| 164 | + - name: Checkout code |
| 165 | + uses: actions/checkout@v4 |
| 166 | + |
| 167 | + - name: Set up Go |
| 168 | + uses: actions/setup-go@v5 |
| 169 | + with: |
| 170 | + go-version: '1.22' |
| 171 | + |
| 172 | + - name: Run unit tests |
| 173 | + run: go test -v -timeout 5m ./pkg/... |
| 174 | + |
| 175 | + performance-summary: |
| 176 | + name: Performance Summary |
| 177 | + needs: [unit-benchmarks, grpc-throughput-tests, integration-tests] |
| 178 | + runs-on: ubuntu-latest |
| 179 | + if: always() |
| 180 | + |
| 181 | + steps: |
| 182 | + - name: Download all artifacts |
| 183 | + uses: actions/download-artifact@v4 |
| 184 | + |
| 185 | + - name: Generate summary |
| 186 | + run: | |
| 187 | + echo "# Performance Test Summary" >> $GITHUB_STEP_SUMMARY |
| 188 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 189 | + |
| 190 | + echo "## Job Status" >> $GITHUB_STEP_SUMMARY |
| 191 | + echo "- Unit Benchmarks: ${{ needs.unit-benchmarks.result }}" >> $GITHUB_STEP_SUMMARY |
| 192 | + echo "- gRPC Throughput: ${{ needs.grpc-throughput-tests.result }}" >> $GITHUB_STEP_SUMMARY |
| 193 | + echo "- Integration Tests: ${{ needs.integration-tests.result }}" >> $GITHUB_STEP_SUMMARY |
| 194 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 195 | + |
| 196 | + if [ -f performance-report/report.md ]; then |
| 197 | + echo "## Performance Report" >> $GITHUB_STEP_SUMMARY |
| 198 | + cat performance-report/report.md >> $GITHUB_STEP_SUMMARY |
| 199 | + fi |
| 200 | + |
| 201 | + if [ -f benchmark-results/benchmark-results.txt ]; then |
| 202 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 203 | + echo "## Benchmark Results" >> $GITHUB_STEP_SUMMARY |
| 204 | + echo "\`\`\`" >> $GITHUB_STEP_SUMMARY |
| 205 | + head -50 benchmark-results/benchmark-results.txt >> $GITHUB_STEP_SUMMARY |
| 206 | + echo "\`\`\`" >> $GITHUB_STEP_SUMMARY |
| 207 | + fi |
| 208 | + |
| 209 | + - name: Check overall status |
| 210 | + run: | |
| 211 | + if [ "${{ needs.unit-benchmarks.result }}" != "success" ] || \ |
| 212 | + [ "${{ needs.grpc-throughput-tests.result }}" != "success" ] || \ |
| 213 | + [ "${{ needs.integration-tests.result }}" != "success" ]; then |
| 214 | + echo "❌ Some performance tests failed" |
| 215 | + exit 1 |
| 216 | + fi |
| 217 | + echo "✅ All performance tests passed" |
0 commit comments