nginx優化壓力測試

 Nginx優化

Nginx以事件驅動(epoll的方式編寫,所以有非常好的性能,同時也是一個非常高效的反向代理、負載平衡但是Nginx並不支持cgi方式運行,原因是可以減少因此帶來的一些程序上的漏洞。所以必須使用FastCGI方式來執行PHP程序。

由於Nginx本身的一些優點,輕量,開源,易用,越來越多的公司使用nginx作爲自己公司的web應用服務器,本文詳細介紹nginx源碼安裝的同時並對nginx進行優化配置。

一、Nginx的優化

1、編譯安裝前優化

編譯前的優化主要是用來修改程序名等等目的更改源碼隱藏軟件名稱和版本號

安裝zlib-develpcre-devel等依賴包

[root@CXW /]# yum -y install gcc gcc-c++ make libtool zlib zlib-devel pcre pcre-devel openssl openssl-devel

下載nginx的源碼包:http://nginx.org/download

解壓源碼包:

[root@CXW /]# tar zxf nginx-1.10.2.tar.gz 
[root@CXW /]# cd nginx-1.10.2/

隱藏軟件名稱和版本號

[root@CXW nginx-1.10.2]# vim src/core/nginx.h

//此行修改的是你想要的版本

#define NGINX_VERSION      "1.22.22"     //13

//此行修改的是你想修改的軟件名稱

#define NGINX_VER          "nginx/" NGINX_VERSION  //14

修改上面的信息,即可更改nginx顯示版本。例如:

#define NGINX_VERSION      "7.0"

#define NGINX_VER          "IIS/" NGINX_VERSION

截圖00.png

修改HTTP頭信息中的connection字段,防止回顯具體版本號

拓展:通用http通用頭包含請求和響應消息都支持的頭,通用頭包含Cache-ControlConnectionDatePragmaTransfer-EncodingUpgradeVia。對通用頭的擴展要求通訊雙方都支持此擴展,如果存在不支持的通用頭,一般將會作爲實體頭處理。那麼也就是說有部分設備,或者是軟件,能獲取到connection,部分不能,要隱藏就要徹底!

[root@CXW nginx-1.10.2]# vim src/http/ngx_http_header_filter_module.c

修改前:

static char ngx_http_server_string[] = "Server: nginx" CRLF;  //49

修改後:

static char ngx_http_server_string[] = "Server: CXW" CRLF;

截圖01.png

修改HTTP頭信息中的connection字段,防止回顯具體版本號

拓展:通用http通用頭包含請求和響應消息都支持的頭,通用頭包含Cache-ControlConnectionDatePragmaTransfer-EncodingUpgradeVia。對通用頭的擴展要求通訊雙方都支持此擴展,如果存在不支持的通用頭,一般將會作爲實體頭處理。那麼也就是說有部分設備,或者是軟件,能獲取到connection,部分不能,要隱藏就要徹底!

[root@CXW nginx-1.10.2]# vim src/http/ngx_http_header_filter_module.c

修改前:

static char ngx_http_server_string[] = "Server: nginx" CRLF;  //49

修改後:

static char ngx_http_server_string[] = "Server: CXW" CRLF;

[root@CXW nginx-1.10.2]# vim src/http/ngx_http_special_response.c

修改前

static u_char ngx_http_error_tail[] =     //29

"<hr><center>nginx</center>" CRLF

"</body>" CRLF

"</html>" CRLF

;

修改後
static u_char ngx_http_error_tail[] =
"<hr><center>CXW</center>" CRLF
"</body>" CRLF
"</html>" CRLF
;

截圖02.png

2、安裝ngnix

[root@CXW nginx-1.10.2]# groupadd www   #添加www組
[root@CXW nginx-1.10.2]# useradd -g www www -s /sbin/nologin  #創建nginx運行賬戶www並加入到www組,不允許www用戶直接登錄系統
root@CXW nginx-1.10.2]#./configure --prefix=/nginx1.10 --with-http_dav_module --with-http_stub_status_module --with-http_addition_module --with-http_sub_module --with-http_flv_module --with-http_mp4_module --with-pcre --with-http_ssl_module --with-http_gzip_static_module --user=www --group=www
[root@CXW nginx-1.10.2]# make && make install

相關選項說明

--with-http_dav_module  #增加PUT,DELETE,MKCOL:創建集合,COPYMOVE方法

--with-http_stub_status_module  #獲取Nginx的狀態統計信息

--with-http_addition_module   #作爲一個輸出過濾器,支持不完全緩衝,分部分相應請求

--with-http_sub_module     #允許一些其他文本替換Nginx相應中的一些文本

--with-http_flv_module     #提供支持flv視頻文件支持

--with-http_mp4_module  #提供支持mp4視頻文件支持,提供僞流媒體服務端支持

--with-http_ssl_module         #啓用ngx_http_ssl_module

[root@CXW nginx-1.10.2]# ln -s /usr/src/nginx1.10/sbin/nginx /usr/local/sbin/
[root@CXW nginx-1.10.2]# nginx -t
nginx: the configuration file /usr/src/nginx1.10/conf/nginx.conf syntax is ok
nginx: configuration file /usr/src/nginx1.10/conf/nginx.conf test is successful
[root@CXW nginx-1.10.2]# nginx
[root@CXW nginx-1.10.2]# netstat -anpt | grep nginx
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      7935/nginx: master
[root@CXW nginx-1.10.2]# nginx -h
nginx version: cxw/7.0

3nginx配置項優化

[root@CXW nginx-1.10.2]# ps -ef | grep nginx

root      7935     1  0 17:24 ?        00:00:00 nginx: master process nginx

www       7936  7935  0 17:24 ?        00:00:00 nginx: worker process

root      8125  4969  0 17:30 pts/1    00:00:00 grep --color=auto nginx

截圖04.png

在這裏我們還可以看到在查看的時候,work進程是nginx程序用戶,但是master進程還是root其中,master是監控進程,也叫主進程,work是工作進程

(1):Nginx運行工作進程個數,一般我們設置CPU的核心或者核心數x2

如果不瞭解cpu的核數可以top命令之後按1也可以看出來,也可以查看/proc/cpuinfo文件#grep ^processor /proc/cpuinfo | wc -l

[root@CXW nginx-1.10.2]# vim /usr/src/nginx1.10/conf/nginx.conf

截圖05.png

[root@CXW nginx-1.10.2]# /usr/src/nginx1.10/sbin/nginx -s reload 
[root@CXW nginx-1.10.2]#  ps -aux | grep nginx | grep -v grep
root      7935  0.0  0.1  46008  1924 ?        Ss   17:24   0:00 nginx: master process nginx
www       8355  0.0  0.1  48520  2072 ?        S    17:39   0:00 nginx: worker process

Nginx運行CPU親和力

比如4核配置

worker_processes  4;

worker_cpu_affinity 0001 0010 0100 1000

比如8核配置

worker_processes 8;

worker_cpu_affinity 00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000;

worker_processes最多開啓8個,8個以上性能提升不會再提升了,而且穩定性變得更低,所以8個進程夠用了。

Nginx最多可以打開文件數

worker_rlimit_nofile 65535;

這個指令是指當一個nginx進程打開的最多文件描述符數目,理論值應該是最多打開文件數(ulimit -n)與nginx進程數相除,但是nginx分配請求並不是那麼均勻,所以最好與ulimit -n的值保持一致。

注:

文件資源限制的配置可以在/etc/security/limits.conf設置,針對root/user等各個用戶或者*代表所有用戶來設置。

*     soft   nofile   65535

*     hard  nofile    65535

(3)開啓高效傳輸模式

http {
include mime.types;
default_type application/octet-stream;
……
sendfile on;
tcp_nopush on;
……

Include mime.types; //媒體類型,include 只是一個在當前文件中包含另一個文件內容的指令

default_type application/octet-stream;   //默認媒體類型足夠

sendfile on//開啓高效文件傳輸模式,sendfile指令指定nginx是否調用sendfile函數來輸出文件,對於普通應用設爲 on,如果用來進行下載等應用磁盤IO重負載應用,可設置爲off,以平衡磁盤與網絡I/O處理速度,降低系統的負載。

注意:如果圖片顯示不正常把這個改成off

tcp_nopush on必須在sendfile開啓模式纔有效,防止網路阻塞,積極的減少網絡報文段的數量將響應頭和正文的開始部分一起發送,而不一個接一個的發送。

(4)連接超時時間

主要目的是保護服務器資源,CPU,內存,控制連接數,因爲建立連接也是需要消耗資源的

keepalive_timeout 60;
tcp_nodelay on;
client_header_buffer_size 4k;
open_file_cache max=102400 inactive=20s;
open_file_cache_valid 30s;
open_file_cache_min_uses 1;
client_header_timeout 15;
client_body_timeout 15;
reset_timedout_connection on;
send_timeout 15;
server_tokens off;
client_max_body_size 10m;

keepalived_timeout客戶端連接保持會話超時時間,超過這個時間,服務器斷開這個鏈接

tcp_nodelay;也是防止網絡阻塞,不過要包涵在keepalived參數纔有效

client_header_buffer_size 4k;
客戶端請求頭部的緩衝區大小,這個可以根據你的系統分頁大小來設置,一般一個請求頭的大小不會超過 1k,不過由於一般系統分頁都要大於1k,所以這裏設置爲分頁大小。分頁大小可以用命令getconf PAGESIZE取得。
open_file_cache max=102400 inactive=20s;
這個將爲打開文件指定緩存,默認是沒有啓用的,max指定緩存數量,建議和打開文件
數一致,inactive 是指經過多長時間文件沒被請求後刪除緩存。
open_file_cache_valid 30s;
這個是指多長時間檢查一次緩存的有效信息。
open_file_cache_min_uses 1;
open_file_cache指令中的inactive 參數時間內文件的最少使用次數,如果超過這個數字,文
件描述符一直是在緩存中打開的,如上例,如果有一個文件在inactive 時間內一次沒被使用,它將被移除。

client_header_timeout設置請求頭的超時時間。我們也可以把這個設置低些,如果超過這個時間沒有發送任何數據,nginx將返回request time out的錯誤

client_body_timeout設置請求體的超時時間。我們也可以把這個設置低些,超過這個時間沒有發送任何數據,和上面一樣的錯誤提示

reset_timeout_connection 告訴nginx關閉不響應的客戶端連接。這將會釋放那個客戶端所佔有的內存空間。

send_timeout響應客戶端超時時間,這個超時時間僅限於兩個活動之間的時間,如果超過這個時間,客戶端沒有任何活動,nginx關閉連接

server_tokens  並不會讓nginx執行的速度更快,但它可以關閉在錯誤頁面中的nginx版本數字,這樣對於安全性是有好處的。

client_max_body_size上傳文件大小限制

(5)fastcgi調優

fastcgi_connect_timeout     600;
fastcgi_send_timeout 600;
fastcgi_read_timeout 600;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k;
fastcgi_temp_path /usr/local/nginx1.10/nginx_tmp;
fastcgi_intercept_errors on;
fastcgi_cache_path /usr/local/nginx1.10/fastcgi_cache levels=1:2 keys_zone=cache_fastcgi:128m inactive=1d max_size=10g;

fastcgi_connect_timeout 600; #指定接到後端FastCGI的超時時間。

fastcgi_send_timeout 600; #FastCGI傳送請求的超時時間。

fastcgi_read_timeout 600; #指定接收FastCGI應答的超時時間。

fastcgi_buffer_size 64k; #指定讀取FastCGI應答第一部分需要用多大的緩衝區,默認的緩衝區大小爲fastcgi_buffers指令中的每塊大小,可以將這個值設置更小。

總結:

nginx的緩存功能有:proxy_cache / fastcgi_cache

proxy_cache的作用是緩存後端服務器的內容,可能是任何內容,包括靜態的和動態。
fastcgi_cache的作用是緩存fastcgi生成的內容,很多情況是php生成的動態的內容。
proxy_cache緩存減少了nginx與後端通信的次數,節省了傳輸時間和後端寬帶。
fastcgi_cache緩存減少了nginxphp的通信的次數,更減輕了php和數據庫(mysql)的壓力。

下面貼一個完整的內核優化設置:

fs.file-max = 999999
net.ipv4.ip_forward = 0
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
kernel.sysrq = 0
kernel.core_uses_pid = 1
net.ipv4.tcp_syncookies = 1
kernel.msgmnb = 65536
kernel.msgmax = 65536
kernel.shmmax = 68719476736
kernel.shmall = 4294967296
net.ipv4.tcp_max_tw_buckets = 6000
net.ipv4.tcp_sack = 1
net.ipv4.tcp_window_scaling = 1
net.ipv4.tcp_rmem = 10240 87380 12582912
net.ipv4.tcp_wmem = 10240 87380 12582912
net.core.wmem_default = 8388608
net.core.rmem_default = 8388608
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.core.netdev_max_backlog = 262144
net.core.somaxconn = 40960
net.ipv4.tcp_max_orphans = 3276800
net.ipv4.tcp_max_syn_backlog = 262144
net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_synack_retries = 1
net.ipv4.tcp_syn_retries = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_mem = 94500000 915000000 927000000
net.ipv4.tcp_fin_timeout = 1
net.ipv4.tcp_keepalive_time = 30
net.ipv4.ip_local_port_range = 1024 65000

執行sysctl  -p使內核修改生效

(10)關於系統連接數的優化:

linux 默認值 open files1024

#ulimit -n

1024

說明server只允許同時打開1024個文件

使用ulimit -a 可以查看當前系統的所有限制值,使用ulimit -n 可以查看當前的最大打開文件數。

新裝的linux 默認只有1024 ,當作負載較大的服務器時,很容易遇到error: too many open files。因此,需要將其改大

/etc/security/limits.conf最後增加:

*                soft    nofile          65535

*                hard    nofile          65535

*                soft    noproc          65535

*                hard    noproc          65535

二、部署LNMP

1、安裝php

(1)解決依賴關係

[root@CXW /]#  yum -y install libxml2-devel libcurl-devel openssl-devel bzip2-devel

安裝libmcrypt

[root@CXW src]# tar zxf libmcrypt-2.5.7.tar.gz 
[root@CXW src]# cd libmcrypt-2.5.7/
[root@CXW libmcrypt-2.5.7]# ./configure --prefix=/usr/src/libmcrypt && make && make install

(2)編譯安裝php

[root@CXW src]# tar zxf php-5.6.27.tar.gz 
[root@CXW src]# cd php-5.6.27/

(3)提供php配置文件

[root@CXW php-5.6.27]# cp php.ini-production /etc/php.ini

(4)php-fpm提供腳本

[root@CXW php-5.6.27]#  cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@CXW php-5.6.27]# chmod +x /etc/init.d/php-fpm 
[root@CXW php-5.6.27]# chkconfig --add php-fpm
[root@CXW php-5.6.27]# chkconfig php-fpm on

(5)提供php-fpm配置文件並編輯:

[root@CXW php-5.6.27]# cp /usr/src/php5.6/etc/php-fpm.conf.default /usr/src/php5.6/etc/php-fpm.conf

修改內容如下:

pid = run/php-fpm.pid
listen = 0.0.0.0:9000
pm.max_children =300
pm.start_servers =20
pm.min_spare_servers = 20
pm.max_spare_servers = 100

啓動php-fpm服務:

[root@CXW php-5.6.27]# systemctl restart php-fpm

nginx.conf文件的server中添加下面內容支持php

location ~ .*\.(php|php5)?$ {
            root html;
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            include fastcgi.conf;
            fastcgi_cache cache_fastcgi;
            fastcgi_cache_valid 200 302 1h;
            fastcgi_cache_valid 301 1d;
            fastcgi_cache_valid any 1m;
            fastcgi_cache_min_uses 1;
            fastcgi_cache_use_stale error timeout invalid_header http_500;
            fastcgi_cache_key http://$host$request_uri;
}

下面是nginx.conf的一個完整配置文件

user www www;

worker_processes  1;

worker_cpu_affinity 0001;

error_log  logs/error.log;

#error_log  logs/error.log  notice;

#error_log  logs/error.log  info;

 

pid        logs/nginx.pid;

 

 

events {

use epoll;

    worker_connections  65535;

    multi_accept on;

}

 

 

http {

include       mime.types;

    default_type  application/octet-stream;

 

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '

    #                  '$status $body_bytes_sent "$http_referer" '

    #                  '"$http_user_agent" "$http_x_forwarded_for"';

 

    #access_log  logs/access.log  main;

 

    sendfile        on;

    tcp_nopush     on;

    keepalive_timeout  65;

    tcp_nodelay on;

    client_header_buffer_size 4k;

    open_file_cache max=102400 inactive=20s;

    open_file_cache_valid 30s;

    open_file_cache_min_uses 1;

    client_header_timeout 15;

    client_body_timeout 15;

    reset_timedout_connection on;

    send_timeout 15;

    server_tokens off;

    client_max_body_size 10m;

 

    fastcgi_connect_timeout     600;

    fastcgi_send_timeout 600;

    fastcgi_read_timeout 600;

    fastcgi_buffer_size 64k;

    fastcgi_buffers     4 64k;

    fastcgi_busy_buffers_size 128k;

    fastcgi_temp_file_write_size 128k;

    fastcgi_temp_path /usr/local/nginx1.10/nginx_tmp;

    fastcgi_intercept_errors on;

    fastcgi_cache_path /usr/local/nginx1.10/fastcgi_cache levels=1:2 keys_zone=cache_fastcgi:128m inactive=1d max_size=10g;

 

gzip on;

    gzip_min_length  2k;

    gzip_buffers     4 32k;

    gzip_http_version 1.1;

    gzip_comp_level 6;

    gzip_types  text/plain text/css text/javascript application/json application/javascript application/x-javascript application/xml;

    gzip_vary on;

    gzip_proxied any;

server {

        listen       80;

        server_name  www.benet.com;

 

        #charset koi8-r;

 

        #access_log  logs/host.access.log  main;

 

        location ~* ^.+\.(jpg|gif|png|swf|flv|wma|wmv|asf|mp3|mmf|zip|rar)$ {

            valid_referers none blocked  www.benet.com benet.com;

            if ($invalid_referer) {

                #return 302  http://www.benet.com/img/nolink.jpg;

                return 404;

                break;

             }

             access_log off;

        }

        location / {

             root   html;

             index  index.php index.html index.htm;

        }

        location ~* \.(ico|jpe?g|gif|png|bmp|swf|flv)$ {

            expires 30d;

            #log_not_found off;

            access_log off;

        }

 

        location ~* \.(js|css)$ {

            expires 7d;

            log_not_found off;

            access_log off;

        }      

 

        location = /(favicon.ico|roboots.txt) {

            access_log off;

            log_not_found off;

        }

        location /status {

            stub_status on;

        }

        location ~ .*\.(php|php5)?$ {

            root html;

            fastcgi_pass 127.0.0.1:9000;

            fastcgi_index index.php;

            include fastcgi.conf;

            fastcgi_cache cache_fastcgi;

            fastcgi_cache_valid 200 302 1h;

            fastcgi_cache_valid 301 1d;

            fastcgi_cache_valid any 1m;

            fastcgi_cache_min_uses 1;

            fastcgi_cache_use_stale error timeout invalid_header http_500;

            fastcgi_cache_key http://$host$request_uri;

        }

        #error_page  404              /404.html;

 

        # redirect server error pages to the static page /50x.html

        #

        error_page   500 502 503 504  /50x.html;

        location = /50x.html {

             root   html;

        }

   }

}

[root@CXW /]# /usr/src/nginx1.10/sbin/nginx -s reload
[root@CXW /]# ab -c 500 -n 50000 http://www.benet.com/index.html

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 www.benet.com (be patient)

Completed 5000 requests

Completed 10000 requests

Completed 15000 requests

Completed 20000 requests

Completed 25000 requests

Completed 30000 requests

Completed 35000 requests

Completed 40000 requests

Completed 45000 requests

Completed 50000 requests

Finished 50000 requests

 

 

Server Software:        IIS

Server Hostname:        www.benet.com

Server Port:            80

 

Document Path:          /index.html

Document Length:        612 bytes

 

Concurrency Level:      500

Time taken for tests:   5.734 seconds

Complete requests:      50000

Failed requests:        0

Write errors:           0

Total transferred:      41800000 bytes

HTML transferred:       30600000 bytes

Requests per second:    8719.82 [#/sec] (mean)

Time per request:       57.341 [ms] (mean)

Time per request:       0.115 [ms] (mean, across all concurrent requests)

Transfer rate:          7118.92 [Kbytes/sec] received

 

Connection Times (ms)

min  mean[+/-sd] median   max

Connect:        1   25   4.2     25      38

Processing:     7   32   5.5     31      47

Waiting:        4   24   6.8     21      39

Total:         40   57   3.9     57      71

float

Percentage of the requests served within a certain time (ms)

  50%     57

  66%     59

  75%     59

  80%     60

  90%     61

  95%     62

  98%     63

  99%     64

 100%     71 (longest request)

第二次壓力測試,比較兩次的差異

[root@www ~]# ab -c 1000 -n 100000 http://www.benet.com/index.html

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 www.benet.com (be patient)

Completed 10000 requests

Completed 20000 requests

Completed 30000 requests

Completed 40000 requests

Completed 50000 requests

Completed 60000 requests

Completed 70000 requests

Completed 80000 requests

Completed 90000 requests

Completed 100000 requests

Finished 100000 requests

 

 

Server Software:        IIS

Server Hostname:        www.benet.com

Server Port:            80

 

Document Path:          /index.html

Document Length:        612 bytes

 

Concurrency Level:      1000

Time taken for tests:   12.010 seconds

Complete requests:      100000

Failed requests:        0

Write errors:           0

Total transferred:      83600000 bytes

HTML transferred:       61200000 bytes

Requests per second:    8326.49 [#/sec] (mean)

Time per request:       120.099 [ms] (mean)

Time per request:       0.120 [ms] (mean, across all concurrent requests)

Transfer rate:          6797.80 [Kbytes/sec] received

 

Connection Times (ms)

min  mean[+/-sd] median   max

Connect:        1   53   8.9     53      82

Processing:    17   67  11.4     66      98

Waiting:        0   49  14.3     43      84

Total:         70  119   6.5    120     140

 

Percentage of the requests served within a certain time (ms)

  50%    120

  66%    122

  75%    123

  80%    124

  90%    126

  95%    128

  98%    129

  99%    130

 100%    140 (longest request)

(5)xcache加速php

安裝xcache

[root@CXW src]# wget http://xcache.lighttpd.net/pub/Releases/3.2.0/xcache-3.2.0.tar.gz
[root@CXW src]# cd xcache-3.2.0/
[root@CXW xcache-3.2.0]# /usr/src/php5.6/bin/phpize

圖片1.png

[root@CXW xcache-3.2.0]# ./configure --enable-xcache --enable-xcache-coverager --enable-xcache-optimizer --with-php-config=/usr/src/php5.6/bin/php-config 
[root@CXW xcache-3.2.0]# make && make install
Installing shared extensions:

安裝完成之後,出現下面的界面,記住以下路徑,後面會用到

/usr/src/php5.6/lib/php/extensions/no-debug-non-zts-20131226/
[root@CXW xcache-3.2.0]# touch /tmp/xcache
[root@CXW xcache-3.2.0]# chmod 777 /tmp/xcache

3拷貝xcache後臺管理程序到網站根目錄

[root@CXW xcache-3.2.0]# cp -r htdocs/ /usr/src/nginx1.10/html/xcache

4配置php支持xcache

vi / etc/php.ini #編輯配置文件,在最後一行添加以下內容

[xcache-common]

extension = /usr/local/php5.6/lib/php/extensions/no-debug-zts-20131226/xcache.so

[xcache.admin]

xcache.admin.enable_auth = Off

[xcache]

xcache.shm_scheme ="mmap"

xcache.size=60M

xcache.count =1

xcache.slots =8K

xcache.ttl=0

xcache.gc_interval =0

xcache.var_size=64M

xcache.var_count =1

xcache.var_slots =8K

xcache.var_ttl=0

xcache.var_maxttl=0

xcache.var_gc_interval =300

xcache.test =Off

xcache.readonly_protection = Off

xcache.mmap_path ="/tmp/xcache"

xcache.coredump_directory =""

xcache.cacher =On

xcache.stat=On

xcache.optimizer =Off

[xcache.coverager]

xcache.coverager =On

xcache.coveragedump_directory =""

測試

[root@CXW xcache-3.2.0]# systemctl restart php-fpm

瀏覽器打開網站根目錄下面的xcache

http://http://www.benet.com/xcache可以看到如下頁面:

截圖06.png

測試對php動態頁面的壓力測試

[root@CXW xcache-3.2.0]# ab -c 1000 -n 100000 http://www.benet.com/test.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 www.benet.com (be patient)

Completed 10000 requests

Completed 20000 requests

Completed 30000 requests

Completed 40000 requests

Completed 50000 requests

Completed 60000 requests

Completed 70000 requests

Completed 80000 requests

Completed 90000 requests

Completed 100000 requests

Finished 100000 requests

 

 

Server Software:        IIS

Server Hostname:        www.benet.com

Server Port:            80

 

Document Path:          /test.php

Document Length:        85102 bytes

 

Concurrency Level:      1000

Time taken for tests:   13.686 seconds

Complete requests:      100000

Failed requests:        0

Write errors:           0

Total transferred:      8527900000 bytes

HTML transferred:       8510200000 bytes

Requests per second:    7306.71 [#/sec] (mean)

Time per request:       136.861 [ms] (mean)

Time per request:       0.137 [ms] (mean, across all concurrent requests)

Transfer rate:          608504.46 [Kbytes/sec] received

 

Connection Times (ms)

min  mean[+/-sd] median   max

Connect:        0   17   5.5     17      81

Processing:    21  119  10.8    121     140

Waiting:        1   17   6.7     16      68

Total:         50  136   8.1    137     151

 

Percentage of the requests served within a certain time (ms)

  50%    137

  66%    139

  75%    140

  80%    141

  90%    143

  95%    144

  98%    146

  99%    148

 100%    151 (longest request)

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 www.benet.com (be patient)

Completed 10000 requests

Completed 20000 requests

Completed 30000 requests

Completed 40000 requests

Completed 50000 requests

Completed 60000 requests

Completed 70000 requests

Completed 80000 requests

Completed 90000 requests

Completed 100000 requests

Finished 100000 requests

 

 

Server Software:        IIS

Server Hostname:        www.benet.com

Server Port:            80

 

Document Path:          /test.php

Document Length:        85102 bytes

 

Concurrency Level:      1000

Time taken for tests:   13.686 seconds

Complete requests:      100000

Failed requests:        0

Write errors:           0

Total transferred:      8527900000 bytes

HTML transferred:       8510200000 bytes

Requests per second:    7306.71 [#/sec] (mean)

Time per request:       136.861 [ms] (mean)

Time per request:       0.137 [ms] (mean, across all concurrent requests)

Transfer rate:          608504.46 [Kbytes/sec] received

 

Connection Times (ms)

min  mean[+/-sd] median   max

Connect:        0   17   5.5     17      81

Processing:    21  119  10.8    121     140

Waiting:        1   17   6.7     16      68

Total:         50  136   8.1    137     151

 

Percentage of the requests served within a certain time (ms)

  50%    137

  66%    139

  75%    140

  80%    141

  90%    143

  95%    144

  98%    146

  99%    148

 100%    151 (longest request)

 


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章