Jac*_*ack 6 apache apachebench node.js
编辑:我的一个朋友刚刚在Linux上对相同的应用程序进行了基准测试,平均r/s约为7000.
编辑#2:我已经检查了Node.exe的CPU使用率,它只使用了5-6%的cpu.当一个四核机器上的这个数字应该是12%,如果在真正负载的情况下在单个线程上运行时,8个线程CPU应该是这个数字?
我编写了一个Node.js应用程序(运行Node v0.6.10)并使用apachebench对其进行基准测试:ab -c 256 -n 50000 http://localhost:3000/.我每秒钟收到大约650个请求的请求.这里有太多代码,但这是基本结构:
应用程序设置:
/**
* Module dependencies.
*/
var util = require('util'), //Useful for inspecting JSON objects
express = require('express'), //Express framework, similar to sinatra for ruby
connect = require('connect'), //An integral part of the express framework
app = module.exports = express.createServer(), //Create the server
io = require('socket.io').listen(app), //Make Socket.io listen on the server
parseCookie = require('connect').utils.parseCookie, //Parse cookies to retrieve session id
MemoryStore = require('connect').session.MemoryStore, //Session memory store
sessionStore = new MemoryStore(),
Session = require('connect').middleware.session.Session,
mongodb = require('mongodb'), //MongoDB Database
BSON = mongodb.BSONPure, //Used to serialize JSON into BSON [binary]
sanitize = require('validator').sanitize;
// Configuration
app.configure(function()
{
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.cookieParser());
app.use(express.session({
store: sessionStore,
secret: '...',
key: 'express.sid'}));
app.use(app.router);
app.use(express.static(__dirname + '/public'));
});
app.configure('development', function(){
//app.use(express.errorHandler({dumpExceptions: true, showStack: true}));
});
app.listen(3000);
console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env);
io.configure('development', function()
{
io.set('transports', ['websocket']);
//io.set('heartbeats', false);
//io.set('heartbeat timeout', 200);
//io.set('heartbeat interval', 220);
});
//MongoDB Database port and ip
var DATABASE_PORT = 27017;
var DATABASE_IP = "127.0.0.1"; //Localhost
/*
setInterval(function(){
console.log("BROWSING:\n" + util.inspect(browsing));
}, 1000);
*/
//Connected users
var validUsers = {};
var clients = {};
var browsing = {};
//Database handles
var users;
var projects;
//Connect to the database server
db = new mongodb.Db('nimble', new mongodb.Server(DATABASE_IP, DATABASE_PORT, {}, {}));
db.open(function (error, client)
{
if (error) {
console.error("Database is currently not running");
throw error;
}
users = new mongodb.Collection(client, 'users'); //Handle to users
projects = new mongodb.Collection(client, 'projects'); //Handle to projects
});
app.get('/', function(req, res)
{
//users.insert("test", {safe:true});
//users.findOne("test", function(result){})
if(req.session.auth)
{
if(req.session.account == "client")
{
//Redirect to the client dash
res.redirect('/dash');
}
else if (req.session.account == "developer")
{
res.redirect('/projects');
}
}
else
{
res.redirect('/login');
}
});
Run Code Online (Sandbox Code Playgroud)
除了上面的代码,唯一值得注意的剩余代码是一系列Express app.get和app.post事件处理程序.
我在基本的Express设置Web服务器和基本的node.js http Web服务器上执行了相同的测试.
Node.js与Express服务器
var express = require('express');
var app = express.createServer();
app.get('/', function(req, res){
res.send();
});
app.listen(3000);
Run Code Online (Sandbox Code Playgroud)
Node.js HTTP
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end();
}).listen(3000, "127.0.0.1");
Run Code Online (Sandbox Code Playgroud)
结果是:
Node.js上每秒
Express
2200请求的每秒2000个请求
我对Apache Web服务器上托管的静态文件执行了相同的测试:
每秒6000个请求
现在这个基准测试显示Node.js击败了Apache手!
http://zgadzaj.com/benchmarking-nodejs-basic-performance-tests-against-apache-php
我的相关硬件规格:
Intel i7 2630qm
6 GB RAM
Jac*_*ack 14
我可以通过在同一台机器上的Linux安装上测试我自己的应用程序来结束它在Windows上实际上非常慢.我不确定这是我的Windows安装还是所有Windows安装.
没有变化的相同应用程序能够在Linux上处理3500请求/秒.哪个速度快了500%......
如果您对自己有类似的体验,请随时在此发帖,我想知道这是否是Windows问题.
在同一台机器上进行基准测试,首先启动到Linux,然后启动Windows.
Linux GET R/s 3534 3494 3568 3580 3528
CLUSTER GET R/s 11987 11565 11950 12042 12056
GET DB INSERT R/s 2251 2201 2167 2207 2132
GET DB SELECT R/s 2436 2512 2407 2457 2496
Windows GET R/s 725 730 721 760 723
CLUSTER GET R/s 3072 3129 3421 2912 3203
GET DB INSERT R/s 611 623 605 632 610
GET DB SELECT R/s 672 691 701 698 682
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8977 次 |
| 最近记录: |