how to speedup http-proxy performance

75 views
Skip to first unread message

nik600 AT 10^100

unread,
Nov 21, 2014, 5:40:06 AM11/21/14
to nod...@googlegroups.com
Dear all

i'm experiencing some performance-gap using http-proxy.

I've got a very simple server that does the following:

var http = require('http');
var httpProxy = require('http-proxy');
var proxy = httpProxy.createProxyServer({});


var server = http.createServer(function(req, res) {
   proxy.web(req, res, {
       target : 'http://127.0.0.1:19007'
   });
});

server.listen(19081);


if i test my server with:


i have:
Requests per second:    553.79 [#/sec] (mean)
Time per request:       180.575 [ms] (mean)
Time per request:       1.806 [ms] (mean, across all concurrent requests)
Transfer rate:          36467.65 [Kbytes/sec] received


but if try to go directly to the port 19007 (served by apache):


i have:
Requests per second:    1713.75 [#/sec] (mean)
Time per request:       58.352 [ms] (mean)
Time per request:       0.584 [ms] (mean, across all concurrent requests)
Transfer rate:          112853.17 [Kbytes/sec] received

i've tried also to enable cluster and fork some more process in the nodejs script but i'm not able to take over ~700 req/sec.

Can you help me to figure it out ?

- is a problem of implementation of my simple proxy ?
- is a "normal" gap ?
- maybe http-proxy has too many features and in this scenario i need something lighter and faster ?

Thanks to all in advance

nik600 AT 10^100

unread,
Nov 21, 2014, 8:37:27 AM11/21/14
to nod...@googlegroups.com
A couple of additional info:

i've tried also with a different set-up of the proxy object:

var http = require('http');
var httpProxy = require('http-proxy');                                   

httpProxy.createProxyServer({target:'http://127.0.0.1:19007'}).listen(19081);


but performances are the same

just to compare the overhead of a proxy interface i've tried to setup the same feature with nginx and i have ~1500 req/sec


Ryan Graham

unread,
Nov 23, 2014, 2:28:06 AM11/23/14
to nodejs
On Fri, Nov 21, 2014 at 2:40 AM, nik600 AT 10^100 <nik...@gmail.com> wrote:
Dear all

i'm experiencing some performance-gap using http-proxy.

I've got a very simple server that does the following:

var http = require('http');
var httpProxy = require('http-proxy');
var proxy = httpProxy.createProxyServer({});


var server = http.createServer(function(req, res) {
   proxy.web(req, res, {
       target : 'http://127.0.0.1:19007'
   });
});

server.listen(19081);




First the general recommendation:

Is this an accurate representation of what your real proxy will be doing? If it is, and performance is a real concern, you should probably look at using something like NGINX for your proxying instead of using Node.

If writing your own proxy really is necessary, then there are some things to look at.

From a quick scan of the http-proxy README, I see that it has an agent option that is uses internally for http.request(). This strongly suggests to me that you will run into issues with the default http.globalAgent.maxSockets being 5.

Try adding something like the following to your proxy code above:

http.globalAgent.maxSockets = 50;

You'll want to play around with different values to see which gives you the best performance for your request sizes and durations.

~Ryan
--
Reply all
Reply to author
Forward
0 new messages