安装

nginx.org上下载最新的nginx源码包

./configure
make && make install

安装好后测试一下,先修改配置文件,在配置文件中设置服务器根目录的路径为博客的根目录:

root ...

启动nginx,在浏览器中输入localhost:80:

测试下性能

使用‘ab’工具来测试nginx的性能,关于这个工具可以读一下manual:

ab is a tool for benchmarking your Apache Hypertext Transfer Protocol (HTTP) server. It is designed to give you an impression of how your current Apache installation performs. This especially shows you how many requests per second your Apache installation is capable of serving.

➜  blog git:(master) ✗ ab -kc 1000 -n 10000 http://127.0.0.1:80/
This is ApacheBench, Version 2.3 <$Revision: 1554214 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 127.0.0.1 (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests


Server Software:        nginx/1.7.6
Server Hostname:        127.0.0.1
Server Port:            80

Document Path:          /
Document Length:        6552 bytes

Concurrency Level:      1000
Time taken for tests:   0.590 seconds
Complete requests:      10000
Failed requests:        0
Keep-Alive requests:    10000
Total transferred:      67910000 bytes
HTML transferred:       65520000 bytes
Requests per second:    16950.93 [#/sec] (mean)
Time per request:       58.994 [ms] (mean)
Time per request:       0.059 [ms] (mean, across all concurrent requests)
Transfer rate:          112415.81 [Kbytes/sec] received

Connection Times (ms)
          min  mean[+/-sd] median   max
Connect:        0    3   8.7      0      39
Processing:    19   52  10.1     55      61
Waiting:       19   52  10.2     55      61
Total:         34   55   3.8     55      61

Percentage of the requests served within a certain time (ms)
  50%     55
  66%     56
  75%     57
  80%     58
  90%     59
  95%     59
  98%     60
  99%     61
 100%     61 (longest request)

请求博客的index.html10000次,同一时间concurrency设置为1000时,输出信息中显示完成10000个并发请求一共花费了0.59秒。

同样测试一下apache的性能:

当concurrency为1000时,直接崩掉

 ➜  blog git:(master) ✗ ab -kc 1000 -n 10000 http://127.0.0.1/
This is ApacheBench, Version 2.3 <$Revision: 1554214 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 127.0.0.1 (be patient)
apr_socket_recv: Connection reset by peer (54)

concurrency降到100时,

➜  blog git:(master) ✗ ab -kc 100 -n 10000 http://127.0.0.1/
This is ApacheBench, Version 2.3 <$Revision: 1554214 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 127.0.0.1 (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests


Server Software:        Apache/2.4.9
Server Hostname:        127.0.0.1
Server Port:            80

Document Path:          /
Document Length:        6552 bytes

Concurrency Level:      100
Time taken for tests:   5.577 seconds
Complete requests:      10000
Failed requests:        38
   (Connect: 0, Receive: 0, Length: 38, Exceptions: 0)
Keep-Alive requests:    9895
Total transferred:      68236808 bytes
HTML transferred:       65415168 bytes
Requests per second:    1793.00 [#/sec] (mean)
Time per request:       55.772 [ms] (mean)
Time per request:       0.558 [ms] (mean, across all concurrent requests)
Transfer rate:          11948.11 [Kbytes/sec] received

Connection Times (ms)
          min  mean[+/-sd] median   max
Connect:        0    0   0.3      0       4
Processing:     0   29 321.9      2    5052
Waiting:        0   21 253.0      2    5052
Total:          0   29 322.0      2    5052

Percentage of the requests served within a certain time (ms)
  50%      2
  66%      3
  75%      3
  80%      3
  90%      4
  95%      5
  98%     16
  99%    272
 100%   5052 (longest request)

此时完成10000个请求共花费了5.577秒,将近是nginx服务器的10倍,相比较在并发量比较大时nginx的性能还是要远远好于apache的。

Comments

Powered by Pelican. Booler's Adventure © 不贰 2014-2016