53、PHP啓用xcache加速

資源限定

軟限制:可以超出的限制,但僅能超出一定時長

硬限制:絕對不能超出的限制

ulimit:只能修改軟限制

   -n [N]:顯示或限制能打開的最大的文件句柄數,

   -u [N]:所能夠打開的最大進程數

如果修改硬限制

/etc/security/limits.conf,擴展配置etc/security/limits.d/*.conf

對誰進行限定    類型  要限定的選項 值

apache hard nofile65535

apache hard nproc30000


ab工具的初步使用

-c 模擬的併發數

-n 模擬的總請求數

一般併發數應該小於等於請求數   

ulimit -n 3000

ab -c 100 -n 10000 http://192.168.130.65/pma/index.php


啓動加速前

[root@localhost ~]# ab -c 10 -n 1000 http://192.168.130.65/pma/index.php  

This is ApacheBench, Version 2.3 <$Revision: 1843412 $>

Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/

Licensed to The Apache Software Foundation, http://www.apache.org/


Benchmarking 192.168.130.65 (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:        Apache/2.4.37

Server Hostname:        192.168.130.65

Server Port:            80


Document Path:          /pma/index.php

Document Length:        14323 bytes


Concurrency Level:      10

Time taken for tests:   19.420 seconds

Complete requests:      1000

Failed requests:        947

   (Connect: 0, Receive: 0, Length: 947, Exceptions: 0)

Total transferred:      15841640 bytes

HTML transferred:       14321640 bytes

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

Time per request:       194.201 [ms] (mean)

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

Transfer rate:          796.62 [Kbytes/sec] received


Connection Times (ms)

              min  mean[+/-sd] median   max

Connect:        0    0   0.2      0       7

Processing:   105  192  93.3    153     786

Waiting:       98  185  92.7    145     778

Total:        105  192  93.3    153     786


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

  50%    153

  66%    193

  75%    227

  80%    262

  90%    337

  95%    373

  98%    437

  99%    522

 100%    786 (longest request)

[root@localhost ~]# 


1、安裝

tar xf xcache-3.2.0.tar.gz 

cd xcache-3.2.0

/usr/local/php/bin/phpize

./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config

make && make install


安裝結束時,會出現類似如下行:

Installing shared extensions:     /usr/local/php/lib/php/extensions/no-debug-zts-20131226/


2、編輯php.ini,整合php和xcache:

mkdir /etc/php.d

cp xcache.ini /etc/php.d

vim /etc/php.d/xcache.ini

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



啓動加速後

[root@localhost xcache-3.2.0]# ab -c 10 -n 1000 http://192.168.130.65/pma/index.php  

This is ApacheBench, Version 2.3 <$Revision: 1843412 $>

Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/

Licensed to The Apache Software Foundation, http://www.apache.org/


Benchmarking 192.168.130.65 (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:        Apache/2.4.37

Server Hostname:        192.168.130.65

Server Port:            80


Document Path:          /pma/index.php

Document Length:        14322 bytes


Concurrency Level:      10

Time taken for tests:   6.322 seconds

Complete requests:      1000

Failed requests:        871

   (Connect: 0, Receive: 0, Length: 871, Exceptions: 0)

Total transferred:      15842084 bytes

HTML transferred:       14322084 bytes

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

Time per request:       63.225 [ms] (mean)

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

Transfer rate:          2446.95 [Kbytes/sec] received


Connection Times (ms)

              min  mean[+/-sd] median   max

Connect:        0    0   0.1      0       0

Processing:    36   63  55.1     50     670

Waiting:       34   60  54.8     47     670

Total:         36   63  55.1     50     670


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

  50%     50

  66%     56

  75%     62

  80%     65

  90%     78

  95%     98

  98%    229

  99%    426

 100%    670 (longest request)

[root@localhost xcache-3.2.0]# 




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