avatar
@bangbang93

fibjs vs nodejs(4)

10/27/2014, 11:13:22 PM

突然想到Node.JS中有种很常用的优化方法,是利用异步的特性不管执行是否成功,先返回HTTP响应,于是按照这种方法我又改了一下代码

var http = require('http');
var mongodb = require('mongodb').MongoClient;
mongodb.connect('mongodb://localhost/fibvsnode?maxPoolSize=500', function (err, db) {
    if (err) {
        throw err;
    }
    var connection = db.collection('node');
    http.createServer(function (req, res) {
        connection.insert({
            time: new Date()
        },function (err){
            
        });
        //真正测试node性能,不管插入结果直接返回
        res.end(JSON.stringify({
            success: true
        }))
    }).listen(12345, '0.0.0.0');
});

fibjs我想了想好像没法实现这种写法,不过我也才接触两天而已,于是只跑了node的测试

[bangbang93@10-4-14-175 ~]$ ab -n 100000 -c 500 -k http://server.bangbang93.com:12345/
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking server.bangbang93.com (be patient)
apr_socket_recv: Connection reset by peer (104)
[bangbang93@10-4-14-175 ~]$ ab -n 100000 -c 500 -k http://server.bangbang93.com:12345/
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking server.bangbang93.com (be patient)
Completed 10000 requests
Completed 20000 requests
Completed 30000 requests
Completed 40000 requests
Completed 50000 requests
Completed 60000 requests
Completed 70000 requests
Completed 80000 requests
Completed 90000 requests
Completed 100000 requests
Finished 100000 requests


Server Software:        
Server Hostname:        server.bangbang93.com
Server Port:            12345

Document Path:          /
Document Length:        16 bytes

Concurrency Level:      500
Time taken for tests:   78.544 seconds
Complete requests:      100000
Failed requests:        0
Write errors:           0
Keep-Alive requests:    0
Total transferred:      9100000 bytes
HTML transferred:       1600000 bytes
Requests per second:    1273.17 [#/sec] (mean)
Time per request:       392.720 [ms] (mean)
Time per request:       0.785 [ms] (mean, across all concurrent requests)
Transfer rate:          113.14 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        9  146 457.3     32   31038
Processing:    11  244 234.0    272    7536
Waiting:       11  244 234.0    272    7536
Total:         34  390 515.7    305   31323

Percentage of the requests served within a certain time (ms)
  50%    305
  66%    310
  75%    314
  80%    318
  90%    819
  95%   1306
  98%   1743
  99%   2758
 100%  31323 (longest request)

尽管是比原来提升了一些,但是比起fibjs的3000qps还是差了很多