Default Avatar
Assistant Engineer
Assistant Engineer
  • UID621
  • Fans1
  • Follows0
  • Posts55
Reads:43236Replies:0

How to optimize PHP7 compiling with GCC PGO

Created#
More Posted time:Nov 14, 2016 10:18 AM
Introduction
PGO refers to Profile-guided Optimization. It is a self-adaptive optimization which means it doesn’t make improvements on the software code itself to achieve performance enhancements. Currently PGO has been applied to GCC, VC++ and other common compilers. Some open-source projects, such as Firefox, use PGO compiling by default to optimize performance. But PGO is not widely applied to most of the software.
If we use GCC PGO to compile PHP7.0 + opcache on a server of Alibaba Cloud with one core and 1G of memory, the performance of WordPress 4.6.0 will be improved by around 5% and that of the Drupal 8.1.8 will be improved by around 2%. Of course, the higher the server configuration and the better the parameter settings, the more obvious the performance improvement.
So next, let's briefly introduce how to use PGO to compile PHP7.0. I personally hold that PGO compiling is most recommended for PHP upgrading. If the website is not fully established when you compile the server environment for the first time, the training will not enjoy significant performance improvement.
Installation
Step 1, in the words of VBird, the newer the GCC compiler, the better. It is better to use GCC 4.8 or above. Although it seems GCC 4 has started to support PGO in the early stage, it never hurts to listen to the opinion of a mastermind.
Step 2, download PHP7.0 and do some configuration in ./configure. I will not repeat it here.
Step 3, we can start the first compilation of PHP.
make prof-gen
Step 4, the three binary files, namely sapi/cli/php, sapi/cgi/php-cgi and sapi/fpm/php-fpm, will be generated in the php directory for us to perform the targeted training.


Step 5, conduct the adaptive training. Run the following commands:
sapi/cgi/php-cgi -T 100 /data/www.mf8.biz/index.php >/dev/null
The targeted training will start on the /data/www.mf8.biz/index.php. In general, the most visited page of a website is the home page, so we only need to train the home page file. In an LNMP environment, you can also use sapi/fpm/php-fpm to replace sapi/cgi/php-cgi to get better feedback.
It is worth noting that the training is valid for only one website program. For example, the trained WordPress will only conduct adaptive performance optimization for WP. If the server has multiple website programs, you can use php_pgo_training_scripts to perform universal PGO optimization.
Step 6, clear the binary files generated during the first compilation and input the following command:
make prof-clean
Step 7, according to the training feedback, conduct the second compilation and installation. Input the following commands:
make prof-use
make install
Note: Some one-click packages and the liconv library are used for compiling PHP. So do not forget to reference additional libraries for make prof-gen and make prof-use.
Others
For Oneinstack users, I also made a small change to upgrade_php.sh. PHP 7.0 users can directly use this to replace the /include/upgrade_php.sh file. Then upgrade PHP and the PGO optimization will be available by default.
Remember to replace /data/wwwroot/mf8/index.php with your own program.
https://gist.github.com/ivmm/f17352d5a310385a1dda1ac553401587

Latest likes:

Default Avataryeho
Default Avatar