Are you using a version of node that defaults to only 5 sockets for the global agent?
~Ryan On Tue, 7 Apr 2015 at 04:42 Kishore Kumar Yekkanti < [email protected]> wrote: > I have a simple case where I'm requesting a different upstream proxy > server from my node.js server. With the increase in load I see the request > takes lot of time to execute(though time taken to respond from my upstream > proxy server is constant across the requests). To demonstrate the issue > i've written a sample program as below. If you execute the below program, > the first request takes *118ms* to execute and the last one takes > *10970ms*. If you observe i'm using async to parallelize my requests. > > *The question is*, what is the reason node.js takes this much time to > execute a request when run in parallel. To give some more context on the > infra settings(centos 6.5) I have opened up my port range from 1024 to > 65535, change the fin_timeout to 15 seconds and enable tw_reuse =1 for > sockets in sysctl.conf > > var http = require('http');var uuid = require('node-uuid');var async = > require('async'); > function callExternalUrl(){ > var uniqueId = uuid.v4(); > console.time(uniqueId); > var options = { > host: 'google.com', > port: '80', > path: '/', > method: 'GET' > }; > var req = http.request(options, function(res) { > var msg = ''; > res.setEncoding('utf8'); > res.on('data', function(chunk) { > msg += chunk; > console.timeEnd(uniqueId); > }); > res.on('end', function() { > }); > }); > req.end();} > function iterateAsync(callback){ > var iter = []; > for(var i=0; i<1000; i++){ > iter[i] = i; > } > async.each(iter, > function(item, callback) { > callExternalUrl(); > }, > function(err) { > callback(err); > } > );} > > iterateAsync(function(){console.log('done');}); > > -- > 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 [email protected]. > To post to this group, send email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/nodejs/e45d0fac-f0d2-45b9-9eeb-4dcc0a4fe650%40googlegroups.com > <https://groups.google.com/d/msgid/nodejs/e45d0fac-f0d2-45b9-9eeb-4dcc0a4fe650%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- 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 [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/CAGjmZGyFVLBH_ibzMEGHSyxqegMx3dgzm4XpaPdT9hbg1jUQJQ%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
