少废话,上代码。nodejs 代码如下:
var http = require("http");
var server = http.createServer(function(request, response) {
response.writeHead(200, {
"Content-Type": "text/html"
});
response.write("Hello World!");
response.end();
});
server.listen(8000);
测试结果:
lion$ wrk -t12 -c400 -d30s http://127.0.0.1:8000/
Running 30s test @ http://127.0.0.1:8000/
12 threads and 400 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 38.61ms 6.18ms 77.46ms 84.50 %
Req/Sec 837.87 134.82 1.77k 81.78 %
297965 requests in 30.00s, 44.05MB read
Socket errors: connect 0, read 453, write 0, timeout 90
Requests/sec: 9931.42
Transfer/sec: 1.47MB
fibjs 相似代码如下:
var http = require("http");
var svr = new http.Server(8080, function(req) {
var rep = req.response;
rep.addHeader({
"Content-Type": "text/html"
});
rep.body.write(new Buffer("Hello World!"));
});
svr.run();
测试结果如下:
lion$ wrk -t12 -c400 -d30s http://127.0.0.1:8080/
\Running 30s test @ http://127.0.0.1:8080/
12 threads and 400 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 16.73ms 31.61ms 162.45ms 94.93 %
Req/Sec 3.25k 822.21 5.28k 89.45 %
1137450 requests in 30.00s, 160.54MB read
Socket errors: connect 0, read 282, write 0, timeout 0
Requests/sec: 37916.03
Transfer/sec: 5.35MB
可是有些代码对 fibjs 纯属多余,精简一下:
var http = require("http");
var svr = new http.Server(8080, function(req) {
req.response.body.write(new Buffer("Hello World!"));
});
svr.run();
测试结果如下:
lion$ wrk -t12 -c400 -d30s http://127.0.0.1:8080/
Running 30s test @ http://127.0.0.1:8080/
12 threads and 400 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 24.39ms 71.85ms 343.96ms 95.11 %
Req/Sec 3.99k 1.00k 6.67k 91.61 %
1379337 requests in 30.00s, 161.80MB read
Socket errors: connect 0, read 270, write 0, timeout 0
Requests/sec: 45980.00
Transfer/sec: 5.39MB