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
[[125938]] The smart home market is very hot now,...
Every company wants to build its own internet cel...
In the early morning of June 8th, Beijing time, t...
Lao A’s practical course on selling goods on Xian...
There are many ways for e-commerce to exist, but ...
In fact, promoting the Internet is not difficult,...
Yeah? Which two little guys are standing on the r...
On March 7, Beijing time, the Geneva Internationa...
Flow Off If you build a community and run it very...
Follow Captain Da Shanzha Wan Set sail for the st...
Recently I found that some friends wanted to attr...
The annual Google I/O developer conference arrive...
In an era where content is king, the value of hig...