負(fù)載均衡
http {
# ... 省略其它配置
upstream art {
server localhost:8281;
server localhost:8282;
server 10.27.250.248:8284;
}
server {
listen 8088;
location / {
proxy_pass http://art;
}
}
# ... 省略其它配置
}
壓力測(cè)試
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
總結(jié)
將數(shù)據(jù)庫(kù)查詢異步后,并發(fā)時(shí),請(qǐng)求時(shí)間縮短的還是很明顯的,使用tornado框架時(shí),除了讓請(qǐng)求異步非阻塞,相關(guān)的redis、mysql、mongodb等數(shù)據(jù)庫(kù)查詢也要異步才能達(dá)到相應(yīng)的效果。