Problem statement-
We are using router between internet client and downstream service. Router(service) is written in Node.js. Its responsiiblty is to pass internet client's request to corresponding downstream service, and return back the response to internet client. We are facing some delay at router level.
Library used for http-proxy-
https://github.com/nodejitsu/node-http-proxy
node-http-proxy Example-
Explaining with sample example. We are facing issue in 99 percentile case -
We did load/performance testing with 100 concurrency.
As per result, till 95 percentile, response time looks great to internet client.
But, in 99 percentile, Downstream service responds in expected time (~250ms). But router is taking 10 times more time than expected(~2500 ms).
Service information-
Both router, and downstream service are in same region, and same subnet. So, this delay is not because of network.
Possibilities of this delay-
To analyse this-
We twicked below configurations -
keepAlive, maxSockets, maxFreeSockets, keepAliveMsecs, log level. PLease check Node configurations for http/https agent - http agent configuration
Code snippet of node service -
var httpProxy = require('http-proxy');
var http = require('http');
var https = require('https');
var agent = new https.Agent({
maxSockets: nconf.get(25),
keepAlive: true,
maxFreeSockets: nconf.get(10),
keepAliveMsecs : nconf.get(5000)
});
var proxy = httpProxy.createServer({ agent: agent });
var domain = require('domain');
var requestTimeout = parseInt(nconf.get('REQUEST_TIMEOUT'));
process.env.UV_THREADPOOL_SIZE = nconf.get(4);
Questions-
[Update 1]
Found one interesting link - war-story.
If I missed any required information here, please ask me to add here.
Node.js in Heroku with AWS RDS js instance was capable to handle 31K requests in 60 seconds, which means an average of 515 requests per second.
Since Node. js uses non-blocking IO, the server can handle multiple requests without waiting for each one to complete, which means Node. js can handle a much higher volume of web traffic than other more traditional languages.
I suspect the http-proxy module to be the issue. If this handles the requests synchronously this can cause javascript to wait for a back-end response before it continues with the next request in the queue. I suggest changing to https://www.npmjs.com/package/http-proxy-async to see if this fixes the issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With