自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

讓你的 PHP 7 更快 (GCC PGO)

開發(fā) 后端
我們一直致力于提升PHP7的性能, 上個(gè)月我們注意到GCC的PGO能在Wordpress上能帶來(lái)近10%的性能提升, 這個(gè)讓我們很激動(dòng).

我們一直致力于提升PHP7的性能,  上個(gè)月我們注意到GCC的PGO能在Wordpress上能帶來(lái)近10%的性能提升,  這個(gè)讓我們很激動(dòng).

 讓你的 PHP 7 更快 (GCC PGO)

然而,  PGO正如名字所說(Profile Guided Optimization 有興趣的可以Google), 他需要用一些用例來(lái)獲得反饋, 也就是說這個(gè)優(yōu)化是需要和一個(gè)特定的場(chǎng)景綁定的.

你對(duì)一個(gè)場(chǎng)景的優(yōu)化, 也許在另外一個(gè)場(chǎng)景就事與愿違了.  它不是一個(gè)通用的優(yōu)化. 所以我們不能簡(jiǎn)單的就包含這些優(yōu)化, 也無(wú)法直接發(fā)布PGO編譯后的PHP7.

當(dāng)然, 我們正在嘗試從PGO找出一些共性的優(yōu)化,  然后手工Apply到PHP7上去, 但這個(gè)很明顯不能做到針對(duì)一個(gè)場(chǎng)景的特別優(yōu)化所能達(dá)到的效果,  所以我決定寫這篇文章簡(jiǎn)單介紹下怎么使用PGO來(lái)編譯PHP7, 讓你編譯的PHP7能特別的讓你自己的獨(dú)立的應(yīng)用變得更快.

首先,  要決定的就是拿什么場(chǎng)景去Feedback GCC,  我們一般都會(huì)選擇: 在你要優(yōu)化的場(chǎng)景中: 訪問量最大的, 耗時(shí)最多的, 資源消耗最重的一個(gè)頁(yè)面.

拿Wordpress為例,  我們選擇Wordpress的首頁(yè)(因?yàn)槭醉?yè)往往是訪問量最大的).

我們以我的機(jī)器為例:

 

  1. Intel(R) Xeon(R) CPU           X5687  @ 3.60GHz X 16(超線程), 
  2.  
  3. 48G Memory 

 

php-fpm 采用固定32個(gè)worker, opcache采用默認(rèn)的配置(一定要記得加載opcache)

以wordpress 4.1為優(yōu)化場(chǎng)景..

首先我們來(lái)測(cè)試下目前WP在PHP7的性能(ab -n 10000 -c 100):

 

  1. $ ab -n 10000 -c 100 http://inf-dev-maybach.weibo.com:8000/wordpress/ 
  2.  
  3. This is ApacheBench, Version 2.3 <$Revision: 655654 $> 
  4.  
  5. Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ 
  6.  
  7. Licensed to The Apache Software Foundation, http://www.apache.org/ 
  8.  
  9. Benchmarking inf-dev-maybach.weibo.com (be patient) 
  10.  
  11. Completed 1000 requests 
  12.  
  13. Completed 2000 requests 
  14.  
  15. Completed 3000 requests 
  16.  
  17. Completed 4000 requests 
  18.  
  19. Completed 5000 requests 
  20.  
  21. Completed 6000 requests 
  22.  
  23. Completed 7000 requests 
  24.  
  25. Completed 8000 requests 
  26.  
  27. Completed 9000 requests 
  28.  
  29. Completed 10000 requests 
  30.  
  31. Finished 10000 requests 
  32.  
  33. Server Software:        nginx/1.7.12 
  34.  
  35. Server Hostname:        inf-dev-maybach.weibo.com 
  36.  
  37. Server Port:            8000 
  38.  
  39. Document Path:          /wordpress/ 
  40.  
  41. Document Length:        9048 bytes 
  42.  
  43. Concurrency Level:      100 
  44.  
  45. Time taken for tests:   8.957 seconds 
  46.  
  47. Complete requests:      10000 
  48.  
  49. Failed requests:        0 
  50.  
  51. Write errors:           0 
  52.  
  53. Total transferred:      92860000 bytes 
  54.  
  55. HTML transferred:       90480000 bytes 
  56.  
  57. Requests per second:    1116.48 [#/sec] (mean) 
  58.  
  59. Time per request:       89.567 [ms] (mean) 
  60.  
  61. Time per request:       0.896 [ms] (mean, across all concurrent requests) 
  62.  
  63. Transfer rate:          10124.65 [Kbytes/sec] received 

 

可見Wordpress 4.1 目前在這個(gè)機(jī)器上, 首頁(yè)的QPS可以到1116.48. 也就是每秒鐘可以處理這么多個(gè)對(duì)首頁(yè)的請(qǐng)求,

現(xiàn)在, 讓我們開始教GCC, 讓他編譯出跑Wordpress4.1更快的PHP7來(lái),  首先要求GCC 4.0以上的版本, 不過我建議大家使用GCC-4.8以上的版本(現(xiàn)在都GCC-5.1了).

第一步, 自然是下載PHP7的源代碼了,  然后做./configure. 這些都沒什么區(qū)別

接下來(lái)就是有區(qū)別的地方了, 我們要首先第一遍編譯PHP7, 讓它生成會(huì)產(chǎn)生profile數(shù)據(jù)的可執(zhí)行文件:

 

  1. $ make prof-gen

注意, 我們用到了prof-gen參數(shù)(這個(gè)是PHP7的Makefile特有的, 不要嘗試在其他項(xiàng)目上也這么搞哈 :) )

然后, 讓我們開始訓(xùn)練GCC:

 

  1. $ sapi/cgi/php-cgi -T 100 /home/huixinchen/local/www/htdocs/wordpress/index.php >/dev/null 

也就是讓php-cgi跑100遍wordpress的首頁(yè), 從而生成一些在這個(gè)過程中的profile信息.

然后, 我們開始第二次編譯PHP7.

 

  1. $ make prof-clean 
  2. $ make prof-use && make install 

 

好的, 就這么簡(jiǎn)單,  PGO編譯完成了,  現(xiàn)在我們看看PGO編譯以后的PHP7的性能:

 

  1. $ ab -n10000 -c 100 http://inf-dev-maybach.weibo.com:8000/wordpress/ 
  2.  
  3. This is ApacheBench, Version 2.3 <$Revision: 655654 $> 
  4.  
  5. Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ 
  6.  
  7. Licensed to The Apache Software Foundation, http://www.apache.org/ 
  8.  
  9. Benchmarking inf-dev-maybach.weibo.com (be patient) 
  10.  
  11. Completed 1000 requests 
  12.  
  13. Completed 2000 requests 
  14.  
  15. Completed 3000 requests 
  16.  
  17. Completed 4000 requests 
  18.  
  19. Completed 5000 requests 
  20.  
  21. Completed 6000 requests 
  22.  
  23. Completed 7000 requests 
  24.  
  25. Completed 8000 requests 
  26.  
  27. Completed 9000 requests 
  28.  
  29. Completed 10000 requests 
  30.  
  31. Finished 10000 requests 
  32.  
  33. Server Software:        nginx/1.7.12 
  34.  
  35. Server Hostname:        inf-dev-maybach.weibo.com 
  36.  
  37. Server Port:            8000 
  38.  
  39. Document Path:          /wordpress/ 
  40.  
  41. Document Length:        9048 bytes 
  42.  
  43. Concurrency Level:      100 
  44.  
  45. Time taken for tests:   8.391 seconds 
  46.  
  47. Complete requests:      10000 
  48.  
  49. Failed requests:        0 
  50.  
  51. Write errors:           0 
  52.  
  53. Total transferred:      92860000 bytes 
  54.  
  55. HTML transferred:       90480000 bytes 
  56.  
  57. Requests per second:    1191.78 [#/sec] (mean) 
  58.  
  59. Time per request:       83.908 [ms] (mean) 
  60.  
  61. Time per request:       0.839 [ms] (mean, across all concurrent requests) 
  62.  
  63. Transfer rate:          10807.45 [Kbytes/sec] received 

 

現(xiàn)在每秒鐘可以處理1191.78個(gè)QPS了,  提升是~7%.  還不賴哈(咦, 你不是說10%么? 怎么成7%了?  呵呵, 正如我之前說過, 我們嘗試分析PGO都做了些什么優(yōu)化, 然后把一些通用的優(yōu)化手工Apply到PHP7中. 所以也就是說, 那~3%的比較通用的優(yōu)化已經(jīng)包含到了PHP7里面了, 當(dāng)然這個(gè)工作還在繼續(xù)).

于是就這么簡(jiǎn)單, 大家可以用自己的產(chǎn)品的經(jīng)典場(chǎng)景來(lái)訓(xùn)練GCC, 簡(jiǎn)單幾步, 獲得提升, 何樂而不為呢 :)

thanks

編者注:本文是 PHP 大神 —— 鳥哥 @Laruence 的作品,原文地址:http://www.laruence.com/2015/06/19/3063.html

 
責(zé)任編輯:王雪燕 來(lái)源: Laruence的博客
相關(guān)推薦

2015-06-23 15:17:57

PHPGCCPGO

2011-06-01 16:56:57

2012-09-06 09:36:17

谷歌NatiShalom數(shù)據(jù)處理

2009-06-23 18:00:11

微軟Windows 7瘦身

2009-05-08 08:49:17

微軟Windows 7操作系統(tǒng)

2024-01-08 17:09:07

Python解釋器CPython

2009-11-13 08:53:01

Windows 7BIOS優(yōu)化

2011-07-06 10:27:32

ADSL

2011-07-06 10:48:12

ADSL

2017-02-06 15:54:42

Windows 10Windows Def電腦

2022-01-06 22:31:21

Python技巧代碼

2024-10-08 10:24:41

Python編程語(yǔ)言

2012-12-27 17:43:11

應(yīng)用商店開發(fā)者

2011-07-06 10:48:42

ADSL

2012-06-15 14:02:51

火狐設(shè)置

2009-11-11 08:58:59

Windows 7系統(tǒng)加速

2015-11-16 10:33:25

網(wǎng)絡(luò)加速網(wǎng)絡(luò)優(yōu)化

2009-10-15 09:01:51

Windows 7修改BIOS系統(tǒng)加速

2023-09-13 09:44:32

GLIBC系統(tǒng)

2017-12-13 13:23:39

數(shù)據(jù)庫(kù)MySQL優(yōu)化
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)