@H_502_0@
Hugepage
PHP7刚刚发布了RC4,包含一些bug修复和一个我们最新的性能提升成果, 那就是”HugePageFy PHP TEXT segment”, 通过启用这个特性,PHP7会把自身的TEXT段(执行体)”挪“到Huagepage上,之前的测试,我们能稳定的在wordpress上看到2%~3%的QPS提升。 @H_502_0@关于Hugepage是啥,简单的说下就是默认的内存是以4KB分页的,而虚拟地址和内存地址是需要转换的, 而这个转换是要查表的,cpu为了加速这个查表过程都会内建TLB(Translation Lookaside Buffer), 显而易见如果虚拟页越小,表里的条目数也就越多,而TLB大小是有限的,条目数越多TLB的Cache Miss也就会越高, 所以如果我们能启用大内存页就能间接降低这个TLB Cache Miss,至于详细的介绍,Google一搜一大堆我就不赘述了,这里主要说明下如何启用这个新特性, 从而带来明显的性能提升。 @H_502_0@新的Kernel启用Hugepage已经变得非常容易了,以我的开发虚拟机为例(Ubuntu Server 14.04,Kernel 3.13.0-45),如果我们查看内存信息:GCC PGO
PGO正如名字所说(Profile Guided Optimization 有兴趣的可以Google),他需要用一些用例来获得反馈,也就是说这个优化是需要和一个特定的场景绑定的. @H_502_0@你对一个场景的优化,也许在另外一个场景就事与愿违了. 它不是一个通用的优化. 所以我们不能简单的就包含这些优化,也无法直接发布PGO编译后的PHP7. @H_502_0@当然,我们正在尝试从PGO找出一些共性的优化,然后手工Apply到PHP7上去,但这个很明显不能做到针对一个场景的特别优化所能达到的效果,所以我决定写这篇文章简单介绍下怎么使用PGO来编译PHP7,让你编译的PHP7能特别的让你自己的独立的应用变得更快. @H_502_0@首先,要决定的就是拿什么场景去Feedback GCC,我们一般都会选择: 在你要优化的场景中: 访问量最大的,耗时最多的,资源消耗最重的一个页面. @H_502_0@拿wordpress为例,我们选择wordpress的首页(因为首页往往是访问量最大的). @H_502_0@我们以我的机器为例: @H_502_0@ Intel(R) Xeon(R) cpu X5687 @ 3.60GHz X 16(超线程), 48G Memory PHP-fpm 采用固定32个worker,opcache采用默认的配置(一定要记得加载opcache) @H_502_0@以wordpress 4.1为优化场景.. @H_502_0@首先我们来测试下目前WP在PHP7的性能(ab -n 10000 -c 100):Benchmarking inf-dev-maybach.weibo.com (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests
Server Software: Nginx/1.7.12
Server Hostname: inf-dev-maybach.weibo.com
Server Port: 8000
Document Path: /wordpress/
Document Length: 9048 bytes
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
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests
Server Software: Nginx/1.7.12
Server Hostname: inf-dev-maybach.weibo.com
Server Port: 8000
Document Path: /wordpress/
Document Length: 9048 bytes
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