惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

云风的 BLOG
云风的 BLOG
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
IT之家
IT之家
Recent Announcements
Recent Announcements
B
Blog
D
Docker
V
V2EX
GbyAI
GbyAI
L
LangChain Blog
博客园 - Franky
U
Unit 42
T
The Blog of Author Tim Ferriss
A
About on SuperTechFans
博客园 - 【当耐特】
Google DeepMind News
Google DeepMind News
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Vercel News
Vercel News
博客园_首页
D
DataBreaches.Net
人人都是产品经理
人人都是产品经理
Y
Y Combinator Blog
量子位
Blog — PlanetScale
Blog — PlanetScale
罗磊的独立博客

风雪之隅

Yac 2.4.0发布 - 小值读取性能提升64% 用Yac给WordPress做缓存:比Memcached快19% Laruence Laruence Laruence Laruence Laruence 深入理解PHP7内核之OBJECT - 风雪之隅 PHP 8新特性之Attributes(注解) - 风雪之隅 博客迁移到腾讯云 - 风雪之隅 在Qcon 2015 北京上的演讲PPT - PHP7 Yar-2.1 新功能介绍 - 风雪之隅 Yaf and Phalcon, which is faster? HTTPOXY漏洞说明 - 风雪之隅 一个关于Zend O+的小分享 - 风雪之隅 在PHP中使用协程实现多任务调度 - 风雪之隅 Curl的毫秒超时的一个"Bug" - 风雪之隅 PHP8.0的Named Parameter - 风雪之隅 关于PHP,关于Realsee - 风雪之隅 PHP8新特性之match表达式 - 风雪之隅 PHP 8新特性之JIT简介 - 风雪之隅 使用SSE2指令高效实现strtolower - 风雪之隅 使用OSC52实现iTerm2远程pbcopy - 风雪之隅 Yaf 3.2 发布 - 风雪之隅 使用PHP Socket开发Yar TCP服务 - 风雪之隅 Yac 2.1 升级说明 - 风雪之隅 Yaconf-1.1 40%速度提升版 - 风雪之隅 PHP FFI详解 - 一种全新的PHP扩展方式 - 风雪之隅 使用SSE2指令集加速字符替换 - 风雪之隅 Yaf_Loader重构测试 - 风雪之隅
Yaf-3.1 10%性能提升版 - 风雪之隅
laruence · 2020-03-15 · via 风雪之隅

Yaf(Yet Another Framework)是我的第一个发布的PECL扩展,也是我走上PHP内核维护的开始,我一直对它比较有感情,Yaf在过去的8年多时间里,也得到了不少朋友的喜爱,当然Yaf还是有很多不足,但毕竟Yaf主要还是针对性能场景,不能满足所有的需求。

即然Yaf == 性能,借着疫情的在家时间,又花了一些时间对Yaf做了一轮优化,希望能对性能有进一步的提升。

主要涉及到的有:

1. 重构了Yaf_Loader::autoload
2. 重写了Yaf_Route_Static/Rewrite的核心逻辑
3. is_localnamespace采用Hash匹配来取代之前的字符串匹配
4. 重写了大部分的逻辑以避免内存分配

因为改动比较大,所以也跳跃了版本,从3.0.9到3.1.0. 下载地址: Yaf At PECL

那么,还是老规矩,我们来测试下性能变化,首先采用yaf代码中的tools/cg/yaf_cg来生成一个测试:

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提升。

当然了,这点提升对于一个实际项目来说,可能并不明显,我只是在这里说明下版本升级对比:)

另外毕竟这次改动变动的代码比较大, 虽然说已经尽力测试, 但可能还是会有问题, 如果大家在实际使用的时候遇到任何问题, 可以在Github上提Issue,或者直接发邮件给我laruence at php dot net, 注意邮件不要带附件,php的mail系统过滤有附件的邮件:< Enjoy!