意外发现了twill可以进行压力测试,于是对比了一下。
正常情况下,我们的压力测试是这样的:
boom -n 1000 -c 100 http://127.0.0.1:5000/login
返回每个页面的结果:
1000 / 1000 Booooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo! 100.00 %
Summary:
Total: 2.3932 secs.
Slowest: 0.2570 secs.
Fastest: 0.0172 secs.
Average: 0.2282 secs.
Requests/sec: 417.8490
Total Data Received: 2048000 bytes.
Response Size per Request: 2048 bytes.
Status code distribution:
[200] 1000 responses
Response time histogram:
0.017 [1] |
0.041 [10] |
0.065 [11] |
0.089 [10] |
0.113 [10] |
0.137 [11] |
0.161 [11] |
0.185 [11] |
0.209 [11] |
0.233 [175] |∎∎∎∎∎∎∎∎∎
0.257 [739] |∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎
Latency distribution:
10% in 0.2197 secs.
25% in 0.2327 secs.
50% in 0.2393 secs.
75% in 0.2425 secs.
90% in 0.2483 secs.
95% in 0.2531 secs.
99% in 0.2564 secs.
但是这没有办法,模仿真实环境下的压力测试。
这时如果我们要模拟登录这个过程的压力测试的话,那么我们可以这样子。
twill-fork -n 500 -p 10 login.twill
(ps: 测试脚本参见 twill Python下的轻量级网站测试工具)
最后结果:
Form #1
## ## __Name__________________ __Type___ __ID________ __Value__________________
1 csrf_token hidden csrf_token 1423387579##ceaaadf260e3df6129683d1d ...
2 email email email None
3 password password password None
4 login submit (None) 登入
AT LINE: login.twill:3
AT LINE: login.twill:4
AT LINE: login.twill:5
AT LINE: login.twill:6
Setting action for form (<Element form at 0x10644ec00>,) to ('http://127.0.0.1:5000/login',)
AT LINE: login.twill:7
Note: submit is using submit button: name="login", value="登入"
==> at http://127.0.0.1:5000/login
AT LINE: login.twill:9
==> at http://127.0.0.1:5000/login
---
n processes: 10
total executed: 500
total time to execute: 105.789509
average time: 0.211579
平均每个网页的Requests/sec
大概是400
,这样下来大概要四次。
当我试着提高线程的时候,发现挂 了。
[2015-02-06 23:15:59 +0800] [21467] [INFO] Using worker: sync
[2015-02-06 23:15:59 +0800] [21470] [INFO] Booting worker with pid: 21470
[2015-02-06 23:16:01 +0800] [21470] [INFO] Worker exiting (pid: 21470)
[2015-02-06 23:16:01 +0800] [21467] [INFO] Handling signal: int
[2015-02-06 23:16:01 +0800] [21467] [INFO] Shutting down: Master
[2015-02-06 23:19:40 +0800] [22366] [INFO] Starting gunicorn 19.1.1
[2015-02-06 23:19:40 +0800] [22366] [INFO] Listening at: http://127.0.0.1:8000 (22366)
[2015-02-06 23:19:40 +0800] [22366] [INFO] Using worker: sync
[2015-02-06 23:19:40 +0800] [22369] [INFO] Booting worker with pid: 22369
于是修改了gunicorn
的参数
gunicorn xunta.wsgi --log-file=xunta.log --workers=2 -k gevent
再进行测试
twill-fork -n 1000 -p 10 login.twill
最后结果
---
n processes: 10
total executed: 1000
total time to execute: 216.028105
average time: 0.216028
再将workers变成4,将process变成100,结果
---
n processes: 100
total executed: 1000
total time to execute: 2043.460434
average time: 2.043460
变成2000多了。。
围观我的Github Idea墙, 也许,你会遇到心仪的项目