1, Buffer acceleration principle
1. Buffer acceleration
- Opcode: when the client requests a PHP program, the PHP engine of the server will parse the PHP program and compile it into a specific opcode file (opcode file for short, binary form). By default, opcode files are discarded after being executed by the PHP engine.
- Buffer acceleration principle: save the compiled opcode and put it into shared memory so that it can be reused when calling the PHP page next time, avoiding repeated compilation of the same code.
- Advantages: it saves the time of repeated compilation of PHP engine, reduces the server load, and reduces the CPU and memory overhead.
2. LAMP environment buffer acceleration
❶ Apache receives PHP program requests from customers and filters them according to rules.
❷ Apache passes the PHP program request to the PHP processing module libphp5 so .
❸ the PHP engine locates the PHP file on the disk and loads it into memory for parsing.
❹ PHP processing module libphp5 So compile PHP source code into opcode.
❺ PHP processing module libpbp5 So executes opcode and caches opcode.
❻ Apache receives the new PHP program request from the client, and the PHP engine directly reads the cache, executes the opcode file, and returns the result. In this task, there is no compilation and parsing in step 4, which improves the efficiency of PHP compilation and parsing.
3. LNMP environment buffer acceleration
❶ Nginx receives the PHP program access request from the client.
❷ Nginx passes the PHP program request to the FCGI (phpfpm) process parsing PHP according to the extension and other filtering rules.
❸ the PHP FPM process calls the PHP parser to read the PHP file on the site disk and load it into memory.
❹ the PHP parser compiles the PHP program into an opcode file, and then caches the opcode.
❺ after the PHP FPM engine executes the opcode tree, it returns the data to Nginx, and then returns to the client.
❻ when Nginx receives the new PHP program request from the customer, the PHP-FPM engine will directly read the opcode in the cache and execute it, and return the result. There is no need for step 4 in this process, which improves the efficiency of PHP compilation and parsing.
❼ if accessing the database, the program first checks whether the data requested by the client exists in the cache of Memcached service. If so, it directly returns the requested data without requesting the back-end database.
❽ if the requested data does not exist in the Memcached cache, the program will go to the Memcahced backend database service. Return the data obtained from the database to the client.
❾ at the same time, cache a copy of the newly obtained database data into the Memcached service cache, and the next time the same request will directly return data from the Memcached service cache, so as to reduce the access pressure of the database.
2, Buffer acceleration environment
LNMP complete environment: WordPress forum for LNMP architecture deployment
1. Linux version check
[root@www ~]# cat /etc/redhat-release CentOS release 6.6 (Final) [root@www ~]# uname -r 2.6.32-504.30.3.el6.x86_64 [root@www ~]# uname -m x86_64
2. Nginx version check
[root@www ~]# /application/php/sbin/nginx -v nginx version: nginx/1.6.3
3. PHP version check
[root@www ~]# /application/php/bin/php -v PHP 5.3.27 (cli) (built: May 14 2021 10:24:11) Copyright (c) 1997-2013 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2013 Zend Technologies
4. MySQL version check
[root@www ~]# mysqladmin -uroot -pxxxx version mysqladmin Ver 8.42 Distrib 5.5.32, for linux2.6 on x86_64 Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Server version 5.5.32 Protocol version 10 Connection Localhost via UNIX socket UNIX socket /tmp/mysql.sock Uptime: 42 min 54 sec Threads: 1 Questions: 1 Slow queries: 0 Opens: 35 Flush tables: 1 Open tables: 4 Queries per second avg: 0.000
3, Plug in environment installation configuration
1. Pre environment
❶ environment variable LC_ALL
- locale environment and LC_ALL=C
- LC_ALL=C: remove all localized LC_* set up
- Solve the alarm: perl: warning: Falling back to the standard locale ("C")
[root@www ~]# vim /etc/profile slightly export LANGUAGE="en_US.UTF-8:zh_CN.UTF-8" export LANG=en_US:zh_CN.UTF-8 export LC_ALL=C "/etc/profile" 81L, 1895C Written [root@www ~]# source /etc/profile
❷ Perl dependency
- ImageMagick environment
[root@www ~]# yum install perl-devel -y Installed: perl-devel.x86_64 4:5.10.1-136.el6_6.1 Dependency Installed: db4-cxx.x86_64 0:4.7.25-19.el6_6 db4-devel.x86_64 0:4.7.25-19.el6_6 gdbm-devel.x86_64 0:1.8.0-36.el6 perl-ExtUtils-MakeMaker.x86_64 0:6.55-136.el6_6.1 perl-ExtUtils-ParseXS.x86_64 1:2.2003.0-136.el6_6.1 perl-Test-Harness.x86_64 0:3.17-136.el6_6.1 [root@www ~]# yum install perl-CPAN -y Installed: perl-CPAN.x86_64 0:1.9402-136.el6_6.1 Dependency Installed: perl-Digest-SHA.x86_64 1:5.47-136.el6_6.1
2. Database buffer
❶Memcached
- Introduction: an open source, high-performance, high concurrency and distributed memory cache service software.
- Principle: save the frequently read objects or data in the website to the pre planned system memory space. When the user accesses, first check the buffer in the Memcached service. If it exists, it will be returned directly. If it does not exist, access the database again. When accessing the database, a copy of the data will also be buffered into the Memcached service and returned directly on the next request.
- Advantages: reduce the direct high concurrent access of the front-end business to the database in peak hours, and improve the concurrent access ability of dynamic services in large-scale website clusters.
- Memcached is divided into server and client.
- The following is the client installation steps.
- Configuration parameters:/ configure --enable-memcache --with-php-config=/application/php/bin/php-config
[root@www ~]# cd /home/centos/tools [root@www tools]# rz [root@www tools]# tar zxf memcache-2.2.7.tgz [root@www tools]# cd memcache-2.2.7 [root@www memcache-2.2.7]# /application/php/bin/phpize Configuring for: PHP Api Version: 20090626 Zend Module Api No: 20090626 Zend Extension Api No: 220090626 [root@www memcache-2.2.7]# ./configure --enable-memcache --with-php-config=/application/php/bin/php-config [root@www memcache-2.2.7]# make [root@www memcache-2.2.7]# make install Installing shared extensions: /application/php/lib/php/extensions/no-debug-non-zts-20090626/ [root@www memcache-2.2.7]# cd .. [root@www tools]# ls -l /application/php/lib/php/extensions/no-debug-non-zts-20090626/ total 244 -rwxr-xr-x. 1 root root 246472 May 17 06:41 memcache.so
❷PDO_MYSQL
- Introduction: it defines a lightweight and consistent interface for PHP to access the database
- Function: provide a data access abstraction layer. Through this abstraction layer, no matter what database is used, you can query and obtain data through consistent functions.
- Configuration parameters:/ configure --with-php-config=/application/php/bin/php-config --with-pdo-mysql=/application/mysql
[root@www tools]# rz [root@www tools]# tar xf PDO_MYSQL-1.0.2.tgz [root@www tools]# cd PDO_MYSQL-1.0.2/ [root@www PDO_MYSQL-1.0.2]# /application/php/bin/phpize Configuring for: PHP Api Version: 20090626 Zend Module Api No: 20090626 Zend Extension Api No: 220090626 config.m4:104: warning: AC_CACHE_VAL(pdo_inc_path, ...): suspicious cache-id, must contain _cv_ to be cached ../../lib/autoconf/general.m4:1974: AC_CACHE_VAL is expanded from... ../../lib/autoconf/general.m4:1994: AC_CACHE_CHECK is expanded from... aclocal.m4:2754: PHP_CHECK_PDO_INCLUDES is expanded from... config.m4:104: the top level config.m4:104: warning: AC_CACHE_VAL(pdo_inc_path, ...): suspicious cache-id, must contain _cv_ to be cached ../../lib/autoconf/general.m4:1974: AC_CACHE_VAL is expanded from... ../../lib/autoconf/general.m4:1994: AC_CACHE_CHECK is expanded from... aclocal.m4:2754: PHP_CHECK_PDO_INCLUDES is expanded from... config.m4:104: the top level [root@www PDO_MYSQL-1.0.2]# ./configure --with-php-config=/application/php/bin/php-config --with-pdo-mysql=/application/mysql [root@www PDO_MYSQL-1.0.2]# make [root@www PDO_MYSQL-1.0.2]# make install Installing shared extensions: /application/php/lib/php/extensions/no-debug-non-zts-20090626/ [root@www PDO_MYSQL-1.0.2]# ls -l /application/php/lib/php/extensions/no-debug-non-zts-20090626/ total 400 -rwxr-xr-x. 1 root root 246472 May 17 06:41 memcache.so -rwxr-xr-x. 1 root root 155836 May 17 06:51 pdo_mysql.so [root@www PDO_MYSQL-1.0.2]# cd ..
3. Image processing extension
❶lmageMagick
- Introduction: a powerful, stable and free image tool set and development kit
- Purpose: it is used to read, write and process more than 89 basic formats of picture files, including popular tiff, jpeg, gif, png, pdf, PhotoCD, etc.
- Dependency: Perl devel Library
- Configure parameters/ configure
[root@www tools]# rz [root@www tools]# tar xf ImageMagick-6.7.9-10.tar.xz [root@www tools]# cd ImageMagick-6.7.9-10/ [root@www ImageMagick-6.7.9-10]# ./configure [root@www ImageMagick-6.7.9-10]# make make all-am make[1]: Entering directory `/root/PDO_MYSQL-1.0.2/ImageMagick-6.7.9-10' slightly make[1]: Leaving directory `/root/PDO_MYSQL-1.0.2/ImageMagick-6.7.9-10' [root@www ImageMagick-6.7.9-10]# make install make install-am make[1]: Entering directory `/root/PDO_MYSQL-1.0.2/ImageMagick-6.7.9-10' make[2]: Entering directory `/root/PDO_MYSQL-1.0.2/ImageMagick-6.7.9-10' slightly make[2]: Leaving directory `/root/PDO_MYSQL-1.0.2/ImageMagick-6.7.9-10' make[1]: Leaving directory `/root/PDO_MYSQL-1.0.2/ImageMagick-6.7.9-10' [root@www ImageMagick-6.7.9-10]# cd ..
❷imagick
- Introduction: an extension module for PHP to call ImageMagick function
- Dependency: ImageMagick
- Configuration parameters:/ configure --with-php-config=/application/php/bin/php-config
[root@www tools]# rz [root@www tools]# tar zxf imagick-2.3.0.tgz [root@www tools]# cd imagick-2.3.0 [root@www imagick-2.3.0]# /application/php/bin/phpize Configuring for: PHP Api Version: 20090626 Zend Module Api No: 20090626 Zend Extension Api No: 220090626 [root@www tools]# ./configure --with-php-config=/application/php/bin/php-config [root@www tools]# make [root@www imagick-2.3.0]# make install Installing shared extensions: /application/php/lib/php/extensions/no-debug-non-zts-20090626/ [root@www imagick-2.3.0]# ls -l /application/php/lib/php/extensions/no-debug-non-zts-20090626/ total 1448 -rwxr-xr-x. 1 root root 1072953 May 17 07:29 imagick.so -rwxr-xr-x. 1 root root 246472 May 17 06:41 memcache.so -rwxr-xr-x. 1 root root 155836 May 17 06:51 pdo_mysql.so [root@www imagick-2.3.0]# cd ..
4. Configuring Memcache / PDO_ MYSQL/ imagick
(1) configuration
- Back up the configuration file CP PHP ini php. ini. bak
- Add module reference path extension_dir = "/application/php/lib/php/extensions/no-debug-non-zts-20090626/"
- Reference module extension = Memcache so
[root@www xcache-3.2.0]# cd /application/php/lib [root@www lib]# ls -l [root@www lib]# cp php.ini php.ini.bak [root@www lib]# ls -l total 140 drwxr-xr-x. 15 root root 4096 May 17 06:41 php -rw-r--r--. 1 root root 69627 May 14 10:40 php.ini -rw-r--r--. 1 root root 69627 May 17 08:03 php.ini.bak [root@www lib]# vim php.ini 819 extension_dir = "/application/php/lib/php/extensions/no-debug-non-zts-20090626/" 820 extension=memcache.so 821 extension=pdo_mysql.so 822 extension=imagick.so
(2) restart
- End process pkill PHP FPM
- Restart the process / application / PHP / SBIN / PHP FPM
- Check the process PS - EF | grep PHP FPM
[root@www lib]# pkill php-fpm [root@www lib]# ps -ef | grep php-fpm | grep -v grep [root@www lib]# /application/php/sbin/php-fpm [root@www lib]# ps -ef | grep php-fpm root 43759 1 0 08:47 ? 00:00:00 php-fpm: master process (/application/php/etc/php-fpm.conf) nginx 43760 43759 0 08:47 ? 00:00:00 php-fpm: pool www nginx 43761 43759 0 08:47 ? 00:00:00 php-fpm: pool www root 43771 6577 0 08:48 pts/1 00:00:00 grep php-fpm [root@www lib]# ps -ef | grep php-fpm | grep -v grep | wc -l 3
(3) preparation
- Write test program vim /application/nginx/html/vps/realm_name/blog/viem_info.php
[root@www lib]# vim /application/nginx/conf/vps/realm_name/blog.conf server { listen 80; server_name blog.test_lnmp.org; location / { root html/vps/realm_name/blog; index index.php index.html index.htm; } location ~ .*\.(php|php5)?$ { root html/vps/realm_name/blog; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include /application/nginx/conf/fastcgi.conf; } access_log logs/access_blog.log main gzip buffer=32k flush=5s; } [root@www lib]# ls -l /application/nginx/html/vps/realm_name/blog [root@www lib]# vim /application/nginx/html/vps/realm_name/blog/viem_info.php <?php phpinfo () ; ?> [root@www lib]# /application/nginx/sbin/nginx -t nginx: the configuration file /application/nginx/conf/nginx.conf syntax is ok nginx: configuration file /application/nginx/conf/nginx.conf test is successful [root@www lib]# /application/nginx/sbin/nginx -s reload
(4) test
Visit website: blog test_ lnmp. org/viem_ info. php
In page search: memcache, pdo_mysql,imagick
4, Plug in installation configuration
Plug in selection: build relevant environment for stress test according to the actual business needs, and then select according to the actual test results.
Test environment: the following three can be installed, but cannot be configured and used together
Actual environment: install one that is most suitable for matching with related services
1,eAccelerator
(1) Introduction
- Description: a free and open source PHP acceleration, optimization and caching extension.
- Principle: cache the compiled opcode, session and other data of PHP program, store them in shared memory, and then call and execute them from memory every time. You can also set to store some compilation results that are not suitable for caching in memory on disk.
- Advantages: speed up the execution of PHP programs and reduce the load pressure on the server.
(2) installation
- Script / application/php/bin/phpize, in/ Execute before configure.
- PHP plug-in modules can be established through phpize script. Modules not configured during PHP installation and compilation can be added through phpize script.
- Configure parameters/ configure --enable-eaccelerator=shared --with-php-config=/application/php/bin/php-config; PHP installation directory -- with PHP config = / application / PHP / bin / PHP config
[root@www tools]# rz [root@www tools]# tar xf eaccelerator-0.9.6.1.tar.bz2 [root@www tools]# cd eaccelerator-0.9.6.1/ [root@www eaccelerator-0.9.6.1]# /application/php/bin/phpize Configuring for: PHP Api Version: 20090626 Zend Module Api No: 20090626 Zend Extension Api No: 220090626 [root@www eaccelerator-0.9.6.1]# ./configure --enable-eaccelerator=shared --with-php-config=/application/php/bin/php-config [root@www eaccelerator-0.9.6.1]# make [root@www eaccelerator-0.9.6.1]# make install [root@www eaccelerator-0.9.6.1]# ls /application/php/lib/php/extensions/no-debug-non-zts-20090626/ eaccelerator.so imagick.so memcache.so pdo_mysql.so [root@www eaccelerator-0.9.6.1]# cd ..
(3) configuration
❶ buffer directory and permissions
- Buffer directory mkdir -p /tmp/eaccelerator
- Permission chown - R nginx nginx /tmp/eaccelerator
[root@www lib]# mkdir -p /tmp/eaccelerator [root@www lib]# chown -R nginx.nginx /tmp/eaccelerator [root@www lib]# ls -ld /tmp/eaccelerator drwxr-xr-x. 2 nginx nginx 4096 May 17 09:23 /tmp/eaccelerator
❷ configuration parameters
parameter | explain |
---|---|
[eaccelerator] | eaccelerator acceleration module |
extension=eaccelerator.so | Load eaccelrator acceleration module. Path relative to extension_ Configuration of dir. |
eaccelerator.shm_size="64" | Size of shared memory to store cached data. If it is 0, the maximum value depends on the kernel configuration / proc/sys/kerael/shmmax. |
eaccelerator.cache_dir="/tmp/eaccelerator" | Disk cache storage path. The cache contents are precompiled code, session, data, content and user entries. The default path is "/ tmp/eaccelerator". |
eaccelerator.enable="1" | eAccelerator cache validation switch. 1 is the default value, which takes effect; 0 is closed and does not take effect. |
eaccelerator.optimizer="1" | Accelerate the execution speed of PHP code. 1 is the default value, indicating activation; 0 is inactive. Used for code acceleration before caching. |
eaccelerator.check_mtime="1" | Check the cache modification time to determine whether the code needs to be recompiled. 1 is active and is the default value. |
eaccelerator.debug="0" | For cache acceleration debugging, 0 is off and 1 is on. After opening, you can see cache acceleration information. |
eaccelerator.filter="" | Set whether the object caches rules. If it is empty, it means it is not set. |
eaccelerator.shm_max="0" | The maximum value of the cache that can be penalized. 0 is unlimited. |
eaccelerator.shm_ttl="3600" | The lifetime of the cache file. |
eaccelerator.shm_prune_period="3600" | The time period during which old data is removed from shared memory when the shared memory space is insufficient. |
eaccelerator.shm_only="0" | Whether to allow caching data to disk. 0 is allowed, but it has no effect on session data and content caching. |
eaccelerator.compress="1" | Whether to turn on compression. 1 is on. |
eaccelerator.compress_level="9" | Compression level. 9 is the highest. |
eaccelerator.keys="shm_and_disk" | Controls the location of the keys cache. shm_and_disk: cache data on shared memory and disk (default value); shm: if the shared memory is full or the data is greater than the kernel setting value, choose between the shared memory or disk; shm_only: cache data on shared memory; disk_only: cache data on disk; none: no buffering |
eaccelerator.sessions="shm_and_disk" | Control sessions cache location |
eaccelerator.content="shm_and_disk" | Control content cache location |
[root@www lib]# vim php.init [eaccelerator] extension=eaccelerator.so eaccelerator.shm_size="64" 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="3600" eaccelerator.shm_prune_period="3600" eaccelerator.shm_only="0" eaccelerator.compress="1" eaccelerator.compress_level="9"
(4) test
- Test buffer configuration / application/php/bin/php -v
[root@www lib]# /application/php/bin/php -v PHP 5.3.27 (cli) (built: May 14 2021 10:24:11) Copyright (c) 1997-2013 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2013 Zend Technologies with eAccelerator v0.9.6.1, Copyright (c) 2004-2010 eAccelerator, by eAccelerator
- Restart PHP service
[root@www lib]# killall php-fpm [root@www lib]# ps -ef | grep php-fpm [root@www lib]# /application/php/sbin/php-fpm [root@www lib]# ps -ef | grep php-fpm
-
Access check
Visit website: blog test_ lnmp. org/viem_ info. php
In page search: eaccelerator
-
View buffer directory
-
find /tmp/eaccelerator/ -type f | xargs file
-
Find the file of common type (f) find /tmp/eaccelerator/ -type f;
-
xargs captures the result of the previous command find /tmp/eaccelerator/ -type f and passes the next command file;
-
File identifies the file type.
-
/tmp/eaccelerator/4/6/eaccelerator-1502.386231: data
-
The content is eaccelerator-1502.386231
-
Type is data
[root@www lib]# ls -l /tmp/eaccelerator/ total 64 drwxrwxrwx. 18 root root 4096 May 17 09:29 0 drwxrwxrwx. 18 root root 4096 May 17 09:29 1 drwxrwxrwx. 18 root root 4096 May 17 09:29 2 drwxrwxrwx. 18 root root 4096 May 17 09:29 3 drwxrwxrwx. 18 root root 4096 May 17 09:29 4 drwxrwxrwx. 18 root root 4096 May 17 09:29 5 drwxrwxrwx. 18 root root 4096 May 17 09:29 6 drwxrwxrwx. 18 root root 4096 May 17 09:29 7 drwxrwxrwx. 18 root root 4096 May 17 09:29 8 drwxrwxrwx. 18 root root 4096 May 17 09:29 9 drwxrwxrwx. 18 root root 4096 May 17 09:29 a drwxrwxrwx. 18 root root 4096 May 17 09:29 b drwxrwxrwx. 18 root root 4096 May 17 09:29 c drwxrwxrwx. 18 root root 4096 May 17 09:29 d drwxrwxrwx. 18 root root 4096 May 17 09:29 e drwxrwxrwx. 18 root root 4096 May 17 09:29 f [root@www lib]# find /tmp/eaccelerator/ -type f | xargs file /tmp/eaccelerator/4/6/eaccelerator-1502.386231: data
2,XCache
(1) Introduction
- Description: an open source, fast and stable PHP optimization and buffer.
- Principle: cache the compiled data (opcode) of PHP program into shared memory to avoid repeated compilation of the same program. When users request the same PHP program, they can directly use the compiled data in the cache.
- Advantages: improve PHP access speed and reduce server load overhead.
(2) installation
- Configuration parameters:/ configure --enable-xcache --with-php-config=/application/php/bin/php-config
[root@www tools]# rz [root@www tools]# tar xf xcache-3.2.0.tar_2.gz [root@www tools]# cd xcache-3.2.0/ [root@www xcache-3.2.0]# /application/php/bin/phpize Configuring for: PHP Api Version: 20090626 Zend Module Api No: 20090626 Zend Extension Api No: 220090626 [root@www xcache-3.2.0]# ./configure --enable-xcache --with-php-config=/application/php/bin/php-config [root@www xcache-3.2.0]# make [root@www xcache-3.2.0]# make install [root@www xcache-3.2.0]# ls /application/php/lib/php/extensions/no-debug-non-zts-20090626/ eaccelerator.so imagick.so memcache.so pdo_mysql.so xcache.so [root@www xcache-3.2.0]# cd ..
(3) configuration
parameter | explain |
---|---|
[xcache-common] extension=xcache.so | Load Xcache So, path relative to extension_ Configuration of dir. |
[xcache.admin] xcache.admin.enable_auth=On xcache.admin.user="mOo" xcache.admin.pass="md5 encrypted password" | Activate administrator authentication. Specify XCache administrator user name and password according to http://xcache.lighttpd.net/demo/cacher/mkpassword.php Address generation, leaving blank means that the management page is prohibited |
[xcache] | XCache cache parameter configuration section |
xcache.shm_scheme="mmap" | Set how XCache allocates shared memory from the system |
xcache.size=256M | 0 disables caching, and non-0 enables caching. Note the maximum value of mmap allowed by the system |
xcache.count=2 | Specify how many blocks the Cache is divided into. The official recommendation is to set the number of server CPU s |
xcache.slots=8K | The reference value of the number of hash slots. There is no problem when the buffer exceeds this value |
xcache.ttl=86400 | Set the lifetime TTL (time to live) of the Cache object. 0 is never expired |
xcache.gc_interval=3600 | The interval at which the recycler scans expired objects to reclaim memory space. 0 is not scanned, and other values are in seconds |
xcache.var_size=64M xcache.var_count=1 xcache.var_slots=8K xcache.var_ttl=0 xcache.var_gc_interval=300 | Variable cache |
xcache.readonly_protection=Off | If this parameter is enabled, the performance will be slightly reduced, but a certain factor of safety will be improved. This option is for Xcache mmap_ PATB = / dev / zero is invalid |
xcache.mmap_path="/dev/zero" | For Nix, Xcache mmap_ Path is a file path, not a directory. If you want to enable this parameter, use a path like "/ tmp/xcache" instead of "/ dev /". If Xcache is enabled readonly_ Protection parameter, PHP of different process groups will not share the same / tmp/xcache path |
xcache.coredump_directory="" | Whether to save the data to the specified path after XCache crash |
xcache.disable_on_crash=Off | When XCache crash es, the XCache cache is automatically closed |
- Remove the comment egrep - V "; | ^ $" / home / CentOS / tools / xcache-3.2.0/xcache ini
- Match all comments "; | ^ $": comment symbols^$ Match from beginning to end
- -v parameter inverse selection
[root@www lib]# egrep -v ";|^$" /home/centos/tools/xcache-3.2.0/xcache.ini [root@www lib]# vim 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.size = 256M xcache.count = 2 xcache.slots = 8K xcache.ttl = 86400 xcache.gc_interval = 3600 xcache.var_size = 64M 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.readonly_protection = Off xcache.mmap_path = "/dev/zero" xcache.coredump_directory = "" xcache.coredump_type = 0 xcache.disable_on_crash = Off xcache.experimental = Off xcache.cacher = On xcache.stat = On xcache.optimizer = Off [xcache.coverager] xcache.coverager = Off xcache.coverager_autostart = On xcache.coveragedump_directory = ""
(4) test
- Test buffer configuration / application/php/bin/php -v
[root@www lib]# /application/php/bin/php -v PHP 5.3.27 (cli) (built: May 14 2021 10:24:11) Copyright (c) 1997-2013 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2013 Zend Technologies with XCache v3.2.0, Copyright (c) 2005-2014, by mOo with XCache Cacher v3.2.0, Copyright (c) 2005-2014, by mOo
- Generate and configure user account and password
- MD5 message digest algorithm encrypts echo -n "xxxx" | md5sum
[root@www lib]# echo -n "xxxx" | md5sum 81dc9bdb52d04dc20089dbd8313ed055 - [root@www lib]# vim php.ini [xcache.admin] xcache.admin.enable_auth = On xcache.admin.user = "centos" xcache.admin.pass = "81dc9bdb52d04dc20089dbd8313ed055"
- Copy the cache acceleration management program of XCacbe software directory to the site directory
- cp -a htdocs/ /application/nginx/html/vps/realm_name/blog/Xcache
- Give Nginx execution permission
- chown -R nginx.nginx /application/nginx/html/vps/realm_name/blog/Xcache
[root@www xcache-3.2.0]# cd /home/centos/tools/xcache-3.2.0 [root@www xcache-3.2.0]# cp -a htdocs/ /application/nginx/html/vps/realm_name/blog/Xcache [root@www xcache-3.2.0]# chown -R nginx.nginx /application/nginx/html/vps/realm_name/blog/Xcache
- Restart PHP service
[root@www xcache-3.2.0]# pkill php-fpm [root@www xcache-3.2.0]# /application/php/sbin/php-fpm
- Access test: blog test_ lnmp. org/Xcache/index. php
- Log in with the account and password set above
3. Configure ZendOpcache
(1) Introduction
- Description: Official PHP cache acceleration plug-in
- Principle: cache the compiled data (opcode) of PHP program into shared memory to avoid repeated compilation of the same program. When users request the same PHP program, they can directly use the compiled data in the cache.
(2) installation
- When installing PHP zendpcache, add the parameter -- zendpcache.
- Configuration parameters:/ configure --enable-opcache --with-php-config=/application/php/bin/php-config
[root@www tools]# rz [root@www tools]# tar xf zendopcache-7.0.5.tgz [root@www tools]# cd zendopcache-7.0.5 [root@www zendopcache-7.0.5]# /application/php/bin/phpize Configuring for: PHP Api Version: 20090626 Zend Module Api No: 20090626 Zend Extension Api No: 220090626 [root@www zendopcache-7.0.5]# ./configure --enable-opcache --with-php-config=/application/php/bin/php-config [root@www zendopcache-7.0.5]# make [root@www zendopcache-7.0.5]# make install Installing shared extensions: /application/php/lib/php/extensions/no-debug-non-zts-20090626/ [root@www zendopcache-7.0.5]# ls /application/php/lib/php/extensions/no-debug-non-zts-20090626/ eaccelerator.so imagick.so memcache.so opcache.so pdo_mysql.so xcache.so [root@www zendopcache-7.0.5]# cd ..
(3) configuration
parameter | explain |
---|---|
opcache.memory_consumption=128 | The shared memory space of OPcache is used to store precompiled PHP code. The default is 64 and the unit is Mbytes |
opcache.interned_strings_buffer=8 | The default value is 4, and the number of inter strings is M |
opcache.max_accelerated_files=4000 | The default value is 2000. The maximum number of key s in opcache hash table |
opcache.revalidate_freq=60 | The default value is 2. Check the frequency of file timestamp for changes in shared memory allocation |
opcache.fast_shutdown=1 | The default value is 0. If activated, a fast shutdown queue will be used to speed up the code |
opcache.enable_cli=1 | The default value is 0 and PHP is activated_ OPcache of CLI for testing and debugging |
- extension=opcache.so must be commented out, otherwise an error will be reported
[root@www ~]# cd /application/php/lib [root@www lib]# vim php.ini [opcache] zend_extension=/application/php/lib/php/extensions/no-debug-non-zts-20090626/opcache.so ;extension=opcache.so ;It must be commented out, otherwise an error will be reported opcache.memory_consumption=128 opcache.interned_strings_buffer=8 opcache.max_accelerated_files=4000 opcache.revalidate_freq=60 opcache.fast_shutdown=1 opcache.enable_cli=1
(4) test
- Test buffer configuration / application/php/bin/php -v
[root@www lib]# /application/php/bin/php -v PHP Warning: PHP Startup: Invalid library (maybe not a PHP library) 'opcache.so' in Unknown on line 0 PHP 5.3.27 (cli) (built: May 14 2021 10:24:11) Copyright (c) 1997-2013 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2013 Zend Technologies with Zend OPcache v7.0.5, Copyright (c) 1999-2015, by Zend Technologies
- Restart PHP service
[root@www lib]# killall php-fpm [root@www lib]# /application/php/sbin/php-fpm
Access test
Visit the website: blog test_ lnmp. org/viem_ info. php
In page search: ZendOpcache
5, Buffer acceleration optimization
1. Buffer directory optimization
- Introduction: tmpfs is a memory based file system. tmpfs is usually used as temporary data storage, which is much faster than local disk storage.
- Optimization: Mount / tmp/eaccelerator on the tmpfs file system.
[root@www lib]# vim /etc/fstab tmpfs /tmp/eaccelerator tmpfs rw,relatime,size=16384k 0 0 [root@www lib]# mount -a [root@www lib]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda3 19G 2.9G 15G 17% / tmpfs 491M 0 491M 0% /dev/shm /dev/sda1 190M 53M 128M 30% /boot tmpfs 16M 0 16M 0% /tmp/eaccelerator [root@www lib]# grep eacc /proc/mounts tmpfs /tmp/eaccelerator tmpfs rw,rootcontext=unconfined_u:object_r:user_tmp_t:s0,seclabel,relatime,size=16384k 0 0
2. Shared memory optimization
- Both XCache and eAccelerator use the shared memory of the system as storage space
- Optimization: adjust the parameters related to the size of the system kernel and shared memory
[root@www lib]# vim /etc/sysctl.conf 30 # Controls the default maxmimum size of a mesage queue 31 kernel.msgmnb = 65536 32 33 # Controls the maximum size of a message, in bytes 34 kernel.msgmax = 65536 35 36 # Controls the maximum shared segment size, in bytes 37 kernel.shmmax = 68719476736 38 39 # Controls the maximum number of shared memory segments, in pages 40 kernel.shmall = 4294967296
6, webbench stress test
1. Introduction
- Webbench is a well-known website stress testing tool.
- Test the performance of different services on the same hardware or the operation of the same service on different hardware.
- The standard test of webch is the number of corresponding requests per second and the amount of data transmitted per second.
- Webbench can simulate up to 30000 concurrent connections to test the load capacity of the website.
2. Installation
- Dependency: ctags
- Webench-1.5/makefile exists, No/ configure
[root@www ~]# yum install -y ctags [root@www ~]# cd /home/centos/tools [root@www tools]# rz [root@www tools]# tar xf webbench-1.5.tar_3.gz [root@www tools]# cd webbench-1.5 [root@www webbench-1.5]# ./configure -bash: ./configure: No such file or directory [root@www webbench-1.5]# tree -L 2 . |-- COPYRIGHT -> debian/copyright |-- ChangeLog -> debian/changelog |-- Makefile |-- debian | |-- changelog | |-- control | |-- copyright | |-- dirs | `-- rules |-- socket.c |-- webbench.1 `-- webbench.c [root@www webbench-1.5]# make slightly install: cannot create regular file `/usr/local/man/man1': No such file or directory make: *** [install] Error 1 [root@www webbench-1.5]# mkdir -p /usr/local/man/man1 [root@www webbench-1.5]# make install [root@www webbench-1.5]# make clean
3. Parameters
[root@www webbench-1.5]# webbench webbench [option]... URL -f|--force Don't wait for reply from server. -r|--reload Send reload request - Pragma: no-cache. -t|--time <sec> Run benchmark for <sec> seconds. Default 30. -p|--proxy <server:port> Use proxy server for request. -c|--clients <n> Run <n> HTTP clients at once. Default one. -9|--http09 Use HTTP/0.9 style requests. -1|--http10 Use HTTP/1.0 protocol. -2|--http11 Use HTTP/1.1 protocol. --get Use GET request method. --head Use HEAD request method. --options Use OPTIONS request method. --trace Use TRACE request method. -?|-h|--help This information. -V|--version Display program version.
4. Testing
(1) test Baidu
- 100 concurrent websench - C 100 - t 30 in 30 seconds http://www.baidu.com/
[root@www tools]# webbench -c 100 -t 30 http://www.baidu.com/ Webbench - Simple Web Benchmark 1.5 Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software. Benchmarking: GET http://www.baidu.com/ 100 clients, running 30 sec. Speed=612 pages/min, 2354904 bytes/sec. Requests: 264 susceed, 42 failed.
(2) test blog
- Perform domain name resolution echo "192.168.10.10 blog. Test_lnmp. Org" > > / etc / hosts
[root@www tools]# webbench -c 100 -t 30 http://blog.test_lnmp.org/ Webbench - Simple Web Benchmark 1.5 Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software. Benchmarking: GET http://blog.test_lnmp.org/ 100 clients, running 30 sec. Connect to server failed. Aborting benchmark. [root@www tools]# ping http://blog.test_lnmp.org/ ping: unknown host http://blog.test_lnmp.org/ [root@www tools]# echo "192.168.10.10 blog.test_lnmp.org" >>/etc/hosts [root@www tools]# tail -1 /etc/hosts 192.168.10.10 blog.test_lnmp.org [root@www tools]# ping -c 3 blog.test_lnmp.org PING blog.test_lnmp.org (192.168.10.10) 56(84) bytes of data. 64 bytes from blog.test_lnmp.org (192.168.10.10): icmp_seq=1 ttl=64 time=0.009 ms 64 bytes from blog.test_lnmp.org (192.168.10.10): icmp_seq=2 ttl=64 time=0.018 ms 64 bytes from blog.test_lnmp.org (192.168.10.10): icmp_seq=3 ttl=64 time=0.017 ms --- blog.test_lnmp.org ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 1999ms rtt min/avg/max/mdev = 0.009/0.014/0.018/0.006 ms [root@www tools]# webbench -c 100 -t 30 http://blog.test_lnmp.org/ Webbench - Simple Web Benchmark 1.5 Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software. Benchmarking: GET http://blog.test_lnmp.org/ 100 clients, running 30 sec. Speed=2010 pages/min, 226692 bytes/sec. Requests: 1005 susceed, 0 failed. [root@www tools]# webbench -c 500 -t 30 http://blog.test_lnmp.org/ Webbench - Simple Web Benchmark 1.5 Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software. Benchmarking: GET http://blog.test_lnmp.org/ 500 clients, running 30 sec. Speed=7268 pages/min, 255686 bytes/sec. Requests: 3634 susceed, 0 failed. [root@www tools]# webbench -c 1000 -t 30 http://blog.test_lnmp.org/ Webbench - Simple Web Benchmark 1.5 Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software. Benchmarking: GET http://blog.test_lnmp.org/ 1000 clients, running 30 sec. Speed=717534 pages/min, 148908 bytes/sec. Requests: 3428 susceed, 355339 failed.
5. Explain
❶ stress testing should be carried out before the product goes online, not after it goes online;
❷ when testing, it is best to turn on the monitoring of the testing machine;
❸ when testing, try to cross the public network rather than the Intranet;
❹ during the test, the concurrency should be gradually increased from small. For example, when the concurrency is 100, observe the website load, whether the opening is smooth, how much it is when the concurrency is 200, how much it is when the website opens slowly, and how much it is when the website cannot be opened;
❺ unit tests should be carried out as far as possible. For example, B2C websites can focus on testing shopping carts and promotion pages, because these pages account for a large proportion of the visits of the whole website;
❻ the more data obtained, the more accurate.