Make your PHP 7 faster (gcc pgo)
We have been committed to improving the performance of PHP 7. Last month we noticed that the gcc pgo can improve the performance by nearly 10% on Wordpress, which made us very excited.
However, PGO, as the name suggests (Google can be used for Profile Guided Optimization), needs some use cases for feedback, that is, the Optimization needs to be bound to a specific scenario.
Your Optimization for one scenario may be counterproductive in another scenario. it is not a general optimization. therefore, we cannot simply include these optimizations or directly release the php7after PGO compilation.
Of course, we are trying to find some common optimizations from PGO and Apply them to PHP7 manually, but this obviously cannot achieve the effect of special optimization for a scenario, so I decided to write this article to briefly introduce how to use PGO to compile PHP7, so that the PHP7 compiled by you can specifically make your own independent applications faster.
First, we need to decide what scenarios to use for Feedback GCC. We generally choose: In the scenario you want to optimize: the most visited, the most time-consuming, the most resource-consuming page.
Take Wordpress as an example. We select the Wordpress homepage (because the homepage is usually the most visited ).
Take my machine as an example:
- Intel (R) Xeon (R) CPU X5687 @ 3.60 GHz X 16 (hyper-threading ),
- 48G Memory
Php-fpm uses 32 fixed workers, and opcache uses the default configuration (remember to load opcache)
Wordpress 4.1 is used as the optimization scenario ..
First, we will test the current performance of WP in PHP 7 (AB-n 10000-c 100 ):
- $ AB-n 10000-c 100 http://inf-dev-maybach.weibo.com: 8000/wordpress/
- This is apachetings, Version 2.3 <$ Revision: 655654 $>
- Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
- Licensed to The Apache Software Foundation, http://www.apache.org/
-
- Benchmarking inf-dev-maybach.weibo.com)
- Completed1000 requests
- Completed2000 requests
- Completed3000 requests
- Completed4000 requests
- Completed5000 requests
- Completed6000 requests
- Completed7000 requests
- Completed8000 requests
- Completed9000 requests
- Completed10000 requests
- Finished 10000 requests
-
- Server Software: nginx/1.7.12
- Server Hostname: inf-dev-maybach.weibo.com
- Server Port: 8000
-
- Document Path:/wordpress/
- Document Length: 9048 bytes
-
- Concurrency Level: 100
- Time taken for tests: 8.957 seconds
- Complete requests: 10000
- Failed requests: 0
- Write errors: 0
- Total transferred: 92860000 bytes
- HTML transferred: 90480000 bytes
- Requests per secondd: 1116.48 [#/sec] (mean)
- Time per request: 89.567 [MS] (mean)
- Time per request: 0.896 [MS] (mean, internal SS all concurrent requests)
- Transfer rate: 10124.65 [Kbytes/sec] canceled ed
It can be seen that Wordpress 4.1 is currently on this machine, and the QPS of the homepage can reach 1116.48. That is, it can process so many requests to the homepage every second,
Now, let's start to teach GCC and let him compile PHP7 that runs Wordpress4.1 faster. First, we need GCC 4.0 or later versions, but I suggest you use a version of GCC-4.8 or above (all GCC-5.1 now ).
The first step is to download the source code of PHP 7, and then do./configure. There is no difference between these.
Next there is a difference. We need to first compile PHP7 so that it can generate an executable file that generates profile data:
- $ Make prof-gen
Note that the prof-gen parameter is used (this is unique to the Makefile of PHP7. Do not try this on other projects)
Then, let's start training GCC:
- $ Sapi/cgi/php-cgi-T 100/home/huixinchen/local/www/htdocs/wordpress/index. php>/dev/null
That is, let php-cgi run the wordpress homepage 100 times to generate some profile information during this process.
Then, we start to compile php7for the second time.
- $ Make prof-clean
- $ Make prof-use & make install
Okay, that's simple. PGO compilation is complete. Now let's take a look at the performance of PHP7 after PGO Compilation:
- $ AB-n10000-c 100 http://inf-dev-maybach.weibo.com: 8000/wordpress/
- This is apachetings, Version 2.3 <$ Revision: 655654 $>
- Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
- Licensed to The Apache Software Foundation, http://www.apache.org/
-
- Benchmarking inf-dev-maybach.weibo.com)
- Completed1000 requests
- Completed2000 requests
- Completed3000 requests
- Completed4000 requests
- Completed5000 requests
- Completed6000 requests
- Completed7000 requests
- Completed8000 requests
- Completed9000 requests
- Completed10000 requests
- Finished 10000 requests
-
- Server Software: nginx/1.7.12
- Server Hostname: inf-dev-maybach.weibo.com
- Server Port: 8000
-
- Document Path:/wordpress/
- Document Length: 9048 bytes
-
- Concurrency Level: 100
- Time taken for tests: 8.391 seconds
- Complete requests: 10000
- Failed requests: 0
- Write errors: 0
- Total transferred: 92860000 bytes
- HTML transferred: 90480000 bytes
- Requests per secondd: 1191.78 [#/sec] (mean)
- Time per request: 83.908 [MS] (mean)
- Time per request: 0.839 [MS] (mean, internal SS all concurrent requests)
- Transfer rate: 10807.45 [Kbytes/sec] canceled ed
Now we can process 1191.78 QPS per second. The increase is ~ 7%. Not long enough (sorry, didn't you say 10%? Why is it 7%? Haha, as I said before, we try to analyze what PGO has done, and then Apply some General optimizations to PhP 7 manually. That is to say, that ~ 3% of the more general optimizations have been included in PHP7, and of course this work is still going on ).
So it's that simple. You can use the classic scenario of your product to train GCC. It's just a few steps to improve your performance. Why not?
PHP 7 innovation and Performance Optimization
PHP 7, you deserve it
Experience PHP 7.0 on CentOS 7.x/Fedora 21
Install LNMP in CentOS 6.3 (PHP 5.4, MyySQL5.6)
Nginx startup failure occurs during LNMP deployment.
Ubuntu install Nginx php5-fpm MySQL (LNMP environment setup)
Detailed php hd scanning PDF + CD source code + full set of teaching videos
Configure the php lnmp development environment in CentOS 6
PHP details: click here
PHP: click here
This article permanently updates the link address: