现在的位置: 首页 > 综合 > 正文

php页面生成耗时分析

2017年12月27日 ⁄ 综合 ⁄ 共 942字 ⁄ 字号 评论关闭

socket读写

使用 smarty 解析 space 的 blog 页模板,php 与 spuser 和 blogapp 通过 socket 各交互一次,spuser 和 blogapp 为虚拟的桩模块,接到请求立即返回。

从 socket_connect 到 socket_close 直接的一次 socket 交互的时间,包括写140(164)字节的请求,读取shead,unpack shead,读取返回数据,shead+返回数据共956(8707)字节。

耗时为 100 次 wget 页面返回结果的平均值。

交互耗时(s):

talk_with_spuser 0.0002652
talk_with_blogapp 0.0002777

桩模块耗时(s):

gserv_spuser 0.000352
gserv_blogapp 0.000252

注: 此处装模块的耗时统计包括了一些返回数据后的其它处理(select、close什么的),所以大于了 php 的耗时统计。

另外,后来查这个问题的时候发现,php 的 Benchmark类的精度不好,统计 talk_with_spuser 的耗时时,在紧挨 $timer->setMarker 的外面加了gettimeofday,统计出来的时间就差了近 50us

总的来说,可以认为 php 的socket 交互耗时很小,基本可以忽略。

unpack耗时

spuser(956 bytes) 0.000242
blogapp(8707 bytes)  0.0004318

这里 spuser 的数据只用了一次unpack,而 blogapp 的数据用了 1 + 1 * 5 + 1 * 15 = 21 次unpack

smarty耗时

smarty 无 cache 时:

smarty 0.0350042
Total 0.036453

smarty 有 cache (compile cache) 时:

smarty 0.0018135
Total 0.0032881

Total 为整个页面的生成时间,包括了 socket 交互、unpack 二进制数据和 smarty 的时间

php socket 与 c socket 读写

分别使用 php 和 c 程序循环向 echo 服务器发包和读包,统计平均耗时

第一列代表包的大小和循环次数

  php C
8192 * 50000 26s 26s
8192 * 500000  4m26s 4m20s
1024 * 100000  40s 39s

抱歉!评论已关闭.