Make your PHP 7 faster GCC PGO

WBOY
Release: 2016-08-08 09:22:12
Original
1631 people have browsed it

We have been working hard to improve the performance of PHP7. Last month we noticed that GCC's PGO can bring nearly 10% performance improvement on WordPress. This makes us very excited.

Make your PHP 7 faster GCC PGO

However, PGO is just as its name says. As mentioned (Profile Guided Optimization, if you are interested, you can Google it), he needs to use some use cases to get feedback, which means that this optimization needs to be bound to a specific scenario.

Your optimization of one scenario may be used in another scenario One scenario backfired. It is not a universal optimization. So we cannot simply include these optimizations, nor can we directly release PHP7 compiled by PGO.

Of course, we are trying to find some common optimizations from PGO, and then Manually Apply to PHP7, but this obviously cannot achieve the effect that special optimization for a scene can achieve, so I decided to write this article to briefly introduce how to use PGO to compile PHP7, so that the PHP7 you compile can be special Make your own independent application faster.

First of all, the first thing to decide is what scenario to use to Feedback GCC. We usually choose: In the scenario you want to optimize: the one with the largest number of visits and the one that takes the most time. The page that consumes the most resources.

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:

<ol>
<li><span><span>Intel(R) Xeon(R) CPU           X5687  @ 3.60GHz X 16(超线程), </span></span></li>
<li><span> </span></li>
<li><span>48G Memory </span></li>
</ol>
Copy after login

php-fpm uses a fixed 32 worker, opcache adopts the default configuration (be sure to remember to load opcache)

Using wordpress 4.1 as the optimization scenario..

First, let’s test the current performance of WP in PHP7 (ab -n 10000 -c 100):

<ol>
<li><span><span>$ ab -n 10000 -c 100 http:</span><span>//inf-dev-maybach.weibo.com:8000/wordpress/</span><span> </span></span></li>
<li><span> </span></li>
<li><span>This is ApacheBench, Version 2.3 <<span>$Revision</span><span>: 655654 $> </span></li>
<li><span> </span></li>
<li><span>Copyright 1996 Adam Twiss, Zeus Technology Ltd, http:<span>//www.zeustech.net/</span><span> </span></span></li>
<li><span> </span></li>
<li><span>Licensed to The Apache Software Foundation, http:<span>//www.apache.org/</span><span> </span></span></li>
<li><span> </span></li>
<li><span>Benchmarking inf-dev-maybach.weibo.com (be patient) </span></li>
<li><span> </span></li>
<li><span>Completed 1000 requests </span></li>
<li><span> </span></li>
<li><span>Completed 2000 requests </span></li>
<li><span> </span></li>
<li><span>Completed 3000 requests </span></li>
<li><span> </span></li>
<li><span>Completed 4000 requests </span></li>
<li><span> </span></li>
<li><span>Completed 5000 requests </span></li>
<li><span> </span></li>
<li><span>Completed 6000 requests </span></li>
<li><span> </span></li>
<li><span>Completed 7000 requests </span></li>
<li><span> </span></li>
<li><span>Completed 8000 requests </span></li>
<li><span> </span></li>
<li><span>Completed 9000 requests </span></li>
<li><span> </span></li>
<li><span>Completed 10000 requests </span></li>
<li><span> </span></li>
<li><span>Finished 10000 requests </span></li>
<li><span> </span></li>
<li><span>Server Software:        nginx/1.7.12 </span></li>
<li><span> </span></li>
<li><span>Server Hostname:        inf-dev-maybach.weibo.com </span></li>
<li><span> </span></li>
<li><span>Server Port:            8000 </span></li>
<li><span> </span></li>
<li><span>Document Path:          /wordpress/ </span></li>
<li><span> </span></li>
<li><span>Document Length:        9048 bytes </span></li>
<li><span> </span></li>
<li><span>Concurrency Level:      100 </span></li>
<li><span> </span></li>
<li><span>Time taken <span>for</span><span> tests:   8.957 seconds </span></span></li>
<li><span> </span></li>
<li><span>Complete requests:      10000 </span></li>
<li><span> </span></li>
<li><span>Failed requests:        0 </span></li>
<li><span> </span></li>
<li><span>Write errors:           0 </span></li>
<li><span> </span></li>
<li><span>Total transferred:      92860000 bytes </span></li>
<li><span> </span></li>
<li><span>HTML transferred:       90480000 bytes </span></li>
<li><span> </span></li>
<li><span>Requests per second:    1116.48 [#/sec] (mean) </span></li>
<li><span> </span></li>
<li><span>Time per request:       89.567 [ms] (mean) </span></li>
<li><span> </span></li>
<li><span>Time per request:       0.896 [ms] (mean, across all concurrent requests) </span></li>
<li><span> </span></li>
<li><span>Transfer rate:          10124.65 [Kbytes/sec] received </span></li>
</ol>
Copy after login

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 handle so many requests for the homepage per second.

Now, let us start teaching GCC and let it compile and run WordPress 4.1 The faster PHP7 is coming, it first requires GCC 4.0 or above, but I recommend that everyone use GCC-4.8 or above (now GCC-5.1).

The first step is to download the source code of PHP7, and then Do ./configure. There is no difference between these

The next thing is the difference. We must first compile PHP7 for the first time and let it generate an executable file that generates profile data:

<ol><li><span><span>$ make prof-gen <br></span></span></li></ol>
Copy after login

Note that we use prof -gen parameter (this is unique to the Makefile of PHP7, don’t try to do it in other projects:))

Then, let’s start training GCC:

<ol><li><span><span>$ sapi/cgi/php-cgi -T </span><span>100</span><span> /home/huixinchen/local/www/htdocs/wordpress/index.php >/dev/</span><span>null</span><span> </span></span></li></ol>
Copy after login

That is, let php-cgi run 100 times on the WordPress homepage , thus generating some profile information in the process.

Then, we start compiling PHP7 for the second time.

<ol>
<li><span><span>$ make prof-clean </span></span></li>
<li><span>$ make prof-<span>use</span><span> && make install </span></span></li>
</ol>
Copy after login

Okay, it’s that simple, PGO compilation is completed, now let’s look at the performance of PHP7 after PGO compilation :

<ol>
<li><span><span>$ ab -n10000 -c </span><span>100</span><span> http:</span><span>//inf-dev-maybach.weibo.com:8000/wordpress/</span><span> </span></span></li>
<li><span> </span></li>
<li><span>This is ApacheBench, Version <span>2.3</span><span> <$Revision: </span><span>655654</span><span> $> </span></span></li>
<li><span> </span></li>
<li><span>Copyright <span>1996</span><span> Adam Twiss, Zeus Technology Ltd, http:</span><span>//www.zeustech.net/</span><span> </span></span></li>
<li><span> </span></li>
<li><span>Licensed to The Apache Software Foundation, http:<span>//www.apache.org/</span><span> </span></span></li>
<li><span> </span></li>
<li><span>Benchmarking inf-dev-maybach.weibo.com (be patient) </span></li>
<li><span> </span></li>
<li><span>Completed <span>1000</span><span> requests </span></span></li>
<li><span> </span></li>
<li><span>Completed <span>2000</span><span> requests </span></span></li>
<li><span> </span></li>
<li><span>Completed <span>3000</span><span> requests </span></span></li>
<li><span> </span></li>
<li><span>Completed <span>4000</span><span> requests </span></span></li>
<li><span> </span></li>
<li><span>Completed <span>5000</span><span> requests </span></span></li>
<li><span> </span></li>
<li><span>Completed <span>6000</span><span> requests </span></span></li>
<li><span> </span></li>
<li><span>Completed <span>7000</span><span> requests </span></span></li>
<li><span> </span></li>
<li><span>Completed <span>8000</span><span> requests </span></span></li>
<li><span> </span></li>
<li><span>Completed <span>9000</span><span> requests </span></span></li>
<li><span> </span></li>
<li><span>Completed <span>10000</span><span> requests </span></span></li>
<li><span> </span></li>
<li><span>Finished <span>10000</span><span> requests </span></span></li>
<li><span> </span></li>
<li><span>Server Software:        nginx/<span>1.7</span><span>.</span><span>12</span><span> </span></span></li>
<li><span> </span></li>
<li><span>Server Hostname:        inf-dev-maybach.weibo.com </span></li>
<li><span> </span></li>
<li><span>Server Port:            <span>8000</span><span> </span></span></li>
<li><span> </span></li>
<li><span>Document Path:          /wordpress/ </span></li>
<li><span> </span></li>
<li><span>Document Length:        <span>9048</span><span> bytes </span></span></li>
<li><span> </span></li>
<li><span>Concurrency Level:      <span>100</span><span> </span></span></li>
<li><span> </span></li>
<li><span>Time taken <span>for</span><span> tests:   </span><span>8.391</span><span> seconds </span></span></li>
<li><span> </span></li>
<li><span>Complete requests:      <span>10000</span><span> </span></span></li>
<li><span> </span></li>
<li><span>Failed requests:        <span>0</span><span> </span></span></li>
<li><span> </span></li>
<li><span>Write errors:           <span>0</span><span> </span></span></li>
<li><span> </span></li>
<li><span>Total transferred:      <span>92860000</span><span> bytes </span></span></li>
<li><span> </span></li>
<li><span>HTML transferred:       <span>90480000</span><span> bytes </span></span></li>
<li><span> </span></li>
<li><span>Requests per second:    <span>1191.78</span><span> [#/sec] (mean) </span></span></li>
<li><span> </span></li>
<li><span>Time per request:       <span>83.908</span><span> [ms] (mean) </span></span></li>
<li><span> </span></li>
<li><span>Time per request:       <span>0.839</span><span> [ms] (mean, across all concurrent requests) </span></span></li>
<li><span> </span></li>
<li><span>Transfer rate:          <span>10807.45</span><span> [Kbytes/sec] received </span></span></li>
</ol>
Copy after login

Now it can process 1191.78 QPS per second, the improvement is ~7%. Not bad (Hey, didn’t you say 10%? How come it is 7%? Haha, as I said before, we try Analyze what optimizations PGO has done, and then manually apply some common optimizations to PHP7. So in other words, ~3% of the more common optimizations have been included in PHP7, of course, this work is still continuing).

So it’s that simple. You can use the classic scenes of your own products to train GCC. In a few simple steps, you can get improved. Why not do it:)

thanks

Editor’s note: This article is written by PHP master——Bird Brother @Laruence’s work, original address: http://www.laruence.com/2015/06/19/3063.html

The above has introduced GCC PGO to make your PHP 7 faster, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!