Three free PHP accelerators: APC, eaccelerator, and xcache

Source: Internet
Author: User
Tags apc zts

A few days ago, we added memcache support to the Nova cache system. However, this may not be suitable for personal blog systems (xklog may be useful when a multi-user version is released). In fact, for my own trial, using memcache on a single machine may result in lower performance (running time is about 20 microseconds when using shmop, and running time is about 40 microseconds when using memcache ). So I am going to drum up three PHP accelerators.

I. Introduction to the PHP accelerator

The PHP accelerator is a PHP operation code cached to improve PHP Execution efficiency. In this way, PHP does not need to be parsed or converted for subsequent execution. You can directly call the PHP operation code, this increases the speed.

In Apache, the execution process of requests and responses using mod_php is as follows:

1. Apache receives the request.
2. Apache sends the request to mod_php.
3. Locate the disk file in mod_php and load it To the memory.
4. mod_php CompilationSource codeBecome the opcode tree.
5. Run the opcode tree in mod_php.

The PHP accelerator corresponds to Step 4, which aims to prevent PHP from repeatedly compiling every request.CodeBecause on websites with high traffic volumes, a large amount of compilation is often not executed at a high speed? So there is a bottleneck in this process that PHP's repeated compilation affects both speed and server load. To solve this problem, the PHP accelerator was born.

Ii. php accelerator installation and configuration

1. install and configure APC

The full name of APC is alternative PHP cache, which is officially translated as "Optional PHP cache". It is an extension in php pecl. It seems that Facebook is using it and the following is the 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-MMAP-with-PHP-Config =/usr/local/PHP/bin/PHP-config
$ Make
$ Sudo make install

Next we will configure APC again, because my PECL extension path has changed, so I have to move the compiled file:
$ Sudo mV/usr/local/PHP/lib/PHP/extension/ no-debug-non-zts-20060613/APC. So/usr/local/PHP/lib/PHP/extensions/PECL

Then edit the php. ini file for configuration. Add the following code to 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

In this way, Apache is restarted and displayed in phpinfo.

2. install and configure eaccelerator

the predecessor of eaccelerator is truck-mmcache, because the person who developed Truk-mmcache is Zend to be installed, therefore, the developer of the eaccelerator inherits some features of truk-mmcache and designs the eaccelerator accelerator. The installation is as follows:
$ 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 cache directory and restart Apache

$ Sudo mkdir/tmp/eaccelerator
$ Sudo chmod 777/tmp/eaccelerator
$ Sudo/usr/local/Apache/apachectl restart

Check whether the installation is successful in phpinfo.

3. install and configure xcache

Xcache is developed by Chinese people. I am also proud to be a novice, and xcache is doing well in both speed and performance. Now let's try it!

$ Wget http://xcache.lighttpd.net/pub/Releases/1.2.2/xcache-1.2.2.tar.gz
$ Tar xvzf xcache-1.2.2.tar.gz
$ Xcache-1.2.2 CD
$/Usr/local/PHP/bin/phpize
$./Configure-enable-xcache-coverager-with-PHP-Config =/usr/local/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

Add configuration information in PHP. ini:

Extension = xcache. So
; Xcache
Xcache. admin. User = "admin"
Xcache. admin. Pass = "(execute) echo '(your password)' | md5sum (obtained ciphertext )"
;
Xcache. size = 24 m
Xcache. shm_scheme = "MMAP"
Xcache. Count = 2
Xcache. Slots = 8 K
Xcache. TTL = 0
Xcache. gc_interval = 0

Xcache. var_size = 8 m
Xcache. var_count = 1
Xcache. var_slots = 8 K
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 cache directory and restart Apache

$ Sudo mkdir/tmp/xcache
$ Sudo chmod 777/tmp/xcache
$ Sudo/usr/local/Apache/bin/apachectl restart

Check the phpinfo () information!

Iii. php accelerator testing

1. Test Environment

Hardware: AMD athlon 64x2 dual core processor 4400 + @ 2.2 GHz CPU, 2 GB memory. 160 gb sata hard drive

Software: Linux Ubuntu server gutsy 7.10, Apache 2.2.4, MySQL 5.0.45, and PHP 5.2.3

Test command: AB-C5-n3000 http://example.com/(we are using the Apache benchmark (AB) tool with concurrent connections of 5 to requests)

2. Test Results

No accelerators:

Document path :/
Document length: 21757 bytes
Concurrency level: 5
Time taken for tests: 288.255212 seconds
Complete requests: 3000
Failed requests: 0
Write errors: 0
Total transferred: 66777000 bytes
HTML transferred: 65271000 bytes
Requests per secondd: 10.41 [#/sec] (mean)
Time per request: 480.425 [MS] (mean)
Time per request: 96.085 [MS] (mean, internal SS all concurrent requests)
Transfer Rate: 226.23 [Kbytes/sec] canceled ed
Connection times (MS)
Min mean [+/-SD] median Max
Connect: 0 0 0.5 0 19
Processing: 181 479 186.0 444 1822
Waiting: 166 461 184.7 427
Total: 181 479 186.0 444
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 secondd: 30.45 [#/sec] (mean)
Time per request: 164.217 [MS] (mean)
Time per request: 32.843 [MS] (mean, internal SS all concurrent requests)
Transfer Rate: 661.84 [Kbytes/sec] canceled ed
Connection times (MS)
Min mean [+/-SD] median Max
Connect: 0 0 0.0 0 2
Processing: 58 163 71.2 155 2452
Waiting: 53 158 69.6 150 2329
Total: 58 163 71.2 155 2452
Percentage of the requests served within a certain time (MS)
50% 155
66% 178
75% 193
80% 204
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 secondd: 31.26 [#/sec] (mean)
Time per request: 159.973 [MS] (mean)
Time per request: 31.995 [MS] (mean, internal SS all concurrent requests)
Transfer Rate: 679.39 [Kbytes/sec] canceled ed
Connection times (MS)
Min mean [+/-SD] median Max
Connect: 0 0 0.1 0 3
Processing: 57 159 91.3 148 3830
Waiting: 50 152 89.8 142
Total: 57 159 91.3 148 3830
Percentage of the requests served within a certain time (MS)
50% 148
66% 174
75% 193
80% 205
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
Failed requests: 0
Write errors: 0
Total transferred: 66777000 bytes
HTML transferred: 65271000 bytes
Requests per secondd: 30.28 [#/sec] (mean)
Time per request: 165.127 [MS] (mean)
Time per request: 33.025 [MS] (mean, internal SS all concurrent requests)
Transfer Rate: 658.19 [Kbytes/sec] canceled ed
Connection times (MS)
Min mean [+/-SD] median Max
Connect: 0 0 0.0 0 2
Processing: 59 164 83.4 155 3367
Waiting: 52 156 66.4 148
Total: 59 164 83.4 155 3367
Percentage of the requests served within a certain time (MS)
50% 155
66% 178
75% 196
80% 206
90% 237
95% 263
98% 287
99% 305
100% 3367 (longest request)

3. Result Summary

  Request time (SEC) Time per request (MS) Maximum memory usage (MB) Minimum memory usage (MB)
None 10.41 96.08 24 24
APC 30.45 32.84 21 21
Eaccelerator 31.26 31.99 23 18
Xcache 30.28 33.02 29 19

Iv. Summary of comparison results of PHP Accelerators

1. Test results show that the eaccelerator is the best in terms of the combination of request time and memory usage.

2. The test result shows that the request time of the accelerator is about three times faster than that of the non-accelerator.

3. According to official observations, xcache is the fastest updated, which also shows the most promising development.

The above is the summary. You may ask me if I am using that accelerator? I can only tell you that, first, it is better to use it than to use it. Second, each accelerator has some parameters that can be tuned, So it depends on your system environment, I personally think you can study the eaccelerator and xcache in detail. These two models have great potential. Finally, I made a result chart from a 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.