起因是什么已经忘记了,最近听说了Ruby On Rails在与CakePHP压力测试的对比中取得了很惨烈的成绩(记得基本上两位数的每秒请求数和三位数的差别,在原文中作者称:非常佩服敢把Ruby On Rails用在生产环境的人),好奇心一下子就被勾引起来了,很想看看JSP,PHP,Node的对比结果。Node是新生事物,据说其单线程的模式在压力测试中表现非常好。

测试环境说明:

OS:  windows xp service pace 3
CPU: Intel Pentium M 2.00 GHz
Mem: 2 GB

测试条件:

ab -c 5 -n 1000 {url} 并发数5, 运行查询1000次

下面是对三种服务端语言的说明:

===========================================================

PHP测试方法与结果:

php -S 127.0.0.1:12001 开启服务器,编写简单脚本:

a.php

<?php
echo date('Y-m-d');
?>

测试结果:

Document Path: /a.php

Document Length: 880 bytes

Concurrency Level: 5

Time taken for tests: 1.797 seconds

Complete requests: 1000

Failed requests: 0

Write errors: 0

Non-2xx responses: 1000

Total transferred: 1009000 bytes

HTML transferred: 880000 bytes

Requests per second: 556.52 [#/sec] (mean)

Time per request: 8.984 [ms] (mean)

Time per request: 1.797 [ms] (mean, across all concurrent requests)

Transfer rate: 548.37 [Kbytes/sec] received

===============================================================

Java(JSP)测试方法与结果:

安装JDK7, Tomcat7, 运行tomcat server

a.jsp

<html>
<body>
Now time is: <%=new java.util.Date()%>
</body>
</html>

测试结果:

Document Path: /examples/jsp/jsp2/simpletag/hello.jsp

Document Length: 389 bytes

Concurrency Level: 5

Time taken for tests: 1.953 seconds

Complete requests: 1000

Failed requests: 0

Write errors: 0

Total transferred: 640000 bytes

HTML transferred: 389000 bytes

Requests per second: 512.00 [#/sec] (mean)

Time per request: 9.766 [ms] (mean)

Time per request: 1.953 [ms] (mean, across all concurrent requests)

Transfer rate: 320.00 [Kbytes/sec] received

===========================================================

Node测试方法与结果:

安装node,运行一下脚本:

a.js

var http=require('http');
server = http.createServer(function(req,res) {
res.writeHeader(200,{'Content-type':'text/plain'});
res.end("Hello,node");
});
server.listen(12001);
console.log("a.js start 12001");

运行: node a.js 即可打开服务器

测试结果:

Document Path: /

Document Length: 10 bytes

Concurrency Level: 5

Time taken for tests: 1.234 seconds

Complete requests: 1000

Failed requests: 0

Write errors: 0

Total transferred: 111000 bytes

HTML transferred: 10000 bytes

Requests per second: 810.13 [#/sec] (mean)

Time per request: 6.172 [ms] (mean)

Time per request: 1.234 [ms] (mean, across all concurrent requests)

Transfer rate: 87.82 [Kbytes/sec] received

====================================================================

结果是,在简易的运行环境和条件下, PHP每秒请求数为 556,JSP在Tomcat的辅助下每秒请求数为 512,Node的每秒请求数为 810

当然,机器很烂,没有任何系统和服务器优化,而且都是简单请求,并不能说明太多问题,仅供大家参考。

另外提一句: Ruby On Rails的每秒请求数大概是 40 。。。。。。

如果换用 Apache Server 或者 Nigix Server, 数值似乎有所波动。这些恳请大家补充指正,笔者的机器上没有安装太多东西。过段时间补充 Python, CGI(C语言版本) 和 ROR 的具体测试结果。