基准测试

https://github.com/17koa/koa-benchmark

比较koa和koa2和express性能

Preview

Prerequisites

for OSX

  1. brew install wrk

wrk原理

Wrk Architecture Structure

命令行操作

  1. $ wrk -t8 -c1000 -d10 http://127.0.0.1:3000

Test

首次测试,需要安装依赖,会比较慢

  1. make all

不安装依赖,重复测试

  1. make test

查看中间件请求测试

  1. make test -f Makefile2

Results

  1. koa-benchmark git:(master) node -v
  2. v4.0.0
  3. koa-benchmark git:(master) npm -v
  4. 2.14.2
  5. koa-benchmark git:(master) npm test
  6. benchmark koa-1
  7. 1 middleware
  8. 5976.88
  9. 5 middleware
  10. 3495.61
  11. 10 middleware
  12. 5494.52
  13. 15 middleware
  14. 5444.90
  15. 20 middleware
  16. 5631.77
  17. 30 middleware
  18. 5091.48
  19. 50 middleware
  20. 3657.46
  21. 100 middleware
  22. 4712.93
  23. benchmark koa-2
  24. 1 middleware
  25. 5959.41
  26. 5 middleware
  27. 5653.19
  28. 10 middleware
  29. 5652.32
  30. 15 middleware
  31. 5882.88
  32. 20 middleware
  33. 5929.52
  34. 30 middleware
  35. 5700.04
  36. 50 middleware
  37. 5852.57
  38. 100 middleware
  39. 5211.41
  40. benchmark express
  41. 1 middleware
  42. 5500.16
  43. 5 middleware
  44. 5783.63
  45. 10 middleware
  46. 5561.32
  47. 15 middleware
  48. 5253.31
  49. 20 middleware
  50. 5305.64
  51. 30 middleware
  52. 4950.02
  53. 50 middleware
  54. 4472.47
  55. 100 middleware
  56. 4077.43

压力测试模型

  1. 假设支持100w
  2. 每个用户每天访问a (web.xxxxx.com)
  3. 每天次数:100w * a
  4. 按照80/20原则,80%的访问集中在20%的时间内
  5. 100w * a * 80% / 4.8小时
  6. 假设对用户来说每次访问6秒钟是可以接受的
  7. (100w*a*80%/4.8h)*6=测试用并发数据

List