Make your PHP 7 faster (gcc pgo)

Source: Internet
Author: User

Make your PHP 7 faster (gcc pgo)

We have been committed to improving the performance of PHP 7. Last month we noticed that the gcc pgo can improve the performance by nearly 10% on Wordpress, which made us very excited.

However, PGO, as the name suggests (Google can be used for Profile Guided Optimization), needs some use cases for feedback, that is, the Optimization needs to be bound to a specific scenario.

Your Optimization for one scenario may be counterproductive in another scenario. it is not a general optimization. therefore, we cannot simply include these optimizations or directly release the php7after PGO compilation.

Of course, we are trying to find some common optimizations from PGO and Apply them to PHP7 manually, but this obviously cannot achieve the effect of special optimization for a scenario, so I decided to write this article to briefly introduce how to use PGO to compile PHP7, so that the PHP7 compiled by you can specifically make your own independent applications faster.

First, we need to decide what scenarios to use for Feedback GCC. We generally choose: In the scenario you want to optimize: the most visited, the most time-consuming, the most resource-consuming page.

Take Wordpress as an example. We select the Wordpress homepage (because the homepage is usually the most visited ).

Take my machine as an example:

  1. Intel (R) Xeon (R) CPU X5687 @ 3.60 GHz X 16 (hyper-threading ),
  2. 48G Memory

Php-fpm uses 32 fixed workers, and opcache uses the default configuration (remember to load opcache)

Wordpress 4.1 is used as the optimization scenario ..

First, we will test the current performance of WP in PHP 7 (AB-n 10000-c 100 ):

  1. $ AB-n 10000-c 100 http://inf-dev-maybach.weibo.com: 8000/wordpress/
  2. This is apachetings, Version 2.3 <$ Revision: 655654 $>
  3. Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
  4. Licensed to The Apache Software Foundation, http://www.apache.org/
  5.  
  6. Benchmarking inf-dev-maybach.weibo.com)
  7. Completed1000 requests
  8. Completed2000 requests
  9. Completed3000 requests
  10. Completed4000 requests
  11. Completed5000 requests
  12. Completed6000 requests
  13. Completed7000 requests
  14. Completed8000 requests
  15. Completed9000 requests
  16. Completed10000 requests
  17. Finished 10000 requests
  18.  
  19. Server Software: nginx/1.7.12
  20. Server Hostname: inf-dev-maybach.weibo.com
  21. Server Port: 8000
  22.  
  23. Document Path:/wordpress/
  24. Document Length: 9048 bytes
  25.  
  26. Concurrency Level: 100
  27. Time taken for tests: 8.957 seconds
  28. Complete requests: 10000
  29. Failed requests: 0
  30. Write errors: 0
  31. Total transferred: 92860000 bytes
  32. HTML transferred: 90480000 bytes
  33. Requests per secondd: 1116.48 [#/sec] (mean)
  34. Time per request: 89.567 [MS] (mean)
  35. Time per request: 0.896 [MS] (mean, internal SS all concurrent requests)
  36. Transfer rate: 10124.65 [Kbytes/sec] canceled ed

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 process so many requests to the homepage every second,

Now, let's start to teach GCC and let him compile PHP7 that runs Wordpress4.1 faster. First, we need GCC 4.0 or later versions, but I suggest you use a version of GCC-4.8 or above (all GCC-5.1 now ).

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

Next there is a difference. We need to first compile PHP7 so that it can generate an executable file that generates profile data:

  1. $ Make prof-gen

Note that the prof-gen parameter is used (this is unique to the Makefile of PHP7. Do not try this on other projects)

Then, let's start training GCC:

  1. $ Sapi/cgi/php-cgi-T 100/home/huixinchen/local/www/htdocs/wordpress/index. php>/dev/null

That is, let php-cgi run the wordpress homepage 100 times to generate some profile information during this process.

Then, we start to compile php7for the second time.

  1. $ Make prof-clean
  2. $ Make prof-use & make install

Okay, that's simple. PGO compilation is complete. Now let's take a look at the performance of PHP7 after PGO Compilation:

  1. $ AB-n10000-c 100 http://inf-dev-maybach.weibo.com: 8000/wordpress/
  2. This is apachetings, Version 2.3 <$ Revision: 655654 $>
  3. Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
  4. Licensed to The Apache Software Foundation, http://www.apache.org/
  5.  
  6. Benchmarking inf-dev-maybach.weibo.com)
  7. Completed1000 requests
  8. Completed2000 requests
  9. Completed3000 requests
  10. Completed4000 requests
  11. Completed5000 requests
  12. Completed6000 requests
  13. Completed7000 requests
  14. Completed8000 requests
  15. Completed9000 requests
  16. Completed10000 requests
  17. Finished 10000 requests
  18.  
  19. Server Software: nginx/1.7.12
  20. Server Hostname: inf-dev-maybach.weibo.com
  21. Server Port: 8000
  22.  
  23. Document Path:/wordpress/
  24. Document Length: 9048 bytes
  25.  
  26. Concurrency Level: 100
  27. Time taken for tests: 8.391 seconds
  28. Complete requests: 10000
  29. Failed requests: 0
  30. Write errors: 0
  31. Total transferred: 92860000 bytes
  32. HTML transferred: 90480000 bytes
  33. Requests per secondd: 1191.78 [#/sec] (mean)
  34. Time per request: 83.908 [MS] (mean)
  35. Time per request: 0.839 [MS] (mean, internal SS all concurrent requests)
  36. Transfer rate: 10807.45 [Kbytes/sec] canceled ed

Now we can process 1191.78 QPS per second. The increase is ~ 7%. Not long enough (sorry, didn't you say 10%? Why is it 7%? Haha, as I said before, we try to analyze what PGO has done, and then Apply some General optimizations to PhP 7 manually. That is to say, that ~ 3% of the more general optimizations have been included in PHP7, and of course this work is still going on ).

So it's that simple. You can use the classic scenario of your product to train GCC. It's just a few steps to improve your performance. Why not?

PHP 7 innovation and Performance Optimization

PHP 7, you deserve it

Experience PHP 7.0 on CentOS 7.x/Fedora 21

Install LNMP in CentOS 6.3 (PHP 5.4, MyySQL5.6)

Nginx startup failure occurs during LNMP deployment.

Ubuntu install Nginx php5-fpm MySQL (LNMP environment setup)

Detailed php hd scanning PDF + CD source code + full set of teaching videos

Configure the php lnmp development environment in CentOS 6

PHP details: click here
PHP: click here

This article permanently updates the link address:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.