Node.js的是否在Windows上表现很差,肯定不能比的Apache基本我慢/ O [英] Does Node.js perform badly on Windows, surely it can't be slower than apache for basic I/O

查看:561
本文介绍了Node.js的是否在Windows上表现很差,肯定不能比的Apache基本我慢/ O的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编辑:我的一个朋友刚刚基准在Linux和平均R / S相同的应用程序是大约7000

A friend of mine has just benchmarked the same application on Linux and the average r/s was approx 7000.

编辑#2:我检查Node.exe的CPU使用率,而且它仅使用CPU的5-6%。当然,如果真的下负载在单个线程运行时,这个数字应该是一个四核机器上的12%,8线程CPU?

Edit #2: I've checked the CPU usage of Node.exe, and it's only using 5-6% of the cpu. Surely this figure should be 12% on a quad core machine, 8 thread CPU when running on a single thread if truly under load?

我写了一个Node.js应用程式(运行节点v0.6.10)和apachebench基准是: AB -c 256 -n 50000的http://本地主机:3000 / 。我得到每大约650每秒请求第二速率的请求。有太多的code放到这里,但是这是基本的结构:

I've written a Node.js application (running Node v0.6.10) and benchmarked it with apachebench: ab -c 256 -n 50000 http://localhost:3000/. I'm getting a request per second rate of roughly 650 requests per second. There's too much code to put here, however this is the basic structure:

应用程序设置:

/**
 * 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');
  }       
});

除了上述code中的唯一显着的剩余code是一个系列防爆preSS的 app.get app.post 事件处理程序。

我已经完成一个基本的防爆preSS设置Web服务器相同的测试,其基本的node.js HTTP Web服务器。

I have performed the same test on a basic Express set up web server, and the basic node.js http web server.

与前preSS服务器的Node.js

var express = require('express');
var app = express.createServer();

app.get('/', function(req, res){
    res.send();
});

app.listen(3000);

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");

结果存在:

每秒2000次请求的前preSS

每秒2200请求对Node.js的

The results being:
2000 requests per second on Express
2200 requests per second on Node.js

我对主持的Apache Web服务器上的静态文件进行相同的测试:

每秒6000请求

I've performed the same test against a static file hosted on an Apache web server:
6000 requests per second

现在这个基准测试显示Node.js的跳动Apache的手了!

http://zgadzaj.com/benchmarking-nodejs-basic-performance -tests-反对的Apache,PHP




我的相关硬件规格:

英特尔酷睿i7 2630QM

6 GB RAM

Now this benchmark shows Node.js beating Apache hands down!
http://zgadzaj.com/benchmarking-nodejs-basic-performance-tests-against-apache-php

My relevant hardware spec:
Intel i7 2630qm
6 GB RAM

推荐答案

我可以通过测试我自己在Linux应用程序安装在同一台机器,这是逸岸在Windows上速度很慢的结论。我不能确定,是否这就是我的Windows安装或所有的Windows安装。

I can conclude through testing my own application on a Linux install on the same machine that it was infact VERY slow on Windows. I'm unsure as to whether that's my Windows install or ALL Windows installs.

没有改变同一个应用程序能够处理的 3500请求/秒Linux上。这是超过500%的速度...

The same application with no change was able to deal with 3500 request / second on Linux. Which is over 500% faster...

请随意张贴在这里,如果你也有过类似的经验,我自己,我想知道,如果这是一个Windows的问题。

标杆在同一台机器上,先以Linux启动了,然后Windows操作系统。

Benchmarking on the same machine, first booted into Linux, and then 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

这篇关于Node.js的是否在Windows上表现很差,肯定不能比的Apache基本我慢/ O的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆