作者:敖士伟
索 引
一、环境
二、代码
三、测试结果
四、结果分析
说明:php调用.net WebService,解决返回消息格式问题,比如数据库查询结果。本方案将.net DataTable序列化为JSON返回给php,php使用json_decode()解码JSON数据为数组。
一、环境
1. dotNet环境
Win2003EE sp2,IIS 6.0,.NET 3.5 sp1
2.PHP环境
CentOS 6.2, Apache 2.2.21, PHP 5.3.8, APC 3.1.9,mysql 5.5.16
PHP和mysql在同一server上
3.测试工具
Apache ab.exe
二、代码
注:mysql连接都使用持久连接
1.dotNet代码
2.php代码
(1)直接查询mysql代码
(2)调用WebService代码
三、测试结果
说明:只列出结果关键参数
1.第一组测试10个并发
(1)直接查询
Requests per second: 334.20 [#/sec] (mean)
Time per request: 29.922 [ms] (mean)
Time per request: 2.992 [ms] (mean, across all concurrent requests)
Transfer rate: 133.87 [Kbytes/sec] received
(2)调用WebService
Requests per second: 184.51 [#/sec] (mean)
Time per request: 54.197 [ms] (mean)
Time per request: 5.420 [ms] (mean, across all concurrent requests)
Transfer rate: 72.39 [Kbytes/sec] received
2.第二组测试50个并发
(1)直接查询
Requests per second: 318.36 [#/sec] (mean)
Time per request: 157.053 [ms] (mean)
Time per request: 3.141 [ms] (mean, across all concurrent requests)
Transfer rate: 127.99 [Kbytes/sec] received
(2)调用WebService
Requests per second: 182.86 [#/sec] (mean)
Time per request: 273.427 [ms] (mean)
Time per request: 5.469 [ms] (mean, across all concurrent requests)
Transfer rate: 71.63 [Kbytes/sec] received
四、结果分析
直接查询比调用WebService大概快77%
(((334.20+318.36)/2)/((184.51+182.86)/2)-1)*100%
可能的原因:
1. 调用WebService增加了网络连接成本
2. 调用WebService在.net端和php都增加了对象的序列化计算成本