Concurrency Level: 100
Time taken for tests: 8.957 seconds
Complete requests: 10000
Failed requests: 0
Write errors: 0
Total transferred: 92860000 bytes
HTML transferred: 90480000 bytes
Requests per second: 1116.48 [#/sec] (mean)
Time per request: 89.567 [ms] (mean)
Time per request: 0.896 [ms] (mean, across all concurrent requests)
Transfer rate: 10124.65 [Kbytes/sec] received
可见Wordpress 4.1 目前在这个机器上, 首页的QPS可以到1116.48. 也就是每秒钟可以处理这么多个对首页的请求,
现在, 让我们开始教GCC, 让他编译出跑Wordpress4.1更快的PHP7来, 首先要求GCC 4.0以上的版本, 不过我建议大家使用GCC-4.8以上的版本(现在都GCC-5.1了).
第一步, 自然是下载PHP7的源代码了, 然后做./configure. 这些都没什么区别
接下来就是有区别的地方了, 我们要首先第一遍编译PHP7, 让它生成会产生profile数据的可执行文件:
$ make prof-gen
注意, 我们用到了prof-gen参数(这个是PHP7的Makefile特有的, 不要尝试在其他项目上也这么搞哈 )
然后, 让我们开始训练GCC:
$ sapi/cgi/php-cgi -T 100 /home/huixinchen/local/www/htdocs/wordpress/index.php >/dev/null
也就是让php-cgi跑100遍wordpress的首页, 从而生成一些在这个过程中的profile信息.
然后, 我们开始第二次编译PHP7.
$ make prof-clean
$ make prof-use && make install
好的, 就这么简单, PGO编译完成了, 现在我们看看PGO编译以后的PHP7的性能:
$ ab -n10000 -c 100 http://inf-dev-maybach.weibo.com:8000/wordpress/
This is ApacheBench, Version 2.3
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Concurrency Level: 100
Time taken for tests: 8.391 seconds
Complete requests: 10000
Failed requests: 0
Write errors: 0
Total transferred: 92860000 bytes
HTML transferred: 90480000 bytes
Requests per second: 1191.78 [#/sec] (mean)
Time per request: 83.908 [ms] (mean)
Time per request: 0.839 [ms] (mean, across all concurrent requests)
Transfer rate: 10807.45 [Kbytes/sec] received
现在每秒钟可以处理1191.78个QPS了, 提升是~7%. 还不赖哈(咦, 你不是说10%么? 怎么成7%了? 呵呵, 正如我之前说过, 我们尝试分析PGO都做了些什么优化, 然后把一些通用的优化手工Apply到PHP7中. 所以也就是说, 那~3%的比较通用的优化已经包含到了PHP7里面了, 当然这个工作还在继续).
于是就这么简单, 大家可以用自己的产品的经典场景来训练GCC, 简单几步, 获得提升, 何乐而不为呢