Make your PHP 7 faster GCC PGO
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.
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>
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>
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>
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>
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>
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>
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.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

There are four ways to adjust the WordPress article list: use theme options, use plugins (such as Post Types Order, WP Post List, Boxy Stuff), use code (add settings in the functions.php file), or modify the WordPress database directly.

WordPress IP blocking plugin selection is crucial. The following types can be considered: based on .htaccess: efficient, but complex operation; database operation: flexible, but low efficiency; firewall: high security performance, but complex configuration; self-written: highest control, but requires more technical level.

The steps to create a custom header in WordPress are as follows: Edit the theme file "header.php". Add your website name and description. Create a navigation menu. Add a search bar. Save changes and view your custom header.

WordPress editing dates can be canceled in three ways: 1. Install the Enable Post Date Disable plug-in; 2. Add code in the functions.php file; 3. Manually edit the post_modified column in the wp_posts table.

WordPress Error Resolution Guide: 500 Internal Server Error: Disable the plug-in or check the server error log. 404 Page not found: Check permalink and make sure the page link is correct. White Screen of Death: Increase the server PHP memory limit. Database connection error: Check the database server status and WordPress configuration. Other tips: enable debug mode, check error logs, and seek support. Prevent errors: regularly update WordPress, install only necessary plugins, regularly back up your website, and optimize website performance.

Enable comments in WordPress website: 1. Log in to the admin panel, go to "Settings" - "Discussions", and check "Allow comments"; 2. Select a location to display comments; 3. Customize comments; 4. Manage comments, approve, reject or delete; 5. Use <?php comments_template(); ?> tags to display comments; 6. Enable nested comments; 7. Adjust comment shape; 8. Use plugins and verification codes to prevent spam comments; 9. Encourage users to use Gravatar avatar; 10. Create comments to refer to

To log in to a WordPress website account: Visit the login page: Enter the website URL plus "/wp-login.php". Enter your username and password. Click "Login". Verification Two-step Verification (optional). After successfully logging in, you will see the website dashboard.

A step-by-step guide to replacing a header image of WordPress: Log in to the WordPress dashboard and navigate to Appearance >Theme. Select the topic you want to edit and click Customize. Open the Theme Options panel and look for the Site Header or Header Image options. Click the Select Image button and upload a new head image. Crop the image and click Save and Crop. Click the Save and Publish button to update the changes.
