We've been working to improve PHP7 performance, and last month we were very excited to note that GCC's PGO can bring nearly 10% performance improvements on WordPress.
However, PGO as the name says (Profile guided optimization interested in Google), he needs to use a few use cases to get feedback, which means that the optimization needs to be tied to a particular scenario.
Your optimization of a scene may backfire in another scenario. It is not a generic optimization. So we can't simply include these optimizations, and we can't directly post PGO compiled PHP7.
Of course, we are trying to find some common optimization from the PGO, and then manually apply to PHP7, but this obviously can not do for a special optimization of the scene can achieve the effect, so I decided to write this article briefly describes how to use the PGO to compile PHP7, The PHP7 that you compile can make your own application faster and more unique.
The first thing to decide is what to take to feedback GCC, and we will generally choose: in the scenario you want to optimize: the most visited, the most time-consuming, and the most resource-consuming page.
Take WordPress For example, we choose the home page of WordPress (because the home page is often the largest number of visits).
let's take my machine for example :
- Intel (R) Xeon (r) CPU X5687 @ 3.60GHz X 16 (Hyper-threading)
- 48G Memory
PHP-FPM uses fixed 32 worker, Opcache adopts the default configuration (must remember to load Opcache)
Optimize the scene with WordPress 4.1.
First, we will test the current WP performance in PHP7 (ab-n 10000-c 100):
- $ ab-n 10000-c http://inf-dev-maybach.weibo.com:8000/wordpress/
- This is apachebench, 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 (Be patient)
- Completed 1000 Requests
- Completed Requests
- Completed 3000 Requests
- Completed 4000 Requests
- Completed 5000 Requests
- Completed 6000 Requests
- Completed 7000 Requests
- Completed 8000 Requests
- Completed 9000 Requests
- Completed 10000 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 second:1116.48 [#/sec] (mean)
- Time per request:89.567 [MS] (mean)
- Time/request:0.896 [MS] (mean, across all concurrent requests)
- Transfer rate:10124.65 [Kbytes/sec] Received
Visible WordPress 4.1 is currently on this machine, the home page QPS can to 1116.48. That is, every second you can handle so many requests to the home page,
Now, let's start by teaching gcc, get him to compile a run Wordpress4.1 faster PHP7, first ask for GCC versions above 4.0, but I suggest you use the GCC-4.8 version (now GCC-5.1).
The first step, nature is to download PHP7 source code, and then do./configure. None of this is any different.
And then there's the difference, and first we're going to compile the PHP7 first, and let it generate the executable file that generates profile data:
Note that we use the Prof-gen parameter (this is PHP7 makefile specific, don't try to do it on other projects:))
And 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 100 times the homepage of WordPress, thus generating some profile information in this process.
Then we start the second compilation of PHP7.
- $ make Prof-clean
- $ make prof-use && make install
OK, so simple, PGO compilation is complete, now let's look at the performance of the PHP7 after PGO compilation:
- $ ab-n10000-c http://inf-dev-maybach.weibo.com:8000/wordpress/
- This is apachebench, 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 (Be patient)
- Completed 1000 Requests
- Completed Requests
- Completed 3000 Requests
- Completed 4000 Requests
- Completed 5000 Requests
- Completed 6000 Requests
- Completed 7000 Requests
- Completed 8000 Requests
- Completed 9000 Requests
- Completed 10000 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 second:1191.78 [#/sec] (mean)
- Time per request:83.908 [MS] (mean)
- Time/request:0.839 [MS] (mean, across all concurrent requests)
- Transfer rate:10807.45 [Kbytes/sec] Received
Now can handle 1191.78 QPS per second, Ascension is ~7%. Still not Raiha (Yi, you say 10%?) How did it become 7%? Well, as I said before, we try to analyze what PGO have done to optimize, and then apply some generic optimizations manually to the PHP7. So that means that ~3% 's more generic optimizations are already included in the PHP7, and of course the work continues.
So it is so simple, you can use their own products in the classic scene to train gcc, simple steps to get promotion, why not do it:)
Thanks
Editor's note: This is the PHP great god--brother Bird @Laruence Works, the original address: http://www.laruence.com/2015/06/19/3063.html
"Responsible Editor: Wangxueyan TEL: (010) 68476606"