Does Node.js work on Windows, of course, it cannot be slower than apache for basic I / O

Question: Is the result reasonable? Is there anything that can affect the decrease in the number of requests per second?

Edit: My friend just compared the same application on Linux, and the average r / s was around 7000.

Edit # 2: I checked the processor usage of Node.exe, and it used only 5-6% of the processor. Of course, this figure should be 12% on a quad-core processor, 8 stream CPUs when working on a single thread, if really under load?

I wrote a Node.js application (running Node v0.6.10) and compared it with apachebench: ab -c 256 -n 50000 http://localhost:3000/ . I get a request per second of about 650 requests per second . There is too much code here, but this is the basic structure:

Application Settings:

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

In addition to the above code, the only notable remaining code is the Express app.get and app.post series of event handlers.

I ran the same test on the core web server configured by Express, and on the core web server Node.js http.

Node.js with Express Server

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

Results:
2000 requests per second on Express
2200 requests per second on Node.js

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

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

My relevant equipment specification:
Intel i7 2630qm
RAM 6 GB

+4
source share
4 answers

I can conclude by testing my own application on a Linux installation on the same machine that on Windows it is very slow. I am not sure if my installation of Windows or ALL Windows OS is installed.

The same application could deal with 3500 requests / sec without any changes . on Linux. . It is more than 500% faster ...

Please feel free to post here if you had similar experience, I would like to know if this is a Windows problem.

Benchmarking on the same computer, first downloaded to Linux and then to 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 
+11
source

I found that node is very slow if you refer to it as "localhost", but very quickly if you refer to it "127.0.0.1". I think that looking for dns on Windows really slows down queries.

+7
source

Is there anything that can affect the decrease in the number of requests per second?

I assume you think something is slowing down Node in your tests. Not. However, in the tests you refer to at the end, something slows down Apache.

You say that you are testing Apache with a static file, but for the tests you refer to, use the PHP file for the Apache test. Apache serving the uninterpreted file is about as close to the metal as you can get. But add PHP and you add a ton of overhead.

So, for your test, this is Apache versus Node and Apache wins, while the one you contacted with it wins Apache + PHP against Node and Node.

Not a single result surprises me.

+2
source

Do you understand that Apache uses several processes or threads to serve requests, while there is one Node.js process? Either configure Apache for a single workflow or thread, or run as many Node.js processes as you can, since you have CPU cores and their balancing.

+1
source

Source: https://habr.com/ru/post/1395959/


All Articles