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

Reply via email to