I'm trying to figure out what's the better solution.
I am running two http servers in my node app, server 1 at port 3000, server 2 on port 3001. Server 1 is making the main logic and database handling, while server 2 handles the file requests.
When I start my app with node myApp.js both servers are launched and listening to their ports.
/*
*Fire Up the Servers
*/
http.createServer(app).listen(3000, function(){
console.log('HTTP Express server listening on port 3000');
});
http.createServer(fileserver).listen(3001, function(){
console.log('HTTP Fileserver is listening on port 3001');
});
Now my Question: Does anyone know if it would make any difference if I would write for every server an own node process, so that I have to run node myApp.js which launches server 1, listening on port 3000 and then run node myFileserver.js which listens on port 3001.
Is there any performance difference? Or any hints where I can read something about it?
Regards, Martin
Depends on the rest of the code. If both the servers have shared states it's better to start them in same process.
If there is no shared state it's better to have them in separate processes so that one's execution flow does not affect the number of requests server by the other one. Specially true if one is IO bound and the other one is cpu intensive.
Also if you are starting them in the same process why not do both the things on the same port?