Files
snake-game/PERFORMANCE_TEST_REPORT.md
openclaw f7d9c11adf
Some checks failed
CI/CD Pipeline / 构建和测试 (push) Has been cancelled
CI/CD Pipeline / 部署到生产环境 (push) Has been cancelled
添加高并发性能测试报告 (#7)
2026-02-28 00:44:07 +00:00

4.7 KiB
Raw Permalink Blame History

蛇游戏高并发性能测试报告

测试日期: 2026-02-28
测试工具: Apache Bench (ab) Version 2.3
测试目标: http://192.168.120.60:80
服务器: nginx/1.18.0


📊 测试概述

本次测试对蛇游戏 Web 服务器进行了三轮不同并发级别的压力测试,评估服务器在高负载情况下的性能表现。

测试场景

场景 并发数 总请求数 文档大小
场景 1 100 1,000 1,687 bytes
场景 2 500 5,000 1,687 bytes
场景 3 1,000 10,000 1,687 bytes
静态资源 500 5,000 6,723 bytes (game.js)

📈 测试结果

场景 1: 100 并发1000 请求

Concurrency Level:      100
Time taken for tests:   0.129 seconds
Complete requests:      1000
Failed requests:        0
Requests per second:    7723.20 [#/sec] (mean)
Time per request:       12.948 [ms] (mean)
Transfer rate:          15024.04 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    5   1.2      5       9
Processing:     3    7   1.8      7      13
Total:          7   12   1.2     13      15

Percentile Response Times:
  50%     13ms
  90%     14ms
  95%     14ms
  99%     15ms
 100%     15ms

结果: 优秀 - 零失败,响应迅速


场景 2: 500 并发5000 请求

Concurrency Level:      500
Time taken for tests:   0.670 seconds
Complete requests:      5000
Failed requests:        0
Requests per second:    7467.26 [#/sec] (mean)
Time per request:       66.959 [ms] (mean)
Transfer rate:          14526.15 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0   28   6.2     28      42
Processing:    13   36   9.9     35      72
Total:         34   64   5.9     63      84

Percentile Response Times:
  50%     63ms
  90%     68ms
  95%     75ms
  99%     78ms
 100%     84ms

结果: 良好 - 零失败,性能稳定


场景 3: 1000 并发10000 请求

Concurrency Level:      1000
Time taken for tests:   1.273 seconds
Complete requests:      10000
Failed requests:        384 (3.84%)
   (Connect: 0, Receive: 0, Length: 192, Exceptions: 192)
Requests per second:    7858.18 [#/sec] (mean)
Time per request:       127.256 [ms] (mean)
Transfer rate:          14993.12 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0   53   8.9     53      74
Processing:    25   68  15.3     69     113
Total:         69  121  10.5    121     141

Percentile Response Times:
  50%    121ms
  90%    131ms
  95%    132ms
  98%    140ms
  99%    141ms
 100%    141ms

⚠️ 结果: 可接受 - 出现 3.84% 失败率,但整体性能仍稳定


静态资源测试: game.js (500 并发5000 请求)

Concurrency Level:      500
Time taken for tests:   0.670 seconds
Complete requests:      5000
Failed requests:        0
Requests per second:    7466.88 [#/sec] (mean)
Time per request:       66.962 [ms] (mean)
Transfer rate:          51677.50 [Kbytes/sec] received

结果: 优秀 - 静态资源传输效率高


📊 性能分析

吞吐量对比

场景 请求/秒 失败率 平均响应时间 P95 响应时间
100 并发 7,723 0% 12.9ms 14ms
500 并发 7,467 0% 67.0ms 75ms
1000 并发 7,858 3.84% 127.3ms 132ms

关键发现

  1. 吞吐量稳定: 服务器在不同并发级别下均保持约 7,500-7,800 请求/秒的吞吐量
  2. 线性扩展: 响应时间随并发数增加呈线性增长,符合预期
  3. 失败率: 1000 并发时出现少量失败 (3.84%),主要是连接异常
  4. 静态资源: nginx 对静态文件的传输效率优秀 (51MB/s)

结论

性能评级: A

蛇游戏服务器在正常负载下表现优秀:

  • 低并发 (100): 完美表现,零失败,响应时间 < 15ms
  • 中并发 (500): 表现良好,零失败,响应时间 < 85ms
  • ⚠️ 高并发 (1000): 可接受,少量失败 (< 4%),响应时间 < 145ms

建议

  1. 当前配置适合生产使用 - 对于单机游戏服务器,性能完全足够
  2. 建议并发上限: 500 并发以下可保证 100% 成功率
  3. 优化方向 (可选):
    • 启用 nginx 连接保持 (keepalive)
    • 配置静态资源缓存头
    • 考虑启用 gzip 压缩

🔧 测试环境

  • 测试工具: Apache Bench 2.3
  • 测试机器: Ubuntu Linux
  • 目标服务器: nginx/1.18.0 @ 192.168.120.60:80
  • 网络环境: 内网直连

报告生成时间: 2026-02-28 00:45 UTC
测试执行: 大壮 (专属 AI 助理) 💪