3 free PHP Accelerators: APC, Eaccelerator, xcache comparison

Source: Internet
Author: User
Tags apc zts
Three free PHP accelerators: APC, Eaccelerator, xcache comparison

This article was reproduced from: http://killker.com/blog/?p=94

Always want to find some articles about the acceleration of PHP, accidentally see the killing of this article, feel good, share to everyone, and then thank the murderer.

Introduction of PHP Accelerator

? PHP Accelerator is a to improve the efficiency of PHP, thereby caching PHP operation code, so that after PHP execution does not have to parse the conversion, you can directly invoke the PHP operation code, so the speed has been improved a lot.

Request and response execution process using mod_php in Apache:

1, Apache receives the request.
2, Apache delivery request to mod_php.
3. mod_php Locate the disk file and load it into memory.
4, mod_php compiled source code becomes opcode tree.
5, mod_php execution opcode tree.

?????? PHP Accelerator is the fourth step, it is the purpose is to prevent PHP every request to compile PHP code repeatedly, because on the high-traffic site, a lot of compilation is often not executed fast? So there is a bottleneck in this is that PHP's repeated compilation affects both the speed and load of the server load, in order to solve this problem, the PHP accelerator was born.

Second, PHP accelerator installation and Configuration

???????? 1. Installation Configuration APC

APC Full name is alternative PHP cache, the official translation is called "Optional PHP cache", it is an extension in PHP pecl, it seems that Facebook is using it, the following start installation (Ubuntu environment):?
$wget http://pecl.php.net/get/APC-3.0.19.tgz
$tar Xvzf apc-3.0.19.tgz
$CD apc-3.0.19/apc-3.0.19
$/usr/local/php/bin/phpize
$./configure–enable-apc–enable-apc-mmap–with-php-config=/usr/local/php/bin/php-config
$make
$sudo make Install

Next we configure APC, because my pecl extension path has changed, so I have to move the compiled file:
$sudo mv/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/apc.so/usr/local/php/lib/php/extensions/ PECL

Then we edit the php.ini file for configuration, please add the following code to the php.ini:
Extension_dir = "/usr/local/php/lib/php/extensions/pecl"
Extension = apc.so
; Apc
apc.enabled = 1
Apc.shm_segments = 1
Apc.shm_size = 64
Apc.optimization = 1
Apc.num_files_hint = 0
Apc.ttl = 0
Apc.gc_ttl = 3600
Apc.cache_by_default = On

???? This restarts Apache to be displayed in the Phpinfo () message.

?????? 2. Installation Configuration Eaccelerator

eaccelerator's former Body is actually truck-mmcache, because the development of Truk-mmcache people are zend to pacified, so the development of eaccelerator people inherit truk-mmcache some features, design eaccelerator accelerator. Install the following:
$wget http://jaist.dl.sourceforge.net/sourceforge/eaccelerator/eaccelerator-0.9.5.tar.bz2
$tar-jxf EACCELERATOR-0.9.5.TAR.BZ2
$cd eaccelerator-0.9.5
$/usr/local/php/bin/phpize
$./configure– Enable-eaccelerator=shared–with-php-config=/usr/local/php/bin/php-config
$make
$sudo make install
$sudo Mv/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so/usr/local/php/lib/php/extensions /pecl

Add the following code to the php.ini file
Extension = eaccelerator.so
; Eaccelerator
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_max = "0"
Eaccelerator.shm_ttl = "0"
Eaccelerator.prune_period = "0"
Eaccelerator.shm_only = "0"
eaccelerator.compress = "1"
Eaccelerator.compress_level = "9"

Create a cache directory and restart Apache

$sudo Mkdir/tmp/eaccelerator
$sudo chmod 777/tmp/eaccelerator
$sudo/usr/local/apache/apachectl Restart

Check whether the installation was successful at Phpinfo ().

3. Installation Configuration XCache

XCache as the people develop their own things, small rookie I also feel proud, and XCache both in speed and performance are good. Let's try it now!

$wget http://xcache.lighttpd.net/pub/Releases/1.2.2/xcache-1.2.2.tar.gz
$tar Xvzf xcache-1.2.2.tar.gz
$CD xcache-1.2.2
$/usr/local/php/bin/phpize
$./configure–enable-xcache–enable-xcache-coverager–with-php-config=/usr/local/php/php-config
$make
$sudo make Install
$sudo mv/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/xcache.so/usr/local/php/lib/php/extensions/ PECL

To add configuration information in php.ini:

Extension = xcache.so
; XCache
Xcache.admin.user = "Admin"
Xcache.admin.pass = "(Execution) echo ' (Your password) ' |md5sum (ciphertext obtained)"
;
Xcache.size = 24M
Xcache.shm_scheme = "Mmap"
Xcache.count = 2
Xcache.slots = 8k
Xcache.ttl = 0
Xcache.gc_interval = 0

Xcache.var_size = 8M
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 = On
Xcache.mmap_path = "/tmp/xcache"
Xcache.coredump_directory = ""
Xcache.cacher = On
Xcache.stat = On
Xcache.optimizer = Off
;
Xcache.coverager = On
Xcache.coveragedump_directory = ""

Create a cache directory and restart Apache

$sudo Mkdir/tmp/xcache
$sudo chmod 777/tmp/xcache
$sudo/usr/local/apache/bin/apachectl Restart

Check out the phpinfo () information now!

Third, the PHP accelerator test

1. Test environment

Hardware: AMD Athlon X2 Dual Core Processor 4400+ @ 2.2GHz CPU, 2GB memory. 160GB SATA HDD

Software: Linux Ubuntu Server Gutsy 7.10, Apache 2.2.4, MySQL 5.0.45 and PHP 5.2.3

Test instruction: ab-c5-n3000 http://example.com/(We use Apache Benchmark (AB) tool, concurrent connection is 5, 3,000 requests)

2. Test results

No accelerator:

document Path:/
Document length:21757 bytes
Concurrency level:5
Time taken for tests:288.255212 seconds
Complete requests:300 0
Failed requests:0
Write errors:0
Total transferred:66777000 bytes
HTML transferred:65271000 bytes
Requests per second:10.41 [#/sec] (mean)
time per request:480.425 [MS] (mean)
time per request:96.085 [MS] (mean, Across all concurrent requests)
Transfer rate:226.23 [kbytes/sec] received
Connection times (ms)
Min mean[+/-s D] median max
connect:0 0 0.5 0
processing:181 479 186.0 444 1822
waiting:166 461 184.7 427 1708
Total: 181 479 186.0 444 1822
Percentage of the requests served within a certain time (ms)
50% 444
66% 525
75% 577
80% 619
90% 732
95% 819
98% 946
99% 1012
100% 1822 (longest request)

APC Accelerator:

document Path:/
Document length:21757 bytes
Concurrency level:5
Time taken for tests:98.530068 seconds
Complete requests:3000
Failed requests:0
Write errors:0
Total transferred:66777000 bytes
HTML transferred:65271000 bytes
Requests per second:30.45 [#/sec] (mean)
time per request:164.217 [MS] (mean)
time per request:32.843 [MS] (mean, Across all concurrent requests)
Transfer rate:661.84 [kbytes/sec] received
Connection times (ms)
Min mean[+/-s D] median max
connect:0 0 0.0 0 2
processing:58 163 71.2 155 2452
waiting:53 158 69.6 2329
total:58 16 3 71.2 155 2452
Percentage of the requests served within a certain time (ms)
50% 155
66% 178
75% 193
80% 20 4
90% 235
95% 258
98% 285
99% 302
100% 2452 (longest request)

eaccelerator Accelerator:

document Path:/
Document length:21757 bytes
Concurrency level:5
Time taken for tests:95.983986 seconds
Complete requests:3000
Failed requests:0
Write errors:0
Total transferred:66777000 bytes
HTML transferred:65271000 bytes
Requests per second:31.26 [#/sec] (mean)
time per request:159.973 [MS] (mean)
time per request:31.995 [MS] (mean, Across all concurrent requests)
Transfer rate:679.39 [kbytes/sec] received
Connection times (ms)
Min mean[+/-s D] median max
Connect:0 0 0.1 0 3
processing:57 159 91.3 148 3830
waiting:50 89.8 142 3704
total:57 15 9 91.3 148 3830
Percentage of the requests served within a certain time (ms)
50% 148
66% 174
75% 193
80% 20 5
90% 239
95% 263
98% 289
99% 309
100% 3830 (longest request)

xcache Accelerator:

document Path:/
Document length:21757 bytes
Concurrency level:5
Time taken for tests:99.76300 seconds
Complete requests:3000< br>failed requests:0
Write errors:0
Total transferred:66777000 bytes
HTML transferred:65271000 bytes
Requests per second:30.28 [#/sec] (mean)
time per request:165.127 [MS] (mean)
time per request:33.025 [MS] (mean, Across all concurrent requests)
Transfer rate:658.19 [kbytes/sec] received
Connection times (ms)
Min mean[+/-s D] median max
connect:0 0 0.0 0 2
processing:59 164 83.4 155 3367
waiting:52 156 66.4 148 1802
total:59 16 4 83.4 155 3367
Percentage of the requests served within a certain time (ms)
50% 155
66% 178
75% 196
80% 20 6
90% 237
95% 263
98% 287
99% 305
100% 3367 (longest request)

3. Summary of results

Request time (seconds) Single request time (milliseconds) Maximum memory consumption (MB) Minimum memory consumption (MB)
None 10.41 96.08 24 24
Apc 30.45 32.84 21st 21st
Eaccelerator 31.26 31.99 23 18
XCache 30.28 33.02 29 19

Iv. Summary of PHP Accelerator comparison results

???? 1, the test results eaccelerator in the request time and memory occupation of the synthesis is the best.

???? 2, through the test to obtain the use of accelerators than no accelerator in the request time is about 3 times times faster.

???? 3, through the official observation, XCache is the fastest update, which also shows the most development.

??????? The above is a summary of the results, you may ask me in the end use that accelerator good? I can only tell you, first of all, with a certain better than not, and then each accelerator has some tunable parameters, so depending on your system environment, then, I personally think you can study in detail under Eaccelerator and XCache, the two potential is still very large, Finally, I made a result diagram from the Comparative professional testing website:

?

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.