Yehnn / seed_lab

一些实验
Other
12 stars 12 forks source link

搭建 LNMP , nginx 负载均衡 #33

Open Yehnn opened 6 years ago

Yehnn commented 6 years ago
Yehnn commented 6 years ago
sudo killall nginx
Yehnn commented 6 years ago

nginx 配置测试:

sudo nginx -t

修改配置文件后,使用命令 ab 测试,。

shiyanlou:/$ ab -n 10 -c 10  http://localhost/test.php

其中-n代表每次并发量,-c代表总共发送的数量。这条命令表示10个请求一次并发出去

测试结果:

Benchmarking localhost (be patient).....done

Server Software:        nginx/1.4.6
Server Hostname:        localhost
Server Port:            80

Document Path:          /test.php           ###请求的资源
Document Length:        16 bytes            ###文档返回的长度,不包括相应头

Concurrency Level:      10                   ###并发个数
Time taken for tests:   0.006 seconds        ###总请求时间
Complete requests:      10               ###总请求数
Failed requests:        4                ###失败的请求数
   (Connect: 0, Receive: 0, Length: 4, Exceptions: 0)
Non-2xx responses:      10
Total transferred:      2744 bytes
HTML transferred:       980 bytes
Requests per second:    1645.55 [#/sec] (mean)   ###平均每秒的请求数
Time per request:       6.077 [ms] (mean)        ###平均每个请求消耗的时间
Time per request:       0.608 [ms] (mean, across all concurrent requests) ###上面的请求除以并发数
Transfer rate:          440.96 [Kbytes/sec] received  ###传输速率

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        1    4   1.7      5       5
Processing:     1    2   1.7      1       5
Waiting:        0    1   1.3      1       5
Total:          5    6   0.0      6       6

Percentage of the requests served within a certain time (ms)
  50%      6            ###50%的请求都在6Ms内完成
  66%      6
  75%      6
  80%      6
  90%      6
  95%      6
  98%      6
  99%      6
 100%      6 (longest request)

然后我们查看log,可以看出我们并发了10条请求,有4条访问失败

sudo tail /var/log/nginx/error.log  

2017/03/08 11:28:50 [error] 1430#0: *161 limiting requests, excess: 5.995 by zone "one", client: ::1, 
2017/03/08 11:28:50 [error] 1430#0: *162 limiting requests, excess: 5.995 by zone "one", client: ::1, 
2017/03/08 11:28:50 [error] 1430#0: *163 limiting requests, excess: 5.995 by zone "one", client: ::1, 
2017/03/08 11:28:50 [error] 1430#0: *164 limiting requests, excess: 5.995 by zone "one", client: ::1, 
Yehnn commented 6 years ago

几个重要的文件:

/etc/nginx/nginx.conf
/etc/nginx/sites-available/default
/usr/share/nginx/html/

若编译安装的话
/usr/local/nginx/conf/nginx.conf

日志
/var/log/nginx/error.log