Reputation: 46543
I'd like to know if there is a difference, performance wise between:
1) in the same port:
var http = require('http');
http.Server(function (req, res) {
if (req.url == 'foo') { foo(); return;}
if (req.url == 'bar') { bar(); }
}).listen(123);
2) splitted on 2 ports
var http = require('http');
http.Server(function (req, res) {
foo();
}).listen(123);
http.Server(function (req, res) {
bar();
}).listen(456);
3) in 2 separate js file that I would launch on 2 different node cmd.
foo()
and bar()
being functions that can take time to resolve like uploading files for example.
Upvotes: 1
Views: 72
Reputation: 27370
#1 and #2 will be basically identical in terms of performance. If you run two servers like in #3 and you have a multi-core machine you will be able to perform up to twice as many simultaneous requests, depending on the IO required and available.
Upvotes: 1
Reputation: 262504
Two different node instances give you two CPU threads (but use up more memory and cannot easily share state). That is the only real difference I can see.
Upvotes: 1