nginx+memcache,nginx


一、Openresty

1、编译、安装opesresty

[root@server6 ~]# tar zxf openresty-1.13.6.1.tar.gz 
[root@server6 ~]# cd openresty-1.13.6.1
[root@server6 openresty-1.13.6.1]# ./configure --prefix=/usr/local/lnmp/openresty
[root@server6 openresty-1.13.6.1]# gmake && gmake install

2、配置文件

[root@server6 ~]# vim /usr/local/lnmp/openresty/nginx/conf/nginx.conf




3、打开 memcached、php-fpm、nginx

[root@server6 ~]# /etc/init.d/memcached start
Starting memcached:                                        [  OK  ]
[root@server6 ~]# /etc/init.d/php-fpm start
Starting php-fpm  done
[root@server6 ~]# /usr/local/lnmp/openresty/nginx/sbin/nginx 
[root@server6 ~]# 

4、物理主机测试
Nginx 没有添加 Memcache 模块,Php有 Memcache 模块

[root@foundation29 pub]#  ab -c 1 -n 1000 http://172.25.29.6/example.php
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 172.25.29.6 (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests


Server Software:        nginx
Server Hostname:        172.25.29.6
Server Port:            80

Document Path:          /example.php
Document Length:        123 bytes

Concurrency Level:      1
Time taken for tests:   0.739 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Total transferred:      279000 bytes
HTML transferred:       123000 bytes
Requests per second:    1353.54 [#/sec] (mean)
Time per request:       0.739 [ms] (mean)
Time per request:       0.739 [ms] (mean, across all concurrent requests)
Transfer rate:          368.79 [Kbytes/sec] received

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

Percentage of the requests served within a certain time (ms)
  50%      1
  66%      1
  75%      1
  80%      1
  90%      1
  95%      1
  98%      1
  99%      1
 100%      2 (longest request)
 [root@foundation29 pub]# ab -c 1 -n 1000 http://172.25.29.6/index.php
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 172.25.29.6 (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests


Server Software:        nginx
Server Hostname:        172.25.29.6
Server Port:            80

Document Path:          /index.php
Document Length:        84756 bytes

Concurrency Level:      1
Time taken for tests:   2.267 seconds
Complete requests:      1000
Failed requests:        104
   (Connect: 0, Receive: 0, Length: 104, Exceptions: 0)
Write errors:           0
Total transferred:      84911880 bytes
HTML transferred:       84755880 bytes
Requests per second:    441.16 [#/sec] (mean)
Time per request:       2.267 [ms] (mean)
Time per request:       2.267 [ms] (mean, across all concurrent requests)
Transfer rate:          36582.06 [Kbytes/sec] received

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

Percentage of the requests served within a certain time (ms)
  50%      2
  66%      2
  75%      2
  80%      2
  90%      2
  95%      3
  98%      3
  99%      3
 100%      5 (longest request)
[root@foundation29 pub]# 

Nginx 添加 Memcahche 模块,Php 相当于 “双 Memcache”

[root@foundation29 pub]# ab -c 1 -n 1000 http://172.25.29.6/example.php
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 172.25.29.6 (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests


Server Software:        openresty/1.13.6.1
Server Hostname:        172.25.29.6
Server Port:            80

Document Path:          /example.php
Document Length:        16 bytes

Concurrency Level:      1
Time taken for tests:   0.409 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Non-2xx responses:      1000
Total transferred:      192000 bytes
HTML transferred:       16000 bytes
Requests per second:    2446.11 [#/sec] (mean)
Time per request:       0.409 [ms] (mean)
Time per request:       0.409 [ms] (mean, across all concurrent requests)
Transfer rate:          458.64 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.1      0       1
Processing:     0    0   0.1      0       3
Waiting:        0    0   0.1      0       3
Total:          0    0   0.1      0       3

Percentage of the requests served within a certain time (ms)
  50%      0
  66%      0
  75%      0
  80%      0
  90%      0
  95%      1
  98%      1
  99%      1
 100%      3 (longest request)
[root@foundation29 pub]# 
[root@foundation29 pub]# ab -c 1 -n 1000 http://172.25.29.6/index.php
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 172.25.29.6 (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests


Server Software:        openresty/1.13.6.1
Server Hostname:        172.25.29.6
Server Port:            80

Document Path:          /index.php
Document Length:        16 bytes

Concurrency Level:      1
Time taken for tests:   0.415 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Non-2xx responses:      1000
Total transferred:      192000 bytes
HTML transferred:       16000 bytes
Requests per second:    2408.44 [#/sec] (mean)
Time per request:       0.415 [ms] (mean)
Time per request:       0.415 [ms] (mean, across all concurrent requests)
Transfer rate:          451.58 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.1      0       2
Processing:     0    0   0.1      0       2
Waiting:        0    0   0.1      0       2
Total:          0    0   0.2      0       3

Percentage of the requests served within a certain time (ms)
  50%      0
  66%      0
  75%      0
  80%      0
  90%      0
  95%      1
  98%      1
  99%      1
 100%      3 (longest request)
[root@foundation29 pub]# 

相比较而言,Nginx 添加 Memcache 模块后,速度由441提高至2408,性能得到显著优化!而 Php 性能也得到了一定的优化!

相关内容

    暂无相关文章