So you guys mean that with each request relate to a heavy computing task,
we should create new process to handle it in NodeJs, right?
I just create those request handler based on this template:
module.exports = function(app) {
//handler1
app.get('pathname1', function() {});
//handler2
app.get('pathname2', function() {});
...other handlers
}
So assume I have 10 handlers in total, but 9 task handlers relate to heavy
computing that utilize cpu power, so I need to create 9 sub processes, is
it a normal and acceptable coding way in Nodejs? I mean from my view, it's
quite weird a little bit.
Any other approach without creating sub process for each request like that?
Thanks.
On Fri, Jun 29, 2012 at 7:27 PM, Ben Noordhuis <[email protected]> wrote:
> On Fri, Jun 29, 2012 at 12:49 PM, hd nguyen <[email protected]>
> wrote:
> > Hi all,
> >
> > I'm new here and want to make a simple test web app with NodeJS and
> Express
> > framework.
> >
> > I created 2 request are http://localhost:3000/heavycompute (very long
> time
> > processing) and http://localhost:3000/ (just display text, return
> > immediately) and handling methods for them as below code:
> >
> > module.exports = function(app) {
> > //for http://localhost:3000/
> > app.get('/', function(req, res){
> > res.render('index', { title: 'Express', html: 'html param' });
> > } );
> >
> >
> > //for http://localhost:3000/heavycompute
> > app.get('/heavycompute', function(req, res) {
> > var sum = 0;
> > for(var i = 0; i < 99998888777; i++) {
> > sum += i;
> > }
> > res.render('index', { title: 'Express', html: sum });
> > } );
> > };
> >
> > The problem here is when I open simultaneously 2 tabs, each method on a
> tab,
> > enter http://localhost:3000/heavycompute FIRST, then
> > hit http://localhost:3000/,
> >
> > I expect http://localhost:3000/ return right away, but seem it must
> wait for
> > completion of http://localhost:3000/heavycompute request handler.
> >
> > Could you help me pointing out what I have done wrong here with my code?
> I'm
> > new and not sure I handle event-driven mechanism in coding properly, I
> want
> > each handler should process each request separately as normal threaded
> web
> > app server (tomcat, IIS,...).
> >
> > Appreciate any explanation/help.
> >
> > Thanks in advance.
>
> Don't do long computations inside your main application. Spin up a
> child process with require('child_process').fork() and do it there.
>
> --
> 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 [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en
>
--
Nguyen Hai Duy
Mobile : 0914 72 1900
Yahoo: nguyenhd_lucky
--
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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en