测试目的

在一个典型的PHP服务器环境下运行一个典型的Zend Framework,并分段逐步分析性能消耗情况

测试环境:

Apache/2.0.55 (Win32) mod_fastcgi/2.4.2
PHP Version 5.2.5 (无Zend Optimizer等加速模块)
Windows 2003 NT 5.2 build 3790
Cpu: intel Xeon 3.0G
内存: 1G

主要测试伪代码


step 1: set_include_path()
step 2:
require Zend_Loder
step 3: registerAutoload
step 4: load config & create db adapter
step 5:
init zend layout
step 6:
init zend auth
step 7:
init Zend front controller & Dispath
?>

测试方法和主要测试指标

1、PHP Core Time(PCT):服务器端使用 vsprintf(‘%d.%06d’, gettimeofday()) 进行微秒级的计时,并输出总的PHP代码运行时间。
2、客户端使用 Webserver Stress Tool 进行客户端的压力测试和访问记时,主要评估两个指标:
Average Time to First Byte (TFB):首字节的接收时间
Average Click Time (CT):模拟点击完成时间,既页面从点击请求开始到下载完成的时间
3、
Webserver Stress Tool测试模拟两种情况
低负载:单用户,间隔2秒点击一次页面
高负载:30个用户,每人间隔2秒点击一次页面,相当于每秒动态页面访问
(DPV)5-10次

测试综合结果




PCT
低负载
高负载

TFB
CT
TFB
CT
执行代码(增量)
Step 1
0.05
89
1054
168
246
set_include_path()
Step 2
1.9
133
847
148
211
require Zend_Loder
Step 3
2.7
144
1010
229
299
registerAutoload
Step 4
70
166
842
249
337
load config & create db adapter
Step 5
150
229
1053
1544
1692
init zend layout
Step 6
150
254
741
2430
2552
init zend auth
Step 7
300
382
1053
5054
5404
init Zend front controller & Dispath
单位:ms

测试结果综合分析

1、ZF的典型环境初始化的基本消耗还是比较大的,测试代码的最终结果仅仅是使用的ZF标准MVC架构输出了一个Hello,我们可以看到,它的PCT到了300ms,在高负载测试中,更是使TFB达到了5000ms。我个人认为可以接受的框架初始消耗的PCT应该在150ms以下,所以对高负载WEB应用使用ZF必须非常慎重。
2、对比低负载测试和高负载测试我们可以发现,TFB会因为负载的提高而明显增加,而随着代码复杂程度的提高,差距越来越大,最高到了382:5054
3、对比低负载测试和高负载测试我们可以发现,在简单代码情况下,“低负载”的CT结果反而会高于“高负载”的结果,我推测这应该是由于Apache或者FastCGI的缓存机制造成;随着代码复杂程度的提高,高负载时服务器的的TFB明显提高,这一现象也被冲淡了。
4、TFB是衡量网页对客户端响应速度的重要指标,我们可以发现,低负载测试结果中的TFB基本都等于相应的PCT + 80ms,这多出来的80ms应该就是Aapche+php的页面环境初始化所消耗的是时间,而这一时间是发生在PHP以外的,所以PHP自身是无法计时和统计到这一时间的。

测试详细结果记录



步骤一:
CODE:


set_include_path(‘app’ . PATH_SEPARATOR
. ‘libs’ . PATH_SEPARATOR
. get_include_path());


PHP Core Time:
~0.055 ms
WT1:30U × 4C D2 (30用户,点击4次,间隔2秒)

2008-6-18 18:47:02: Measured Times:
2008-6-18 18:47:02: Average Time to Create Local Socket for 30 Users: 2 ms
2008-6-18 18:47:02: Average DNS Time for 30 Users: 71 ms
2008-6-18 18:47:02: Average Time to Connect for 30 Users: 101 ms
2008-6-18 18:47:02: Average Time to First Byte for 30 Users: 168 ms
2008-6-18 18:47:02: Average Click Time for 30 Users: 246 ms
2008-6-18 18:47:02:
2008-6-18 18:47:02: Hits per Second: 13.09 (equals 47,127.99 Hits per Hour)
2008-6-18 18:47:02: Successful clicks per Second: 13.09 (equals 47,127.99 Clicks per Hour)
2008-6-18 18:47:02:
2008-6-18 18:47:02: Results per URL for this Period:
2008-6-18 18:47:02: URL#1 (Test): Average Click Time 246 ms, 134 Clicks, 0 Errors,
2008-6-18 18:47:02: Average Click Time of all URLs: 246 ms


WT2:1U × 10C D2

2008-6-18 18:50:15: Measured Times:
2008-6-18 18:50:15: Average Time to Create Local Socket for 1 Users: 1 ms
2008-6-18 18:50:15: Average DNS Time for 1 Users: 48 ms
2008-6-18 18:50:15: Average Time to Connect for 1 Users: 49 ms
2008-6-18 18:50:15: Average Time to First Byte for 1 Users: 89 ms
2008-6-18 18:50:15: Average Click Time for 1 Users: 1,054 ms
2008-6-18 18:50:15:
2008-6-18 18:50:15: Hits per Second: 0.30 (equals 1,064.36 Hits per Hour)
2008-6-18 18:50:15: Successful clicks per Second: 0.30 (equals 1,064.36 Clicks per Hour)
2008-6-18 18:50:15:
2008-6-18 18:50:15: Results per URL for this Period:
2008-6-18 18:50:15: URL#1 (Test): Average Click Time 1,054 ms, 3 Clicks, 0 Errors,
2008-6-18 18:50:15: Average Click Time of all URLs: 1,054 ms




步骤二:
CODE:


+ require_once “Zend/Loader.php”;

PHP Core Time:

~1.9ms

WT1:30U × 4C D2 (30用户,点击4次,间隔2秒)

2008-6-18 19:11:40: Average Time to Create Local Socket for 30 Users: 1 ms
2008-6-18 19:11:40: Average DNS Time for 30 Users: 68 ms
2008-6-18 19:11:40: Average Time to Connect for 30 Users: 75 ms
2008-6-18 19:11:40: Average Time to First Byte for 30 Users: 148 ms
2008-6-18 19:11:40: Average Click Time for 30 Users: 211 ms
2008-6-18 19:11:40:
2008-6-18 19:11:40: Hits per Second: 13.02 (equals 46,863.23 Hits per Hour)
2008-6-18 19:11:40: Successful clicks per Second: 13.02 (equals 46,863.23 Clicks per Hour)
2008-6-18 19:11:40:
2008-6-18 19:11:40: Results per URL for this Period:
2008-6-18 19:11:40: URL#1 (Test): Average Click Time 211 ms, 133 Clicks, 0 Errors,

WT2:1U × 10C D2

2008-6-19 9:39:48: Average Time to Create Local Socket for 1 Users: 1 ms
2008-6-19 9:39:48: Average DNS Time for 1 Users: 50 ms
2008-6-19 9:39:48: Average Time to Connect for 1 Users: 52 ms
2008-6-19 9:39:48: Average Time to First Byte for 1 Users: 133 ms
2008-6-19 9:39:48: Average Click Time for 1 Users: 847 ms
2008-6-19 9:39:48:
2008-6-19 9:39:48: Hits per Second: 0.29 (equals 1,054.84 Hits per Hour)
2008-6-19 9:39:48: Successful clicks per Second: 0.29 (equals 1,054.84 Clicks per Hour)
2008-6-19 9:39:48:
2008-6-19 9:39:48: Results per URL for this Period:
2008-6-19 9:39:48: URL#1 (Test): Average Click Time 847 ms, 3 Clicks, 0 Errors,






步骤三:
CODE:


+ Zend_Loader::registerAutoload();


PHP Core Time:
~2.7ms
WT1:30U × 4C D2 (30用户,点击4次,间隔2秒)

2008-6-19 9:50:03: Average Time to Create Local Socket for 30 Users: 1 ms
2008-6-19 9:50:03: Average DNS Time for 30 Users: 85 ms
2008-6-19 9:50:03: Average Time to Connect for 30 Users: 90 ms
2008-6-19 9:50:03: Average Time to First Byte for 30 Users: 229 ms
2008-6-19 9:50:03: Average Click Time for 30 Users: 299 ms
2008-6-19 9:50:03:
2008-6-19 9:50:03: Hits per Second: 12.71 (equals 45,772.06 Hits per Hour)
2008-6-19 9:50:03: Successful clicks per Second: 12.71 (equals 45,772.06 Clicks per Hour)
2008-6-19 9:50:03:
2008-6-19 9:50:03: Results per URL for this Period:
2008-6-19 9:50:03: URL#1 (Test): Average Click Time 299 ms, 129 Clicks, 0 Errors,

WT2:1U × 10C D2

2008-6-19 9:51:56: Average Time to Create Local Socket for 1 Users: 1 ms
2008-6-19 9:51:56: Average DNS Time for 1 Users: 53 ms
2008-6-19 9:51:56: Average Time to Connect for 1 Users: 55 ms
2008-6-19 9:51:56: Average Time to First Byte for 1 Users: 144 ms
2008-6-19 9:51:56: Average Click Time for 1 Users: 1,010 ms
2008-6-19 9:51:56:
2008-6-19 9:51:56: Hits per Second: 0.30 (equals 1,062.37 Hits per Hour)
2008-6-19 9:51:56: Successful clicks per Second: 0.30 (equals 1,062.37 Clicks per Hour)
2008-6-19 9:51:56:
2008-6-19 9:51:56: Results per URL for this Period:
2008-6-19 9:51:56: URL#1 (Test): Average Click Time 1,010 ms, 3 Clicks, 0 Errors,




步骤
CODE:


+ init Zend DB

PHP Core Time:
~70ms
WT1:30U × 4C D2

2008-6-19 10:33:46: Average Time to Create Local Socket for 30 Users: 2 ms
2008-6-19 10:33:46: Average DNS Time for 30 Users: 82 ms
2008-6-19 10:33:46: Average Time to Connect for 30 Users: 84 ms
2008-6-19 10:33:46: Average Time to First Byte for 30 Users: 249 ms
2008-6-19 10:33:46: Average Click Time for 30 Users: 337 ms
2008-6-19 10:33:46:
2008-6-19 10:33:46: Hits per Second: 12.39 (equals 44,614.31 Hits per Hour)
2008-6-19 10:33:46: Successful clicks per Second: 12.39 (equals 44,614.31 Clicks per Hour)
2008-6-19 10:33:46:
2008-6-19 10:33:46: Results per URL for this Period:
2008-6-19 10:33:46: URL#1 (Test): Average Click Time 337 ms, 124 Clicks, 0 Errors,

WT2:1U × 10C D2
2008-6-19 10:35:26: Average Time to Create Local Socket for 1 Users: 1 ms

2008-6-19 10:35:26: Average DNS Time for 1 Users: 46 ms
2008-6-19 10:35:26: Average Time to Connect for 1 Users: 48 ms
2008-6-19 10:35:26: Average Time to First Byte for 1 Users: 166 ms
2008-6-19 10:35:26: Average Click Time for 1 Users: 842 ms
2008-6-19 10:35:26:
2008-6-19 10:35:26: Hits per Second: 0.40 (equals 1,421.12 Hits per Hour)
2008-6-19 10:35:26: Successful clicks per Second: 0.40 (equals 1,421.12 Clicks per Hour)
2008-6-19 10:35:26:
2008-6-19 10:35:26: Results per URL for this Period:
2008-6-19 10:35:26: URL#1 (Test): Average Click Time 842 ms, 4 Clicks, 0 Errors,



步骤
CODE:


+ init Zend Layout


PHP Core Time:
~150ms
WT1:30U × 4C D2

2008-6-19 10:41:18: Average Time to Create Local Socket for 30 Users: 1 ms
2008-6-19 10:41:18: Average DNS Time for 30 Users: 90 ms
2008-6-19 10:41:18: Average Time to Connect for 30 Users: 93 ms
2008-6-19 10:41:18: Average Time to First Byte for 30 Users: 1,544 ms
2008-6-19 10:41:18: Average Click Time for 30 Users: 1,692 ms
2008-6-19 10:41:18:
2008-6-19 10:41:18: Hits per Second: 7.76 (equals 27,927.16 Hits per Hour)
2008-6-19 10:41:18: Successful clicks per Second: 7.76 (equals 27,927.16 Clicks per Hour)
2008-6-19 10:41:18:
2008-6-19 10:41:18: Results per URL for this Period:
2008-6-19 10:41:18: URL#1 (Test): Average Click Time 1,692 ms, 80 Clicks, 0 Errors,

WT2:1U × 10C D2
2008-6-19 10:42:48: Average Time to Create Local Socket for 1 Users: 1 ms

2008-6-19 10:42:48: Average DNS Time for 1 Users: 46 ms
2008-6-19 10:42:48: Average Time to Connect for 1 Users: 47 ms
2008-6-19 10:42:48: Average Time to First Byte for 1 Users: 229 ms
2008-6-19 10:42:48: Average Click Time for 1 Users: 1,053 ms
2008-6-19 10:42:48:
2008-6-19 10:42:48: Hits per Second: 0.40 (equals 1,424.74 Hits per Hour)
2008-6-19 10:42:48: Successful clicks per Second: 0.40 (equals 1,424.74 Clicks per Hour)
2008-6-19 10:42:48:
2008-6-19 10:42:48: Results per URL for this Period:
2008-6-19 10:42:48: URL#1 (Test): Average Click Time 1,053 ms, 4 Clicks, 0 Errors,


步骤
CODE:


+ init Zend View
+ init Zend User


PHP Core Time:
~150ms
WT1:30U × 4C D2

2008-6-19 11:27:59: Average Time to Create Local Socket for 30 Users: 1 ms
2008-6-19 11:27:59: Average DNS Time for 30 Users: 77 ms
2008-6-19 11:27:59: Average Time to Connect for 30 Users: 85 ms
2008-6-19 11:27:59: Average Time to First Byte for 30 Users: 2,430 ms
2008-6-19 11:27:59: Average Click Time for 30 Users: 2,552 ms
2008-6-19 11:27:59:
2008-6-19 11:27:59: Hits per Second: 6.33 (equals 22,786.27 Hits per Hour)
2008-6-19 11:27:59: Successful clicks per Second: 6.33 (equals 22,786.27 Clicks per Hour)
2008-6-19 11:27:59:
2008-6-19 11:27:59: Results per URL for this Period:
2008-6-19 11:27:59: URL#1 (Test): Average Click Time 2,552 ms, 65 Clicks, 0 Errors,

WT2:1U × 10C D2

2008-6-19 11:24:37: Average Time to Create Local Socket for 1 Users: 1 ms
2008-6-19 11:24:37: Average DNS Time for 1 Users: 46 ms
2008-6-19 11:24:37: Average Time to Connect for 1 Users: 47 ms
2008-6-19 11:24:37: Average Time to First Byte for 1 Users: 254 ms
2008-6-19 11:24:37: Average Click Time for 1 Users: 741 ms
2008-6-19 11:24:37:
2008-6-19 11:24:37: Hits per Second: 0.39 (equals 1,411.08 Hits per Hour)
2008-6-19 11:24:37: Successful clicks per Second: 0.39 (equals 1,411.08 Clicks per Hour)
2008-6-19 11:24:37:
2008-6-19 11:24:37: Results per URL for this Period:
2008-6-19 11:24:37: URL#1 (Test): Average Click Time 741 ms, 4 Clicks, 0 Errors,



步骤(完成):
CODE:


+ init Zend_Controller_Front
+ dispatch & run

PHP Core Time:
~300ms
WT1:30U × 4C D2

2008-6-19 11:33:51: Average Time to Create Local Socket for 30 Users: 2 ms
2008-6-19 11:33:51: Average DNS Time for 30 Users: 101 ms
2008-6-19 11:33:51: Average Time to Connect for 30 Users: 114 ms
2008-6-19 11:33:51: Average Time to First Byte for 30 Users: 5,054 ms
2008-6-19 11:33:51: Average Click Time for 30 Users: 5,404 ms
2008-6-19 11:33:51:
2008-6-19 11:33:51: Hits per Second: 4.14 (equals 14,890.34 Hits per Hour)
2008-6-19 11:33:51: Successful clicks per Second: 4.14 (equals 14,890.34 Clicks per Hour)
2008-6-19 11:33:51:
2008-6-19 11:33:51: Results per URL for this Period:
2008-6-19 11:33:51: URL#1 (Test): Average Click Time 5,404 ms, 43 Clicks, 0 Errors,

WT2:1U × 10C D2

2008-6-19 11:35:03: Average Time to Create Local Socket for 1 Users: 1 ms
2008-6-19 11:35:03: Average DNS Time for 1 Users: 47 ms
2008-6-19 11:35:03: Average Time to Connect for 1 Users: 48 ms
2008-6-19 11:35:03: Average Time to First Byte for 1 Users: 382 ms
2008-6-19 11:35:03: Average Click Time for 1 Users: 1,053 ms
2008-6-19 11:35:03:
2008-6-19 11:35:03: Hits per Second: 0.40 (equals 1,424.61 Hits per Hour)
2008-6-19 11:35:03: Successful clicks per Second: 0.40 (equals 1,424.61 Clicks per Hour)
2008-6-19 11:35:03:
2008-6-19 11:35:03: Results per URL for this Period:
2008-6-19 11:35:03: URL#1 (Test): Average Click Time 1,053 ms, 4 Clicks, 0 Errors,

(161)


7 条评论

丕子 · 2010/06/17 9:05 上午

哇哦 看到了最详细的测试

会跳舞的鞋子 · 2011/01/23 6:58 下午

额 没想到ZF这么消耗性能
犹豫…

如何祛痘痕 · 2011/03/14 7:43 下午

有点复杂!

关于PHP开发框架Zend Framework的执行效率 | 丕子 · 2010/06/17 9:09 上午

[…] 3、Emeric.Li 做的测试更加详细,摘要一下: 1、ZF的典型环境初始化的基本消耗还是比较大的,测试代码的最终结果仅仅是使用的ZF标准MVC架构输出了一个Hello,我们可以看到,它的PCT到 了300ms,在高负载测试中,更是使TFB达到了5000ms。我个人认为可以接受的框架初始消耗的PCT应该在150ms以下,所以对高负载WEB应 用使用ZF必须非常慎重。 2、对比低负载测试和高负载测试我们可以发现,TFB会因为负载的提高而明显增加,而随着代码复杂程度的提高,差距越来越大,最高到了382:5054 3、对比低负载测试和高负载测试我们可以发现,在简单代码情况下,“低负载”的CT结果反而会高于“高负载”的结果,我推测这应该是由于Apache或者 FastCGI的缓存机制造成;随着代码复杂程度的提高,高负载时服务器的的TFB明显提高,这一现象也被冲淡了。 4、TFB是衡量网页对客户端响应速度的重要指标,我们可以发现,低负载测试结果中的TFB基本都等于相应的PCT + 80ms,这多出来的80ms应该就是Aapche+php的页面环境初始化所消耗的是时间,而这一时间是发生在PHP以外的,所以PHP自身是无法计时 和统计到这一时间的。 | 更多 分类: 技术 标签: MVC, php, Zend Framework, 效率 相关文章[请教] 最近想用PHP开发个中型站点,请推荐些技术吧 (13)PHP的ip2long有bug (0)谈谈PHP,ASP,JSP,Python的速度,关于WEB应用 (0)WordPress 的彩色标签云 (0)WordPress摘要的使用 (2)最新版php_memcache.dll下载地址 (0) 评论 (0) Trackbacks (0) 发表评论 Trackback […]

小人物 » [转]技术站点 · 2011/05/25 11:04 上午

[…] 简单生活@NET » Zend Framework 框架典型初始化过程的效率测试与分析 […]

收藏的技术站点 – 轻松麻酱面 · 2011/07/29 2:06 下午

[…] 简单生活@NET » Zend Framework 框架典型初始化过程的效率测试与分析 […]

岭南六少 – 一朵在LAMP架构下挣扎的云 » 我收藏的技术站点 · 2011/09/28 11:56 下午

[…] 简单生活@NET » Zend Framework 框架典型初始化过程的效率测试与分析 […]

发表评论

电子邮件地址不会被公开。