Make your PHP7 faster (GCCPGO) _ PHP Tutorial

Source: Internet
Author: User
Make your PHP7 faster (GCCPGO ). To make your PHP7 faster (GCCPGO), we have been committed to improving the performance of PHP7. Last month we noticed that the gcc pgo can improve performance by nearly 10% on Wordpress, this makes us very excited to 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 ).

Let's 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 ApacheBench, 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. Benchmarking inf-dev-maybach.weibo.com (be patient)
  6. Completed 1000 requests
  7. Completed 2000 requests
  8. Completed 3000 requests
  9. Completed 4000 requests
  10. Completed 5000 requests
  11. Completed 6000 requests
  12. Completed 7000 requests
  13. Completed 8000 requests
  14. Completed 9000 requests
  15. Completed 10000 requests
  16. Finished 10000 requests
  17. Server Software: nginx/1.7.12
  18. Server Hostname: inf-dev-maybach.weibo.com
  19. Server Port: 8000
  20. Document Path: /wordpress/
  21. Document Length: 9048 bytes
  22. Concurrency Level: 100
  23. Time taken for tests: 8.957 seconds
  24. Complete requests: 10000
  25. Failed requests: 0
  26. Write errors: 0
  27. Total transferred: 92860000 bytes
  28. HTML transferred: 90480000 bytes
  29. Requests per second: 1116.48 [#/sec] (mean)
  30. Time per request: 89.567 [ms] (mean)
  31. Time per request: 0.896 [ms] (mean, across all concurrent requests)
  32. Transfer rate: 10124.65 [Kbytes/sec] received

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 too :))

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 ApacheBench, 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. Benchmarking inf-dev-maybach.weibo.com (be patient)
  6. Completed 1000 requests
  7. Completed 2000 requests
  8. Completed 3000 requests
  9. Completed 4000 requests
  10. Completed 5000 requests
  11. Completed 6000 requests
  12. Completed 7000 requests
  13. Completed 8000 requests
  14. Completed 9000 requests
  15. Completed 10000 requests
  16. Finished 10000 requests
  17. Server Software: nginx/1.7.12
  18. Server Hostname: inf-dev-maybach.weibo.com
  19. Server Port: 8000
  20. Document Path: /wordpress/
  21. Document Length: 9048 bytes
  22. Concurrency Level: 100
  23. Time taken for tests: 8.391 seconds
  24. Complete requests: 10000
  25. Failed requests: 0
  26. Write errors: 0
  27. Total transferred: 92860000 bytes
  28. HTML transferred: 90480000 bytes
  29. Requests per second: 1191.78 [#/sec] (mean)
  30. Time per request: 83.908 [ms] (mean)
  31. Time per request: 0.839 [ms] (mean, across all concurrent requests)
  32. Transfer rate: 10807.45 [Kbytes/sec] received

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 it. why not :)

Thanks

Editor's note: This article is the PHP God -- bird brother @ Laruence works, the original address: http://www.laruence.com/2015/06/19/3063.html

Faster than PHP 7 (gcc pgo) we have been committed to improving the performance of PHP 7. Last month we noticed that the gcc pgo can improve performance by nearly 10% on Wordpress, this makes us very excited...

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.