Open leearmstrong opened 7 years ago
Even a simpler script exhibits the same issue...
var http = require('http'),
httpProxy = require('http-proxy');
//
// Create your proxy server and set the target in the options.
//
httpProxy.createProxyServer({target:'http://10.0.1.81'}).listen(8000); // See (†)
@leearmstrong try using something like wrk
rather than apache bench. apache bench doesnt support http 1.1. See if that makes a difference in your benchmarks. I would also suggest using an Agent
for this case so there is better socket reuse.
Node version would also be interesting to know
Never used wrk before so will give it a go. All of the client connecting into the nginx server direct (before the proxy I want to implement) are only HTTP 1.0 capable anyway so ab may be a better test.
This is Node 6.10.0
So I added a keep alive agent to it with a timeout of 30000msec and it made a bit of a difference, the test now completes in 75 seconds and not 103 seconds. This is no where near the direct connections from ab to the upstream of closer to 5 seconds.
I can accept there will be some overhead for proxying via node but this seems excessive? Or is this to be expected?
Stats using wrk
and using a keepAlive config
wrk -c 100 http://localhost/
Running 10s test @ http://localhost/
2 threads and 100 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 67.99ms 22.95ms 250.93ms 88.57%
Req/Sec 755.77 179.23 0.97k 75.13%
14873 requests in 10.01s, 5.24MB read
Requests/sec: 1485.59
Transfer/sec: 536.34KB
wrk -c 100 http://10.0.1.81/
Running 10s test @ http://10.0.1.81/
2 threads and 100 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 52.85ms 146.70ms 1.02s 90.08%
Req/Sec 26.95k 9.01k 57.15k 73.85%
524184 requests in 10.01s, 184.46MB read
Requests/sec: 52376.22
Transfer/sec: 18.43MB
I'm honestly not sure if we are comparing apples to apples if your backend is an nginx that can spawn workers. I would run your node process and do some profiling to get some more information. https://nodejs.org/en/docs/guides/simple-profiling/
I meet the same problem,I do not know what happened.
I am suffering from anything proxied via node being incredibly slow compared to direct and I cannot work out why! The code is incredibly simple... but as you will see from these apache bench tests they are MUCH MUCH slower in real life.
The idea of the ab tests is to show that the upstream servers in the round robin don't have any issues at all with the tests running from the server that the node code is running on.
This seems to happen for POST and GET requests.
The runtime of ab for the same request goes from 5 seconds to 105 seconds!