Node background worker possible?

632 views
Skip to first unread message

Johan Alkstål

unread,
Jan 2, 2014, 4:55:14 PM1/2/14
to nod...@googlegroups.com
I'm building a sports app with a game simulation engine.

I'd like the simulation engine to run independently of the main web app.

Questions I have are,

do I need to run it independently first of all, in order to not cause performance problems with the main web app?

Is it possible to have a node app running like a worker in the background?

Anyone with any other ideas on how to set this up using Node?

Ryan Dahl

unread,
Jan 2, 2014, 5:10:25 PM1/2/14
to nodejs
Yeah, forking off a separate process is a good idea. Check out require('child_process').fork() which will allow you to send messages back and forth between the web-head and the simulator

Akzhan Abdulin

unread,
Jan 2, 2014, 6:17:08 PM1/2/14
to nod...@googlegroups.com
Yet another option is require('webworker'). Typical implementation is https://npmjs.org/package/webworker-threads


2014/1/3 Johan Alkstål <johan....@gmail.com>
--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines: 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 post to this group, send email to nod...@googlegroups.com
To unsubscribe from this group, send email to
nodejs+un...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
 
---
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.
For more options, visit https://groups.google.com/groups/opt_out.

Johan Alkstål

unread,
Jan 3, 2014, 1:47:53 PM1/3/14
to nod...@googlegroups.com

So should this forked child process always be running (and thus having all simulations use it) or should I fork one for each simulation run?

I mean if the simulations should be queued and executed in order or in parallel by multiple processes?

And what are the benefits/drawbacks from using the web worker implementation with multiple threads?


Ryan Dahl

unread,
Jan 3, 2014, 2:14:51 PM1/3/14
to nodejs
On Fri, Jan 3, 2014 at 1:47 PM, Johan Alkstål <johan....@gmail.com> wrote:

So should this forked child process always be running (and thus having all simulations use it) or should I fork one for each simulation run?

I mean if the simulations should be queued and executed in order or in parallel by multiple processes?
  

That'll depend on how long these simulations run and how many of them there will be - but I would suspect you want on child process per simulation.
 
And what are the benefits/drawbacks from using the web worker implementation with multiple threads?

Web worker is just a different (browser compatible) API for child_process.fork. Probably you should just use the API node provides unless you're thinking about running these simulations client side as well.

Hongli Lai

unread,
Jan 4, 2014, 5:18:32 AM1/4/14
to nod...@googlegroups.com, r...@tinyclouds.org
On Friday, January 3, 2014 8:14:51 PM UTC+1, Ryan Dahl wrote:
On Fri, Jan 3, 2014 at 1:47 PM, Johan Alkstål <johan....@gmail.com> wrote:

So should this forked child process always be running (and thus having all simulations use it) or should I fork one for each simulation run?

I mean if the simulations should be queued and executed in order or in parallel by multiple processes?
  

That'll depend on how long these simulations run and how many of them there will be - but I would suspect you want on child process per simulation.

It also depends on how expensive the startup of your code is. If it takes 5 seconds to start your simulation program then you should not create a process per simulation. Instead, you should keep the simulation program running and feed it input to avoid the startup cost.

Johan Alkstål

unread,
Jan 4, 2014, 7:12:51 AM1/4/14
to nod...@googlegroups.com
Thank you all for your replies! Much appreciated.


2014/1/4 Hongli Lai <hong...@gmail.com>

--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines: 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 post to this group, send email to nod...@googlegroups.com
To unsubscribe from this group, send email to
nodejs+un...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
 
---
You received this message because you are subscribed to a topic in the Google Groups "nodejs" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/nodejs/5xNIbJSRMiY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to nodejs+un...@googlegroups.com.

Tony Huang

unread,
Jan 4, 2014, 10:08:33 PM1/4/14
to nod...@googlegroups.com
i think use "forever" instead of raw child process may be a good idea~


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.

For more options, visit https://groups.google.com/groups/opt_out.



--
------------------------------------------------------
Tony Huang    cnw...@gmail.com
                     wz...@hotmail.com
                     wz...@vip.sina.com

Johan Alkstål

unread,
Jan 5, 2014, 7:14:46 AM1/5/14
to nod...@googlegroups.com
Tony, what do you mean?


2014/1/5 Tony Huang <cnw...@gmail.com>

Hongli Lai

unread,
Jan 5, 2014, 8:58:37 AM1/5/14
to nod...@googlegroups.com

Forever is a tool for running node processes in the background and keeping them running. It eases the management of processes somewhat.

Sent from my Android phone.

John Engstrom

unread,
Jan 5, 2014, 1:12:24 PM1/5/14
to nod...@googlegroups.com
.p....pp

Johan Alkstål

unread,
Jan 5, 2014, 1:13:05 PM1/5/14
to nod...@googlegroups.com
Wouldn't that still be using child processes or would it be a completely different node app?


2014/1/5 Hongli Lai <hon...@phusion.nl>

Hongli Lai

unread,
Jan 5, 2014, 2:06:17 PM1/5/14
to nod...@googlegroups.com

Yes it would still use child processes. It's essentially the same thing, just with easier management.

Sent from my Android phone.

Reply all
Reply to author
Forward
0 new messages