We have been working hard to improve the performance of PHP7. Last month we noticed that GCC PGO can bring nearly 10% performance improvement on WordPress, which makes us very excited. However, PGO, as its name suggests (Profile Guided Optimization, you can Google it if you are interested), requires some use cases to get feedback, which means that this optimization needs to be bound to a specific scenario. What you optimize for one scenario may not work for another scenario. It is not a universal optimization. So we cannot simply include these optimizations, nor can we release PGO-compiled PHP7 directly. Of course, we are trying to find some common optimizations from PGO and then manually apply them to PHP7, but this obviously cannot achieve the effect that can be achieved by special optimization for a scenario, so I decided to write this article to briefly introduce how to use PGO to compile PHP7, so that your compiled PHP7 can make your own independent application faster. First, you need to decide which scenario to use to give feedback to GCC. We usually choose: the page with the most visits, the most time-consuming, and the most resource-intensive page in the scenario you want to optimize. Take WordPress as an example, we choose the homepage of WordPress (because the homepage is often the most visited). Let's take my machine as an example:
php-fpm uses a fixed 32 workers, and opcache uses the default configuration (be sure to remember to load opcache) Taking WordPress 4.1 as the optimization scenario.. First, let's test the current performance of WP in PHP7 (ab -n 10000 -c 100):
It can be seen that WordPress 4.1 currently on this machine, the QPS of the home page can reach 1116.48. That is, it can process so many requests for the home page per second. Now, let's start teaching GCC to compile PHP7 to run faster than WordPress4.1. First of all, GCC 4.0 or above is required, but I recommend everyone to use GCC-4.8 or above (now GCC-5.1). The first step is to download the PHP7 source code and then do ./configure. There is no difference between Now here's the difference, we have to compile PHP7 first, to make it generate the executable file that will generate the profile data:
Note that we use the prof-gen parameter (this is specific to PHP7 Makefile, don’t try this on other projects :) ) Then, let's start training GCC:
That is, let php-cgi run the homepage of wordpress 100 times, and generate some profile information in the process. Then, we start compiling PHP7 for the second time.
OK, that's it, PGO compilation is complete, now let's take a look at the performance of PHP7 after PGO compilation:
Now we can process 1191.78 QPS per second, which is an improvement of ~7%. Not bad (Hey, didn’t you say 10%? How did it become 7%? Haha, as I said before, we tried to analyze what optimizations PGO has done, and then manually apply some common optimizations to PHP7. So in other words, the ~3% of more common optimizations have been included in PHP7, of course this work is still ongoing). So it’s that simple. You can use the classic scenarios of your own products to train GCC. With just a few simple steps, you can get an improvement. Why not? |
<<: I asked the programmer goddess for her QQ number, but...
>>: Hprose for Node.js 1.6.0 released
Zuoyebang is committed to providing learning tuto...
Not long ago, at the Shanghai CJ, the domestic bl...
There is something strange happening with the sca...
Author: Yan Yongjun, Unit: China Mobile Smart Hom...
Author: Cheng Wangrong, vivo Internet Server Team...
Survival or destruction? This is not only a philo...
Recently, "Nezha 2: The Devil Boy Conquers t...
First, let me tell you a story: There was a pair ...
The author of this article leads everyone to have...
A comatose male patient in his 30s was sent to th...
The latest traffic rankings of major information ...
On July 12, Alibaba's subsidiary Lingyang rel...
199IT original compilation There are still many t...
Traffic is a hot topic that all walks of life are...
What are we talking about when we talk about ad v...