Zendopcache, XCache, eaccelerator Comparison of PHP service cache optimization

Source: Internet
Author: User
Tags bz2 fpm ini min php code zts server port zend

PHP Service Caching Optimization principle


Nginx the PHP program request to the fcgi of parsing PHP based on the extension or filtering rules, that is, the PHP-FPM process


Cache operation code (opcode)

Opcode,php compiled intermediate files, cached for user access

When a client requests a PHP program, the server's PHP engine parses the PHP program and compiles it into a specific opcode file, which is a binary file representation of the PHP code that executes. By default, this compiled opcode file is discarded by the PHP engine, and the principle of opcode caching is to save the compiled opcode and put it into shared memory so that it can be reused the next time the PHP page is called, avoiding duplicate compilation of the same code. Saves the PHP engine from repeating compile time, reduces server load, and reduces CPU and memory overhead.

Common PHP cache Acceleration software

1) XCache

Tested, XCache more efficient, community active, compatible PHP version

2) Zendopcache

Apache Independent research and Development software, 5.5 version after the band, plus Enbale-opcache compiler parameters directly used, but the software stability to be detected

3) Eaccelerator

Accelerated software used frequently in the 5.3 release, and with the advent of the 5.5 version, and the emergence of excellent software such as XCache, community activity began to decline

Caching software preferred Xcahe, continuous attention zendopcache ...

XCache deployment

1) Download XCache, add as PHP expansion module, compile and install

[Root@web01 tools]# wget http://xcache.lighttpd.net/pub/Releases/3.2.0/xcache-3.2.0.tar.bz2
[Root@web01 tools]# Tar XF xcache-3.2.0.tar.bz2
[Root@web01 tools]# CD xcache-3.2.0
[Root@web01 xcache-3.2.0]#/application/php/bin/phpize
[Root@web01 xcache-3.2.0]#./configure--enable-xcache--with-php-config=/application/php/bin/php-config
[Root@web01 xcache-3.2.0]# make && make install
...
Installing Shared extensions:/application/php5.5.32/lib/php/extensions/no-debug-non-zts-20121212/
Installing header files:/application/php5.5.32/include/php/
2) Configure PHP extension to take effect

[Root@db02 application]# Vim/application/php/lib/php.ini
Extension_dir = "/application/php5.5.32/lib/php/extensions/no-debug-non-zts-20121212/"
Extension = memcache.so
Extension = imagick.so
Extension = xcache.so
3 Restart PHP After the module is effective

[Root@db02 application]#/application/php/bin/php-m|grep "XCache"
XCache
XCache Cacher
4) XCache configuration file

[Root@db02 ~]# cat ~/tools/xcache-3.2.0/xcache.ini|egrep-v "^;|^" >>/application/php/lib/php.ini
[Xcache-common]
Extension = xcache.so #模块

[Xcache.admin]
Xcache.admin.enable_auth = on #开启密码认证

Xcache.admin.user = "MOo"
Xcache.admin.pass = "MD5 encrypted password"

[XCache]

Xcache.shm_scheme = "Mmap" #设置Xcache如何从系统分配共享内存
Xcache.size = 60M #缓存大小, 0 disable caching
Xcache.count = 1 #指定将xcache切分为多少块, recommended the same as CPU core (grep-c Processor/proc/cpuinfo)
Xcache.slots = 8K
Xcache.ttl = 0 #设置cache对象生存期TTL, 0 never expires; If the number of online, small
Xcache.gc_interval = 0 #回收器扫描过期的对象回收内存空间的间隔, 0 not scanned
Xcache.var_size = 4M #变量缓存, not opcache cache
Xcache.var_count = 1
Xcache.var_slots = 8K
Xcache.var_ttl = 0
Xcache.var_maxttl = 0
Xcache.var_gc_interval = 300

Xcache.var_namespace_mode = 0
Xcache.var_namespace = ""
Xcache.coredump_type = 0
5) View PHP chache loading

[Root@db02 ~]#/application/php/sbin/php-fpm-v
PHP 5.5.32 (fpm-fcgi) (Built:jun 29 2016 11:32:56)
Copyright (c) 1997-2015 the PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2015 Zend Technologies
With XCache v3.2.0, the Copyright (c) 2005-2014, by MOo
With XCache Cacher v3.2.0, Copyright (c) 2005-2014, by MOo
6 Web Interface Configuration

[Root@db02 ~]# echo-n "123456" |md5sum
E10ADC3949BA59ABBE56E057F20F883E-
[ROOT@DB02 ~]# CP ~/tools/xcache-3.2.0/htdocs/application/nginx/html/www/xadmin-a
[Root@db02 ~]# Vim/application/php/lib/php.ini
[Date]
Date.timezone = asia/chongqing
[Xcache.admin]
Xcache.admin.enable_auth = On

Xcache.admin.user = "Admin"
Xcache.admin.pass = "e10adc3949ba59abbe56e057f20f883e"
[Root@db02 ~]# Pkill php-fpm
[Root@db02 ~]#/APPLICATION/PHP/SBIN/PHP-FPM

AB pressure test effect

1) before adding XCache

[Root@db02 application]# ab-n 3000-c http://10.0.0.111/test_info.php
# 3,000 times session request, 100 concurrent number
Server software:nginx/1.6.3
Server hostname:10.0.0.111
Server port:80
Document Path:/test_info.php #测试页面
Document length:83921 bytes #页面大小
Concurrency level:100 #100并发数
Time taken for tests:7.973 seconds #整个测试持续时间
Complete requests:3000 #完成的请求总数
Failed requests:302 #失败的请求次数
(connect:0, receive:0, length:302, exceptions:0)
Write errors:0
Total transferred:252203675 bytes #整个过程的网络传输量
HTML transferred:251762675 bytes #HTML内容传输量
Requests per second:376.25 [#/sec] (mean) #吞吐量, the number of concurrent numbers that can be processed each second
Time per request:265.779 [MS] (mean) #平均事务响应时间
Time/request:2.658 [MS] (mean, across all concurrent requests)
#每个连接请求实际运行时间
Transfer rate:30889.42 [Kbytes/sec] Received
#平均每秒网络上的流量 to help eliminate the problem of large network traffic causing a prolonged response time
Connection Times (MS)
Min MEAN[+/-SD] Median max
Connect:0 1 3.2 0 21
Processing:14 261 32.2 261 331
Waiting:2 260 32.4 260 331
Total:29 261 29.9 261 331
Percentage of the requests served within a certain time (MS)
50% 261
66% 268
75% 273
80% 276
90% 287 #90% of the request task completed within 287MS
95% 303
98% 315
99% 322
100% 331 (Longest request)
2) after configuring Xache

[Root@db02 application]# ab-n 3000-c http://10.0.0.111/test_info.php
Server software:nginx/1.6.3
Server hostname:10.0.0.111
Server port:80
Document Path:/test_info.php
Document length:172 bytes
Concurrency level:100
Time taken for tests:0.516 seconds
Complete requests:3000
Failed requests:0
Write errors:0
Non-2xx responses:3000
Total transferred:969000 bytes
HTML transferred:516000 bytes
Requests per second:5819.42 [#/sec] (mean) #并发数上升为5000 +
Time per request:17.184 [MS] (mean)
Time/request:0.172 [MS] (mean, across all concurrent requests)
Transfer rate:1835.62 [Kbytes/sec] Received
Connection Times (MS)
Min MEAN[+/-SD] Median max
Connect:0 0 1.3 0 9
Processing:6 17 2.1 16 21
waiting:0 17 2.2 16 21
Total:7 17 1.6 16 21
Percentage of the requests served within a certain time (MS)
50% 16
66% 17
75% 18
80% 19
90% 19
95% 19
98% 20
99% 21
100% (Longest request)
Because it is a virtual machine test environment, not necessarily very accurate, not installed XCache concurrent number in 400-500, after the installation of the number of concurrency in 5000, the cache effect of 10 times times more ...

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.