-
Notifications
You must be signed in to change notification settings - Fork 2
329 lines (275 loc) · 10.6 KB
/
benchmark.yml
File metadata and controls
329 lines (275 loc) · 10.6 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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
name: 性能测试
on:
workflow_dispatch:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
benchmark-1:
runs-on: ubuntu-latest
services:
redis:
image: redis:latest
ports:
- 6379:6379
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: 检出代码
uses: actions/checkout@v4
- name: 设置 Java 环境
uses: actions/setup-java@v4
with:
java-version: '8'
distribution: 'temurin'
cache: 'maven'
- name: 编译项目
run: mvn compile
- name: 运行性能测试 (客户端数量 1)
run: |
echo "Running benchmark tests with 1 clients..."
# 定义测试参数
clients=("Redisun" "Redisson" "Jedis" "Lettuce")
methods=("asyncSet" "asyncGet" "concurrentSet" "concurrentGet")
# 循环执行所有测试
for client in "${clients[@]}"; do
for method in "${methods[@]}"; do
echo "Running ${client} ${method} test..."
mvn test -Dtest=${client}Benchmark#${method} -Dclient.count=1 > ${client,,}_${method}_1.log 2>&1 || true
done
done
# 上传单个测试结果作为工件
- name: 上传单个测试结果
uses: actions/upload-artifact@v4
with:
name: benchmark-results-1
path: "*.log"
benchmark-8:
runs-on: ubuntu-latest
services:
redis:
image: redis:latest
ports:
- 6379:6379
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: 检出代码
uses: actions/checkout@v4
- name: 设置 Java 环境
uses: actions/setup-java@v4
with:
java-version: '8'
distribution: 'temurin'
cache: 'maven'
- name: 编译项目
run: mvn compile
- name: 运行性能测试 (客户端数量 8)
run: |
echo "Running benchmark tests with 8 clients..."
# 定义测试参数
clients=("Redisun" "Redisson" "Jedis" "Lettuce")
methods=("asyncSet" "asyncGet" "concurrentSet" "concurrentGet")
# 循环执行所有测试
for client in "${clients[@]}"; do
for method in "${methods[@]}"; do
echo "Running ${client} ${method} test..."
mvn test -Dtest=${client}Benchmark#${method} -Dclient.count=8 > ${client,,}_${method}_8.log 2>&1 || true
done
done
# 上传单个测试结果作为工件
- name: 上传单个测试结果
uses: actions/upload-artifact@v4
with:
name: benchmark-results-8
path: "*.log"
benchmark-128:
runs-on: ubuntu-latest
services:
redis:
image: redis:latest
ports:
- 6379:6379
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: 检出代码
uses: actions/checkout@v4
- name: 设置 Java 环境
uses: actions/setup-java@v4
with:
java-version: '8'
distribution: 'temurin'
cache: 'maven'
- name: 编译项目
run: mvn compile
- name: 运行性能测试 (客户端数量 128)
run: |
echo "Running benchmark tests with 128 clients..."
# 定义测试参数
clients=("Redisun" "Redisson" "Jedis" "Lettuce")
methods=("asyncSet" "asyncGet" "concurrentSet" "concurrentGet")
# 循环执行所有测试
for client in "${clients[@]}"; do
for method in "${methods[@]}"; do
echo "Running ${client} ${method} test..."
mvn test -Dtest=${client}Benchmark#${method} -Dclient.count=128 > ${client,,}_${method}_128.log 2>&1 || true
done
done
# 上传单个测试结果作为工件
- name: 上传单个测试结果
uses: actions/upload-artifact@v4
with:
name: benchmark-results-128
path: "*.log"
benchmark-1024:
runs-on: ubuntu-latest
services:
redis:
image: redis:latest
ports:
- 6379:6379
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: 检出代码
uses: actions/checkout@v4
- name: 设置 Java 环境
uses: actions/setup-java@v4
with:
java-version: '8'
distribution: 'temurin'
cache: 'maven'
- name: 编译项目
run: mvn compile
- name: 运行性能测试 (客户端数量 1024)
run: |
echo "Running benchmark tests with 1024 clients..."
# 定义测试参数
clients=("Redisun" "Redisson" "Jedis" "Lettuce")
methods=("asyncSet" "asyncGet" "concurrentSet" "concurrentGet")
# 循环执行所有测试
for client in "${clients[@]}"; do
for method in "${methods[@]}"; do
echo "Running ${client} ${method} test..."
mvn test -Dtest=${client}Benchmark#${method} -Dclient.count=1024 > ${client,,}_${method}_1024.log 2>&1 || true
done
done
# 上传单个测试结果作为工件
- name: 上传单个测试结果
uses: actions/upload-artifact@v4
with:
name: benchmark-results-1024
path: "*.log"
# 新增一个job来整合所有结果
merge-reports:
needs: [benchmark-1, benchmark-8, benchmark-128, benchmark-1024]
runs-on: ubuntu-latest
steps:
- name: 检出代码
uses: actions/checkout@v4
# 下载所有测试结果
- name: 下载所有测试结果
uses: actions/download-artifact@v4
with:
path: ./artifacts
# 整合报告
- name: 整合测试报告
run: |
echo "# Redis客户端性能测试报告" > benchmark-report.md
echo "测试时间: $(date)" >> benchmark-report.md
echo "" >> benchmark-report.md
echo "## 测试环境" >> benchmark-report.md
echo "- 操作系统: Ubuntu 20.04" >> benchmark-report.md
echo "- Java 版本: JDK 8" >> benchmark-report.md
echo "- Redis 版本: latest" >> benchmark-report.md
echo "- 测试键数量: 50000" >> benchmark-report.md
echo "" >> benchmark-report.md
# 创建通用函数提取数据
extract_data() {
local client_name=$1
local method=$2
local client_count=$3
local log_file="./artifacts/benchmark-results-${client_count}/${client_name}_${method}_${client_count}.log"
if [ -f "$log_file" ]; then
# 提取时间 (cost)
local time=$(grep " cost:" "$log_file" | awk '{print $5}' | sed 's/ms$//' | sed 's/[^0-9\-]*//g' | head -1)
if [ -z "$time" ]; then
time="-"
fi
# 提取OPS
local ops=$(grep " ops/s:" "$log_file" | awk '{print $5}' | sed 's/[^0-9\-]*//g' | head -1)
if [ -z "$ops" ]; then
ops="-"
fi
echo "$time/$ops"
else
echo "-/-"
fi
}
# 定义测试类型和表头
test_types=("concurrent_set" "async_set" "concurrent_get" "async_get")
type_names=("同步SET性能对比" "异步SET性能对比" "同步GET性能对比" "异步GET性能对比")
# 为每种测试类型生成表格
for i in "${!test_types[@]}"; do
test_type=${test_types[$i]}
type_name=${type_names[$i]}
echo "## $type_name" >> benchmark-report.md
echo "| 客户端数量 | 耗时(Redisun/Redisson/Jedis/Lettuce) | OPS(Redisun/Redisson/Jedis/Lettuce) |" >> benchmark-report.md
echo "|------------|------------------------|-----------------------|" >> benchmark-report.md
for client_count in 1 8 128 1024; do
# 根据测试类型设置方法名
case "${test_type}" in
"concurrent_set")
method="concurrentSet"
;;
"async_set")
method="asyncSet"
;;
"concurrent_get")
method="concurrentGet"
;;
"async_get")
method="asyncGet"
;;
esac
# 提取各客户端的数据
redisun_data=$(extract_data "redisun" "${method}" "$client_count")
redisson_data=$(extract_data "redisson" "${method}" "$client_count")
jedis_data=$(extract_data "jedis" "${method}" "$client_count")
lettuce_data=$(extract_data "lettuce" "${method}" "$client_count")
redisun_time=$(echo $redisun_data | cut -d'/' -f1)
redisun_ops=$(echo $redisun_data | cut -d'/' -f2)
redisson_time=$(echo $redisson_data | cut -d'/' -f1)
redisson_ops=$(echo $redisson_data | cut -d'/' -f2)
jedis_time=$(echo $jedis_data | cut -d'/' -f1)
jedis_ops=$(echo $jedis_data | cut -d'/' -f2)
lettuce_time=$(echo $lettuce_data | cut -d'/' -f1)
lettuce_ops=$(echo $lettuce_data | cut -d'/' -f2)
echo "| ${client_count} | ${redisun_time}/${redisson_time}/${jedis_time}/${lettuce_time} | ${redisun_ops}/${redisson_ops}/${jedis_ops}/${lettuce_ops} |" >> benchmark-report.md
done
echo "" >> benchmark-report.md
done
echo "> 注意:由于 GitHub Actions 环境限制,测试结果可能不如本地环境准确。" >> benchmark-report.md
echo "" >> benchmark-report.md
# 显示报告内容
cat benchmark-report.md
# 上传整合后的测试报告
- name: 上传整合后的测试报告
uses: actions/upload-artifact@v4
with:
name: benchmark-report
path: benchmark-report.md