https://www.laruence.com/2020/03/15/5563.htmlphp
- 本文地址: https://www.laruence.com/2020/03/15/5563.html
- 轉載請註明出處
Yaf(Yet Another Framework)是個人第一個發佈的PECL擴展,也是我走上PHP內核維護的開始,我一直對它比較有感情,Yaf在過去的8年多時間裏,也獲得了很多朋友的喜好,固然Yaf仍是有不少不足,但畢竟Yaf主要仍是針對性能場景,不能知足全部的需求。
html
即然Yaf == 性能,藉着疫情的在家時間,又花了一些時間對Yaf作了一輪優化,但願能對性能有進一步的提高。nginx
主要涉及到的有:git
1. 重構了Yaf_Loader::autoload 2. 重寫了Yaf_Route_Static/Rewrite的核心邏輯 3. is_localnamespace採用Hash匹配來取代以前的字符串匹配 4. 重寫了大部分的邏輯以免內存分配
由於改動比較大,因此也跳躍了版本,從3.0.9到3.1.0. 下載地址: Yaf At PECLgithub
那麼,仍是老規矩,咱們來測試下性能變化,首先採用yaf代碼中的tools/cg/yaf_cg來生成一個測試:bash
tools/cg/yaf_cg benchmark /var/www/html/yaf
測試服務器配置:服務器
32GB RAM Intel(R) Xeon(R) CPU E5-2620 v2 @ 2.10GHz * 24 Nginx 12 processes PHP-FPM 24 processes
咱們首先用yaf-3.0.9版原本測試(200併發):併發
ab -n 100000 -c 200 http://10.33.1.23:8000/yaf/ Server Software: nginx/1.9.7 Server Hostname: 10.33.1.23 Server Port: 8000 Document Path: /yaf/ Document Length: 26 bytes Concurrency Level: 200 Time taken for tests: 17.950 seconds Complete requests: 100000 Failed requests: 0 Write errors: 0 Total transferred: 19100000 bytes HTML transferred: 2600000 bytes Requests per second: 5571.17 [#/sec] (mean) Time per request: 35.899 [ms] (mean) Time per request: 0.179 [ms] (mean, across all concurrent requests) Transfer rate: 1039.15 [Kbytes/sec] received
而後咱們用yaf-3.1.0來測試(200併發):框架
ab -n 100000 -c 200 http://10.33.1.23:8000/yaf/ Server Software: nginx/1.9.7 Server Hostname: 10.33.1.23 Server Port: 8000 Document Path: /yaf/ Document Length: 26 bytes Concurrency Level: 200 Time taken for tests: 16.046 seconds Complete requests: 100000 Failed requests: 0 Write errors: 0 Total transferred: 19100000 bytes HTML transferred: 2600000 bytes Requests per second: 6232.05 [#/sec] (mean) Time per request: 32.092 [ms] (mean) Time per request: 0.160 [ms] (mean, across all concurrent requests) Transfer rate: 1162.42 [Kbytes/sec] received
能夠看到,QPS從5571飆升到了6232, 11%的QPS提高。post
固然了,這點提高對於一個實際項目來講,可能並不明顯,我只是在這裏說明下版本升級對比:)
另外畢竟此次改動變更的代碼比較大, 雖說已經盡力測試, 但可能仍是會有問題, 若是你們在實際使用的時候遇到任何問題, 能夠在Github上提Issue,或者直接發郵件給我laruence at php dot net, 注意郵件不要帶附件,php的mail系統過濾有附件的郵件:< Enjoy!