我们计划使用nodejs而不是tomcat或jetty。但我们围绕它进行了一些测试,节点的执行速度比jetty慢。我们运行的测试用例是8核心机器,32GB内存。对于测试,我们使用了1000个并发1000个请求。我们使用了集群模块,url模块,http模块和带有流的os模块。这些模块是否增加了任何开销......?我们可以做些什么来改善性能。以下是节点的代码。
var http = require("http");
var url = require("url");
var cluster = require('cluster');
var fs = require('fs');
var numCPUs = require('os').cpus().length;
var stream = [];
if (cluster.isMaster) {
for (var i = 0; i < numCPUs; i++) {
cluster.fork();
}
cluster.on('death', function(worker) {
console.log('worker ' + worker.pid + ' died');
});
}
else{
var server = http.createServer(function(request, response) {
response.end();
});
stream = fs.createWriteStream("nodejsCluster"+cluster.worker.id+".txt");
stream.once('open', function(fd) {
server.listen(8084);
});
server.on('request', function(request, response){
var parsedUrl = url.parse(request.url, true, true);
var queryAsObject = parsedUrl.query;
stream.write( ( new Date() )+'This is the content to write into file '+queryAsObject.test+"\n");
});
console.log("Server is listening"+cluster.worker.id);
}
由于