Description
I would like to open a thread regarding performance, because I think it requires a bit more of attention than it has actually received lately.
Although this project does not aim to be as performant as other leading proxies such as HAProxy or nginx, I think most of its users would certainly be happy if the proxy does not degrade the performance to a nodejs server by a factor of 10x or 15x.
This closed issue: #929 shows that it is very easy to actually verify the performance degradation produced by the proxy. The workaround is to send a http.Agent
with keepAlive: true
, and maybe other finetunings. The issue refers to a FAQ, but I cannot find any FAQ. Also it would be great to provide a couple of things regarding http.Agent: 1) what is the tradeoff of using it? (if none, why is it not enabled by default), 2) Which is the optimal set of options for it? just changing arbitrarily and re-testing does not seem like a good approach, and also a dangerous one I may add, since the user most probably does not know what he is doing. 3) Why is http.Agent required to begin with?
One thing that may make many wondering is how is it possible that if a dummy http server in node js is capable of delivering responses in the order of magnitud 10k, a simple proxy infront of it, that should, in its most basic conceptual form, just pipe the data from source to target, reduces the performance to order of magnitude 0.5k. One could accept 50% degration, but not this much. Thing is, this may not be related to http-proxy at all, for instance I wrote this super simple example:
var http = require('http');
var request = require('request');
http.createServer(function(req, res){
request.get('http://127.0.0.1:3000').pipe(res);
}).listen(8080);
http.createServer(function(req, res){
res.writeHead(200);
res.write('HELLO WORLD');
res.end();
}).listen(3000);
And got this results (in node 4.5):
$ wrk -c 64 -d 15s http://localhost:3000
Running 15s test @ http://localhost:3000
2 threads and 64 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 4.85ms 3.41ms 307.55ms 99.38%
Req/Sec 6.73k 505.00 7.10k 93.38%
202128 requests in 15.10s, 24.87MB read
Requests/sec: 13384.99
Transfer/sec: 1.65MB
$ wrk -c 64 -d 15s http://localhost:8080
Running 15s test @ http://localhost:8080
2 threads and 64 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 55.45ms 12.50ms 158.42ms 88.76%
Req/Sec 569.33 128.19 760.00 81.94%
8265 requests in 15.07s, 0.98MB read
Requests/sec: 548.31
Transfer/sec: 66.40KB
So can it really be node's streams are so amazingly slow? It's a bit worrisome I must admit. Anybody as any insights that he wouldn´t mind to share?