On Friday, April 10, 2015 at 1:54:23 PM UTC-4, Ingwie Phoenix wrote:Hey.
I would like to ask how I can turn a single-process express app into one that uzilizes multiple processes. Imagine the following structure:
main (pid 1001)
|- express1 (pid 1002)
|- express2 (pid 1003)
|- …
My goal is to improve performance by spanning my http server across multiple processes. I also will add a Varnish server infront, so all that my Express app is doing is handling the actual action, which can be quite heavy on a single process.
Step 1: Make sure your requests share state by communicating out of process, not by sharing state in variables, if requests interact with each other at all.
Step 2: use the cluster module. That's exactly what it's for. It's better designed in iojs and node 0.12 than node 0.10, but the general idea is the same.
Step 1: Make sure your requests share state by communicating out of process, not by sharing state in variables, if requests interact with each other at all.I use Redis to establish an RPC/RMI layer. It is used to distribute events to trigger backups and the like.
Step 2: use the cluster module. That's exactly what it's for. It's better designed in iojs and node 0.12 than node 0.10, but the general idea is the same.Do I listen on the port on the master or child process?
I looked into pm2, but I got a bit confused with it. I only saw CLI usage. What is a basic in-script usage?
On Friday, April 10, 2015 at 3:20:24 PM UTC-4, Ingwie Phoenix wrote:Step 2: use the cluster module. That's exactly what it's for. It's better designed in iojs and node 0.12 than node 0.10, but the general idea is the same.Do I listen on the port on the master or child process?
In the child. Counterintuitive, but that's how the magic happens.
I looked into pm2, but I got a bit confused with it. I only saw CLI usage. What is a basic in-script usage?
CLI is the normal way -- it wraps your process and starts it, injecting its magic. Weird, but works pretty well.
Mind the license though.
I looked into pm2, but I got a bit confused with it. I only saw CLI usage. What is a basic in-script usage?
CLI is the normal way -- it wraps your process and starts it, injecting its magic. Weird, but works pretty well.Mm…I prefer to keep things self-contained. Workerman is the same for PHP, really. I have a main script and then call that instead of a pre-installed program. Gives me more control of the used versions and alike. I also looked at forever - but neither pm2 or forever seem to allow to simply be require()’d and then set up… well, looks like I’ll have to make my own cluster initializer then.
Mind the license though.
What exactly do you mean? I am not a native english, so reading licenses usually gives me grande headaches...
--
Job board: http://jobs.nodejs.org/
New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+un...@googlegroups.com.
To post to this group, send email to nod...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/41b34414-9144-47f8-9ac8-780763ae5b1e%40googlegroups.com.