PHP opcode Cache Acceleration Component: APC Introduction

Source: Internet
Author: User
Tags apc apc module file info min php file php code server port zend

PHP is not a significant performance relative to other compiled languages, but performance improvement after using the opcode cache is obvious. Common cache acceleration components are mainly EACCELERATOR,XCACHE,APC this article mainly introduces the installation and use of APC.

APC, the full name is alternative PHP cache, official translation is called "Optional PHP caching." It provides us with a framework for caching and optimizing PHP's intermediate code. The APC cache is divided into two parts: the system cache and the user data cache.

System cache

It means that the APC caches the compiled results of the PHP file source code, and then compares the time tag with each call. If it is not expired, it is run using the cached intermediate code. The default cache is 3600s (one hour). But it still wastes a lot of CPU time. Therefore, you can set the system cache to never expire (apc.ttl=0) in php.ini. However, if you do this, you need to restart the Web server after you change the PHP code. This type of caching is currently used more often.

User Data caching

Caching is read and written by the user when writing PHP code using the Apc_store and Apc_fetch function operations. If the amount of data is small, you can try. If the volume of data is large, it would be better to use a more monographs memory caching scheme similar to Memcache.

Installation of APC Module

The easiest way to do this is to use pecl directly and enter at the command line:/usr/local/php/bin/pecl Install APC
Then follow the prompts step-by-step, as shown in the following example:

[Root@iz23bm1tc0pz ~]#/usr/local/php/bin/pecl Install APC
Downloading apc-3.1.13.tgz ...
Starting to download apc-3.1.13.tgz (171,591 bytes)
... done:171,591 bytes-----------------------
source files, Building
Running:phpize
Configuring for:
PHP Api version:20100412
Zend Module Api no:20100525
Zend Extension Api no:220100525
Enable internal debugging in APC [No]: No
Enable per request file info about files used from the APC cache [No]: No
Enable Spin Locks (experimental) [No]: No
Enable memory Protection (experimental) [No]: No
Enable pthread mutexes (default) [No]: No
Enable pthread Read/write Locks (experimental) [Yes]: Yes

Then reboot the server:

LNMP nginx Restart

Let's take a look at the test results without using APC:

[Root@iz23bm1tc0pz ~]# ab-n1000-c100 http://zfsphp.cn/index.php
This is apachebench, Version 2.3 < $Revision: 1706008 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to the Apache Software Foundation, http://www.apache.org/
Benchmarking zfsphp.cn (Be patient)
Completed Requests
Completed Requests
Completed Requests
Completed Requests
Completed Requests
Completed Requests
Completed Requests
Completed Requests
Completed 900 Requests
Completed 1000 Requests
Finished 1000 requests
Server Software:nginx
Server Hostname:zfsphp.cn
Server port:80
Document Path:/index.php
Document length:14341 bytes
Concurrency level:100
Time taken for tests:15.517 seconds
Complete requests:1000
Failed requests:0
Total transferred:14544000 bytes
HTML transferred:14341000 bytes
Requests per second:64.45 [#/sec] (mean)
Time per request:1551.671 [MS] (mean)
Time/request:15.517 [MS] (mean, across all concurrent requests)
Transfer rate:915.34 [Kbytes/sec] Received
Connection Times (MS)
Min MEAN[+/-SD] Median max
Connect:0 2 4.8 0 17
processing:46 1481 277.0 1560 1638
Waiting:42 1481 277.1 1560 1638
total:58 1482 272.8 1560 1638
Percentage of the requests served within a certain time (MS)
50% 1560
66% 1576
75% 1582
80% 1587
90% 1602
95% 1612
98% 1622
99% 1629
100% 1638 (Longest request)
Visible maximum throughput rate is only 64.45reqs/s

Then we open the APC and the test results are as follows:

[Root@iz23bm1tc0pz ~]# ab-n1000-c100 http://zfsphp.cn/index.php
This is apachebench, Version 2.3 < $Revision: 1706008 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to the Apache Software Foundation, http://www.apache.org/
Benchmarking zfsphp.cn (Be patient)
Completed Requests
Completed Requests
Completed Requests
Completed Requests
Completed Requests
Completed Requests
Completed Requests
Completed Requests
Completed 900 Requests
Completed 1000 Requests
Finished 1000 requests
Server Software:nginx
Server Hostname:zfsphp.cn
Server port:80
Document Path:/index.php
Document length:14341 bytes
Concurrency level:100
Time taken for tests:7.122 seconds
Complete requests:1000
Failed requests:0
Total transferred:14544000 bytes
HTML transferred:14341000 bytes
Requests per second:140.41 [#/sec] (mean)
Time per request:712.189 [MS] (mean)
Time/request:7.122 [MS] (mean, across all concurrent requests)
Transfer rate:1994.29 [Kbytes/sec] Received
Connection Times (MS)
Min MEAN[+/-SD] Median max
Connect:0 1 2.4 0 10
Processing:23 677 125.3 705 775
Waiting:22 677 125.4 705 775
Total:30 678 123.1 705 775
Percentage of the requests served within a certain time (MS)
50% 705
66% 719
75% 726
80% 730
90% 742
95% 750
98% 760
99% 765
100% 775 (Longest request)

Visible throughput rate increased by more than one times, to reach 140.41reqs/s.
Then, we open the dynamic content cache (the landlord's blog with the Smarty cache), the test results are as follows:

[Root@iz23bm1tc0pz ~]# ab-n1000-c100 http://zfsphp.cn/index.php
This is apachebench, Version 2.3 < $Revision: 1706008 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to the Apache Software Foundation, http://www.apache.org/
Benchmarking zfsphp.cn (Be patient)
Completed Requests
Completed Requests
Completed Requests
Completed Requests
Completed Requests
Completed Requests
Completed Requests
Completed Requests
Completed 900 Requests
Completed 1000 Requests
Finished 1000 requests
Server Software:nginx
Server Hostname:zfsphp.cn
Server port:80
Document Path:/index.php
Document length:14341 bytes
Concurrency level:100
Time taken for tests:2.263 seconds
Complete requests:1000
Failed requests:0
Total transferred:14544000 bytes
HTML transferred:14341000 bytes
Requests per second:441.98 [#/sec] (mean)
Time per request:226.255 [MS] (mean)
Time/request:2.263 [MS] (mean, across all concurrent requests)
Transfer rate:6277.49 [Kbytes/sec] Received
Connection Times (MS)
Min MEAN[+/-SD] Median max
Connect:0 1 3.1 0 12
Processing:18 215 38.1 222 255
Waiting:18 215 38.3 222 255
Total:26 216 35.6 223 255
Percentage of the requests served within a certain time (MS)
50% 223
66% 230
75% 232
80% 234
90% 237
95% 239
98% 240
99% 243
100% 255 (Longest request)

This time throughput unexpectedly reached 441.98reqs/s, increased by more than three times times, compared to the original 64.45REQS/S improved nearly 7 times times, can be seen using APC opcode cache with Smarty cache, the optimization of the performance of the site is quite obvious.

Related Article

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.