负载均衡
http {
# ... 省略其它配置
upstream art {
server localhost:8281;
server localhost:8282;
server 10.27.250.248:8284;
}
server {
listen 8088;
location / {
proxy_pass http://art;
}
}
# ... 省略其它配置
}
压力测试
ab -n 10000 -c 100 -T application/x-www-form-urlencoded -p post.txt http://127.0.0.1:8088/art/api/action
post.txt
p=%7B%7D&method=markers&modular=reports&pageSize=1&pageNo=1
阻塞情况
直接使用使用sqlalchemy
zshdeMacBook-Air:Desktop zsh$ ab -n 10000 -c 100 -T application/x-www-form-urlencoded -p post.txt http://10.27.250.248:8284/art/api/action
Finished 10000 requests
Server Software: TornadoServer/5.1.1
Server Hostname: 10.27.250.248
Server Port: 8284
Document Path: /art/api/action
Document Length: 479 bytes
Concurrency Level: 100
Time taken for tests: 171.431 seconds
Complete requests: 10000
Failed requests: 0
Total transferred: 6320000 bytes
Total body sent: 2410000
HTML transferred: 4790000 bytes
Requests per second: 58.33 [#/sec] (mean)
Time per request: 1714.306 [ms] (mean)
Time per request: 17.143 [ms] (mean, across all concurrent requests)
Transfer rate: 36.00 [Kbytes/sec] received
13.73 kb/s sent
49.73 kb/s total
非阻塞
使用aiomysql
ab -n 10000 -c 100 -T application/x-www-form-urlencoded -p post.txt http://10.27.250.248:8284/art/api/action
Finished 10000 requests
Server Software: TornadoServer/5.1.1
Server Hostname: 10.27.250.248
Server Port: 8284
Document Path: /art/api/action
Document Length: 138 bytes
Concurrency Level: 100
Time taken for tests: 22.589 seconds
Complete requests: 10000
Failed requests: 0
Total transferred: 2910000 bytes
Total body sent: 2410000
HTML transferred: 1380000 bytes
Requests per second: 442.70 [#/sec] (mean)
Time per request: 225.886 [ms] (mean)
Time per request: 2.259 [ms] (mean, across all concurrent requests)
Transfer rate: 125.81 [Kbytes/sec] received
104.19 kb/s sent
230.00 kb/s total
总结
将数据库查询异步后,并发时,请求时间缩短的还是很明显的,使用tornado框架时,除了让请求异步非阻塞,相关的redis、mysql、mongodb等数据库查询也要异步才能达到相应的效果。
网友评论