1+ name : 性能测试
2+
3+ on :
4+ # 允许手动触发
5+ workflow_dispatch :
6+ # 在推送代码到主分支时触发
7+ push :
8+ branches : [ master ]
9+ # 在创建 pull request 时触发
10+ pull_request :
11+ branches : [ master ]
12+
13+ jobs :
14+ benchmark :
15+ runs-on : ubuntu-latest
16+
17+ services :
18+ # 启动 Redis 服务
19+ redis :
20+ image : redis:latest
21+ ports :
22+ - 6379:6379
23+ options : >-
24+ --health-cmd "redis-cli ping"
25+ --health-interval 10s
26+ --health-timeout 5s
27+ --health-retries 5
28+
29+ steps :
30+ # 检出代码
31+ - name : 检出代码
32+ uses : actions/checkout@v4
33+
34+ # 设置 Java 环境
35+ - name : 设置 Java 环境
36+ uses : actions/setup-java@v4
37+ with :
38+ java-version : ' 8'
39+ distribution : ' temurin'
40+ cache : ' maven'
41+
42+ # 编译项目
43+ - name : 编译项目
44+ run : mvn compile
45+
46+ # 运行 Redisun、Redisson、Jedis 和 Lettuce 性能测试
47+ - name : 运行性能测试
48+ run : |
49+ # 串行执行所有客户端数量的测试
50+ for client_count in 1 8 16 64 128 1024 2048; do
51+ echo "Running Redisun vs Redisson vs Jedis vs Lettuce benchmark tests with ${client_count} clients..."
52+
53+ for framework in Redisson Jedis Lettuce Redisun; do
54+ echo "Running ${framework} benchmark with ${client_count} clients..."
55+ mvn test -Dtest=${framework}Benchmark -Dclient.count=${client_count} > ${framework}_${client_count}.log 2>&1 || true
56+ done
57+ done
58+
59+ # 提取测试结果
60+ - name : 提取测试结果
61+ run : |
62+ echo "# Redisun vs Redisson vs Jedis vs Lettuce 性能测试报告" > benchmark-report.md
63+ echo "测试时间: $(date)" >> benchmark-report.md
64+ echo "" >> benchmark-report.md
65+ echo "## 测试环境" >> benchmark-report.md
66+ echo "- 操作系统: Ubuntu 20.04" >> benchmark-report.md
67+ echo "- Java 版本: JDK 8" >> benchmark-report.md
68+ echo "- Redis 版本: latest" >> benchmark-report.md
69+ echo "- 测试键数量: 50000" >> benchmark-report.md
70+ echo "" >> benchmark-report.md
71+
72+ echo "## 详细数据" >> benchmark-report.md
73+ for case in "CONCURRENT SET" "CONCURRENT GET" "ASYNC SET" "ASYNC GET"; do
74+ echo "### ${case}" >> benchmark-report.md
75+ echo "| Concurrency | Redisun COST | Redisson COST | Jedis COST | Lettuce COST | Redisun OPS | Redisson OPS | Jedis OPS | Lettuce OPS |" >> benchmark-report.md
76+ echo "|------------|-------------|--------------|-----------|-------------|-------------|--------------|-----------|-------------|" >> benchmark-report.md
77+ # 遍历所有客户端数量提取结果
78+ for client_count in 1 8 16 64 128 1024 2048; do
79+ echo -n "|${client_count}|" >> benchmark-report.md
80+
81+ # 耗时
82+ for framework in Redisun Redisson Jedis Lettuce; do
83+ if grep -q "\[${case}\] cost:" ${framework}_${client_count}.log; then
84+ cost_time=$(grep "\[${case}\] cost:" ${framework}_${client_count}.log | awk '{print $4}')
85+ echo -n "${cost_time}|" >> benchmark-report.md
86+ else
87+ echo -n "N/A|" >> benchmark-report.md
88+ fi
89+ done
90+
91+ # OPS
92+ for framework in Redisun Redisson Jedis Lettuce; do
93+ if grep -q "\[${case}\] ops/s:" ${framework}_${client_count}.log; then
94+ ops=$(grep "\[${case}\] ops/s:" ${framework}_${client_count}.log | awk '{print $4}')
95+ echo -n "${ops}|" >> benchmark-report.md
96+ else
97+ echo -n "N/A|" >> benchmark-report.md
98+ fi
99+ done
100+ echo "" >> benchmark-report.md
101+ done
102+ echo "" >> benchmark-report.md
103+ done
104+
105+ echo "> 注意:由于 GitHub Actions 环境限制,测试结果可能不如本地环境准确。Jedis 不支持原生异步操作,因此标记为 -。" >> benchmark-report.md
106+ echo "" >> benchmark-report.md
107+
108+ # 显示报告内容
109+ cat benchmark-report.md
110+
111+ # 上传测试报告作为工件
112+ - name : 上传测试报告
113+ uses : actions/upload-artifact@v4
114+ with :
115+ name : benchmark-report
116+ path : benchmark-report.md
0 commit comments