標籤:eaccelerator、網站最佳化、lamp效能提升
RedHat Enterprise 6.5環境下使用eAccelerator最佳化網站效能
第一步:在做最佳化之前,首先對網站伺服器的硬體做一下檢測
1,記憶體資訊:2G記憶體,swap容量為4G
[[email protected] ~]# free -m
total used free shared buffers cached
Mem: 1870 1228 642 0 47 435
-/+ buffers/cache: 744 1125
Swap: 4095 0 4095
2,cpu資訊,也可以通過cat /proc/cpuinfo查看
[[email protected] ~]# lscpu
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 1
On-line CPU(s) list: 0
Thread(s) per core: 1
Core(s) per socket: 1
Socket(s): 1
NUMA node(s): 1
Vendor ID: GenuineIntel
CPU family: 6
Model: 58
Stepping: 9
CPU MHz: 3569.819
BogoMIPS: 7139.63
Hypervisor vendor: VMware
Virtualization type: full
L1d cache: 32K
L1i cache: 32K
L2 cache: 256K
L3 cache: 8192K
NUMA node0 CPU(s): 0
[[email protected] ~]#
3,查看磁碟的續寫效能:讀取速度為:2544MB,吸入速度為847MB
[[email protected] ~]# hdparm -t /dev/sda
/dev/sda:
Timing buffered disk reads: 2544 MB in 3.00 seconds = 847.63 MB/sec
[[email protected] ~]#
4,對網站首頁進行壓力測試:ab命令
對指定網頁進行10次並發,1000次請求進行壓力測試:返回的結果是10.13
也就是說一天24小時可以承受的請求數量為:10*60*60*24=86400
[[email protected] ~]# ab -c 10 -n 1000 http://www.linuxcast.net/index.php
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking www.linuxcast.net (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.2.15
Server Hostname: www.linuxcast.net
Server Port: 80
Document Path: /index.php
Document Length: 0 bytes
Concurrency Level: 10
Time taken for tests: 98.761 seconds
Complete requests: 1000
Failed requests: 0
Write errors: 0
Non-2xx responses: 1000
Total transferred: 293000 bytes
HTML transferred: 0 bytes
Requests per second: 9.23 [#/sec] (mean)
Time per request: 987.614 [ms] (mean)
Time per request: 98.761 [ms] (mean, across all concurrent requests)
Transfer rate: 2.90 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 2.0 0 32
Processing: 355 986 49.7 985 1625
Waiting: 355 983 48.8 982 1605
Total: 355 986 49.7 985 1625
Percentage of the requests served within a certain time (ms)
50% 985
66% 997
75% 1004
80% 1010
90% 1032
95% 1050
98% 1076
99% 1097
100% 1625 (longest request)
[[email protected] ~]#
第二步:安裝eAccelerator,提升網站效能
1,安裝Development Tool工具
yum groupinstall -y "Development Tools"
2,安裝php-devel
註:可以在pkgs.org上下載相關的版本(必須和php版本相同)
[[email protected] ~]# rpm -qa | grep php
php-pdo-5.3.3-26.el6.x86_64
php-gd-5.3.3-26.el6.x86_64
php-5.3.3-26.el6.x86_64
php-common-5.3.3-26.el6.x86_64
php-devel-5.3.3-26.el6.x86_64
php-mysql-5.3.3-26.el6.x86_64
php-xml-5.3.3-26.el6.x86_64
php-cli-5.3.3-26.el6.x86_64
php-pear-1.9.4-4.el6.noarch
[[email protected] ~]# cd
[[email protected] ~]# wget http://mirror.centos.org/centos/6/os/x86_64/Packages/php-devel-5.3.3-26.el6.x86_64.rpm
--2014-08-08 14:11:48-- http://mirror.centos.org/centos/6/os/x86_64/Packages/php-devel-5.3.3-26.el6.x86_64.rpm
[[email protected] ~]# rpm -ivh php-devel-5.3.3-26.el6.x86_64.rpm
3,下載並安裝eAccelerator
[[email protected] ~]# cd /usr/local/
下載eAccelerator並命名為master.zip:
[[email protected] local]# wget https://github.com/eaccelerator/eaccelerator/zipball/master -O master.zip
[[email protected] local]# unzip master.zip
重新命名解壓縮出來的檔案夾為eAccelerator:
[[email protected] local]# mv eaccelerator-eaccelerator-42067ac/ eaccelerator
[[email protected] local]# cd eaccelerator/
[[email protected] eaccelerator]# ls
AUTHORS config.w32 debug.c eaccelerator.h ea_dasm.h ea_restore.h fnmatch.h mm.h optimize.c win32
bugreport.php control.php debug.h eaccelerator.ini ea_info.c ea_store.c Makefile.frag NEWS PHP_Highlight.php
ChangeLog COPYING doc eaccelerator_version.h ea_info.h ea_store.h Makefile.in opcodes.c README
config.m4 dasm.php eaccelerator.c ea_dasm.c ea_restore.c fnmatch.c mm.c opcodes.h README.win32
[[email protected] eaccelerator]# ls configure
ls: cannot access configure: No such file or directory
在eAccelerator目錄中執行phpize命令,產生configure檔案:
[[email protected] eaccelerator]# phpize
Configuring for:
PHP Api Version: 20090626
Zend Module Api No: 20090626
Zend Extension Api No: 220090626
[[email protected] eaccelerator]# ls configure
configure
安裝eAccelerator:
[[email protected] eaccelerator]# ./configure
[[email protected] eaccelerator]# make && make install
第三步:編輯eAccelerator的設定檔:
在/etc/php.d目錄下建立eacceleractor.ini
內容參照:https://github.com/eaccelerator/eaccelerator網頁上的
To install as PHP extension:
eAccelerator.ini檔案內容:
extension="eaccelerator.so"
eaccelerator.shm_size="16"
eaccelerator.cache_dir="/tmp/eaccelerator"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.debug="0"
eaccelerator.filter=""
eaccelerator.shm_ttl="0"
eaccelerator.shm_prune_period="0"
eaccelerator.shm_only="0"
建立eAccelerator虛擬目錄:
mkdir /tmp/eaccelerator
設定eAccelerator目錄的許可權:
chmod 0777 /tmp/eaccelerator
註:配置完成之後需要重新啟動httpd服務
service httpd restart
第四步:安裝好eAccelerator之後,再次對網站首頁進行壓力測試:
測試結果:
[[email protected] php.d]# ab -c 10 -n 1000 http://www.linuxcast.net/index.php
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking www.linuxcast.net (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.2.15
Server Hostname: www.linuxcast.net
Server Port: 80
Document Path: /index.php
Document Length: 0 bytes
Concurrency Level: 10
Time taken for tests: 41.735 seconds
Complete requests: 1000
Failed requests: 0
Write errors: 0
Non-2xx responses: 1000
Total transferred: 293000 bytes
HTML transferred: 0 bytes
Requests per second: 23.96 [#/sec] (mean)
Time per request: 417.353 [ms] (mean)
Time per request: 41.735 [ms] (mean, across all concurrent requests)
Transfer rate: 6.86 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.6 0 10
Processing: 179 417 21.9 416 480
Waiting: 178 415 21.7 415 480
Total: 179 417 21.9 416 480
Percentage of the requests served within a certain time (ms)
50% 416
66% 423
75% 429
80% 432
90% 440
95% 450
98% 461
99% 466
100% 480 (longest request)
[[email protected] php.d]#
可以看到最佳化後的返回結果為:Requests per second: 23.96 [#/sec] (mean)
也就是說,是最佳化之前的三倍。
php的加速器除了eAccelerator之外還有xcache、APC(Alternative PHP Cache)等...
本文出自 “森林部落格” 部落格,請務必保留此出處http://murongqingqqq.blog.51cto.com/2902694/1537477