Make your PHP 7 faster (GCC PGO)

Source: Internet
Author: User
Tags net version server port

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 :

 
  
  
  1. Intel (R) Xeon (r) CPU X5687 @ 3.60GHz X 16 (Hyper-threading)
  2. 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):

 
 
  1. $ ab-n 10000-c 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 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/request:0.896 [MS] (mean, across all concurrent requests)
  32. 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:

 
  
  
  1. $ 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.

 
  
  
  1. $ make Prof-clean
  2. $ 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:

 
 
  1. $ ab-n10000-c 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 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/request:0.839 [MS] (mean, across all concurrent requests)
  32. 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"


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.