大佬教程收集整理的这篇文章主要介绍了Node.js在Windows上表现不佳,当然它不能比基本I / O的apache慢,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
编辑:我的一个朋友刚刚在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'); } });
除了上面的代码,唯一值得注意的剩余代码是一系列Express app.get和app.post事件处理程序.
我在基本的Express设置Web服务器和基本的node.js http Web服务器上执行了相同的测试.
Node.js与Express服务器
var express = require('express'); var app = express.createServer(); app.get('/',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");
结果是:
Express上每秒2000个请求
Node.js上每秒2200个请求
我对Apache Web服务器上托管的静态文件执行了相同的测试:
每秒6000个请求
现在这个基准测试@L_673_19@Node.js击败了Apache手!
http://zgadzaj.com/benchmarking-nodejs-basic-performance-tests-against-apache-php
我的相关硬件规格:
英特尔i7 2630qm
6 GB RAM
没有变化的相同应用程序能够在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 @R_197_10288@CT 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 @R_197_10288@CT R/s 672 691 701 698 682
以上是大佬教程为你收集整理的Node.js在Windows上表现不佳,当然它不能比基本I / O的apache慢全部内容,希望文章能够帮你解决Node.js在Windows上表现不佳,当然它不能比基本I / O的apache慢所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。