node.js - nodejs multithread for the same resource -


i'm quite new nodejs , i'm doing experiments. them (and hope i'm wrong!) nodejs couldn't serve many concurrent requests same resource without putting them in sequence.

consider following code (i use express framework in following example):

var express = require('express'); var app = express();  app.get('/otherurl', function (req, res) { res.send('otherurl!'); });  app.get('/slowfasturl', function (req, res)  {      var test = math.round(math.random());      if(test == "0")     {         var i;         settimeout         (             function()             {                 res.send('slow!');              }, 10000         );      }     else     {         res.send('fast!');     }  });  app.listen(3000, function () {       console.log('app listening on port 3000!');     }); 

the piece of code above exposes 2 endpoints:

scenario 1 : reply "fast!" simple text

or

scenario 2 : reply after 10 seconds "slow!" simple text

my test: i've opened several windows of chrome calling @ same time slowfasturl url , i've noticed first request falls in "scenario 2", causes blocking of other requests fired subsequentely (with other windows of chrome), indipendently of fact these ones fallen "scenario 1" (and return "slow!") or "scenario 2" (and return "fast!"). requests blocked @ least until first 1 (the 1 falling in "scenario 2") not completed.

how explain behavior? requests made same resource served in sequence?

i experience different behavior if while request fallen in "scenario 2" waiting response, second request done resource (e.g. otherurl url explained above). in case second request completed without waiting first one

thank you

davide

as far remember, requests blocked browser side.

your browser preventing parallel requests server can process them. try in different browsers or using curl , should work.


Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -