Home > Article > Backend Development > Understand the transformation of PHP7 performance in one minute (performance increased by 4 times)
PHP5.1 The average response time of quick sorting with 5000 numbers is 2587ms
PHP5.2 The average response time of quick sorting with 5000 numbers is 2625ms
PHP5.3 The average response time of quick sorting with 5000 numbers is 2509ms
PHP5.4 5000 number quick sorting average response time 2339ms
PHP7.0 5000 number quick sorting average response time 685ms
PHP5.1 WordPress average response time 505ms
PHP5.2 WordPress average response time 521ms
PHP5.3 WordPress average response time 498ms
PHP5.4 WordPress average response time 470ms
PHP7. 0 WordPress average response time 158ms
PHP5.4 500 quick sorting TPS 552
PHP7.0 500 Number quick sort TPS 3165
Flyme community APP home page PHP5.4 TPS 1535
Flyme community APP home page PHP7.0 TPS 1975
Flyme community APP section list page PHP5.4 TPS 2237
Flyme community APP section List page PHP7.0 TPS 2387
1. JIT
2. Changes in Zval
3. Internal type zend_string
4. Changes in PHP arrays (HashTable and Zend Array)
5. Function calling mechanism (Function Calling Convention)
6. Through macro definitions and inline functions (inline), let the compiler complete part of the work in advance
The purpose of Redis Proxy is for Redis high availability & distributed caching
Passed The performance test is relatively direct connection to redis. The performance loss of using Proxy is about 10-15% (different businesses may have relatively large differences)
So is there room for optimization of Proxy?
PHP7 Redis long connection performance is about 10% higher than short connection performance (different businesses vary greatly)
The database connection pool is responsible for allocating, managing and releasing database connections. It allows applications to reuse an existing database connection instead of establishing a new one.
Atlas is database middleware developed and maintained by 360. It is located between the application and MySQL. It implements the client-server protocol of MySQL, communicates with the application as a server, and communicates with MySQL as a client. It shields DB details from applications and reduces the burden on MySQL.
Atlas supports main database downtime without affecting reading, read-write separation, automatic table sharding, security processing, smooth restart, connection pool, etc.
After using the database connection pool, the TPS performance leverage is increased by 80%
Let’s take a look at the effect
How Opcache accelerates
Look at the results after adding opcache (request average The response time has been reduced by half.)
PGO is a compilation optimization technology that can be used with compilers such as GCC to improve the compilation efficiency of the compiler.
Although PGO can improve compilation efficiency, it is not widely used.
The reason is very simple:
1. Its complicated dual compilation model and limited usage scenarios make PGO seem useless
2. After the emergence of products like opcache, the performance improvement brought by PGO It's not very obvious.
<source lang="xml" collapse="false" first-line="1"> #php-fpm.conf listen = /dev/shm/php-fcgi.sock #php-fpm2.conf listen = /dev/shm/php-fcgi2.sock #/usr/local/php/sbin/php-fpm --fpm-config /usr/local/php/etc/php-fpm.conf #/usr/local/php/sbin/php-fpm --fpm-config /usr/local/php/etc/php-fpm2.conf #代理 upstream backend{ server unix:/dev/shm/php-fcgi.sock; server unix:/dev/shm/php-fcgi2.sock; } </source>
HugePage (increase 2%-3%)
The default memory is paged at 4KB, and the virtual address and the memory address need to be converted, and this conversion requires a table lookup.
In order to speed up the table lookup process, the CPU will have a built-in TLB (Translation Lookaside Buffer). Obviously, if the virtual page is smaller, the number of entries in the table will be more.
And the TLB size is limited. The more entries, the higher the Cache Miss of the TLB will be. So if we can enable large memory pages, This TLB Cache Miss can be indirectly reduced.
<source lang="xml" collapse="false" first-line="1"> opcache.huge_code_pages=1 sudo sysctl vm.nr_hugepages=128 </source>
Phase performance parameter optimization
php.ini configuration
<source lang="xml" collapse="false" first-line="1"> opcache.enable=1 opcache.enable_cli=1 opcache.memory_consumption=128 opcache.interned_strings_buffer=8 opcache.max_accelerated_files=4000 opcache.revalidate_freq=60 opcache.save_comments=0 opcache.fast_shutdown=1 opcache.huge_code_pages=1 opcache.file_cache=/dev/shm/opcache/ </source>
PHP-FPM
<source lang="xml" collapse="false" first-line="1"> listen = /dev/shm/php-fcgi.sock pm = static pm.max_children = 320 pm.max_requests = 10240 </source>
Nginx HTTPS performance issues
##Background of researching PHP7 technologyThe above is the detailed content of Understand the transformation of PHP7 performance in one minute (performance increased by 4 times). For more information, please follow other related articles on the PHP Chinese website!