-
Notifications
You must be signed in to change notification settings - Fork 0
155 lines (128 loc) · 4.68 KB
/
benchmark.yml
File metadata and controls
155 lines (128 loc) · 4.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
name: "Benchmark"
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
pull-requests: write
env:
IMAGE: async-dev
CACHE_KEY: async-dev-${{ github.event.pull_request.head.sha }}
on: [pull_request]
jobs:
setup:
name: Setup & Build Docker Image
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build Docker Image
uses: docker/build-push-action@v3
with:
context: .
push: false
tags: ${{ env.IMAGE }}
load: true
cache-from: type=gha
cache-to: type=gha,mode=max
outputs: type=docker,dest=/tmp/${{ env.IMAGE }}.tar
- name: Cache Docker Image
uses: actions/cache@v3
with:
key: ${{ env.CACHE_KEY }}
path: /tmp/${{ env.IMAGE }}.tar
benchmark:
name: Run Benchmarks
runs-on: ubuntu-latest
needs: setup
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Load Cache
uses: actions/cache@v3
with:
key: ${{ env.CACHE_KEY }}
path: /tmp/${{ env.IMAGE }}.tar
fail-on-cache-miss: true
- name: Load and Start Services
run: |
docker load --input /tmp/${{ env.IMAGE }}.tar
docker compose up -d
sleep 10
- name: Run Swoole Benchmark
id: benchmark-swoole
timeout-minutes: 30
run: |
echo "### Swoole Adapters" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
docker compose exec -T tests php /usr/src/code/benchmarks/Benchmark.php --iterations=10 2>&1 | tee benchmark_swoole.txt
cat benchmark_swoole.txt >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
- name: Run ext-parallel Benchmark
id: benchmark-parallel
timeout-minutes: 30
run: |
echo "### ext-parallel Adapter" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
docker compose exec -T tests php -n -d extension=parallel.so -d extension=sockets.so /usr/src/code/benchmarks/Benchmark.php --iterations=10 2>&1 | tee benchmark_parallel.txt
cat benchmark_parallel.txt >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
- name: Combine Results
run: |
echo "## Benchmark Results" > benchmark_output.txt
echo "" >> benchmark_output.txt
echo "### Swoole Adapters" >> benchmark_output.txt
cat benchmark_swoole.txt >> benchmark_output.txt
echo "" >> benchmark_output.txt
echo "### ext-parallel Adapter" >> benchmark_output.txt
cat benchmark_parallel.txt >> benchmark_output.txt
- name: Post Benchmark Results as Comment
continue-on-error: true
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const swooleOutput = fs.readFileSync('benchmark_swoole.txt', 'utf8');
const parallelOutput = fs.readFileSync('benchmark_parallel.txt', 'utf8');
const body = `## Benchmark Results
<details>
<summary>Swoole Adapters (Sync, Swoole Thread, Swoole Process, Amp, React)</summary>
\`\`\`
${swooleOutput}
\`\`\`
</details>
<details>
<summary>ext-parallel Adapter (Sync, Amp, React, ext-parallel)</summary>
\`\`\`
${parallelOutput}
\`\`\`
</details>
> Benchmarks run with 10 iterations on GitHub Actions runner`;
// Find existing comment
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const botComment = comments.find(comment =>
comment.user.type === 'Bot' &&
comment.body.includes('## Benchmark Results')
);
if (botComment) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: body
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: body
});
}