我尝试使用benchmark.js来获取节点服务器性能的一些统计信息,但不知何故无法获取服务器函数调用而没有统计信息,这是我得到的唯一内容 - 服务器通过基准测试脚本启动。
如果benchmark.js适合此类任务,如何获取统计信息而不启动服务器?
服务器:
叔server.js
'use strict';
var
http = require('http');
var self = module.exports = {
init: function(){
self.server = http.createServer(self.handleRequest);
self.server.listen(8080, function(){
console.log("Server up ");
});
}
}
self.handleRequest = function(request, response) {
var requestParams = {a: 'a', b: 1};
self.process2test(response, requestParams);
}
self.process2test = function(response, requestParams) {
console.log("in process2test, got a:"+requestParams.a+",b:"+requestParams.b);
}
self.init();
基准脚本
基准-v.js
var Benchmark = require('benchmark');
var suite = new Benchmark.Suite();
var server = require('./t-server');
var response={};
var requestParams = {
"a":"a",
"b": 2
};
suite.add('process2test_a', function(response, requestParams) {
requestParams.b++;
server.process2test(response,requestParams);
})
.add('process2test_b', function(response, requestParams) {
requestParams.a='c';
server.process2test(response,requestParams);
})
.on('cycle', function(event) {
console.log(String(event.target));
})
.on('complete', function() {
console.log('Fastest is ' + this.filter('fastest').map('name'));
})
.run({ 'async': true });