I am investigating the possibility of using Node to act as a reverse proxy. One of the primary goals of my project is for it to be VERY high performance. So I've setup a node server to proxy requests to the target node server that will respond with 'hello world' no matter the request.
Using Apache Bench I've done some comparison on the number of requests processed per second. The proxy, target and caller are each on separate M1 Large instances in AWS. My results are frustrating and confusing.
Direct from caller to Target:
ab -c 100 -n 10000 http://target-instance/
= ~2600 requests/second
From caller through proxy to target
ab -c 100 -n 10000 http://proxy-instance/
= ~1100 requests/second
Using lighttpd I was able to get ~3500 requests/second on proxy and target
I'm disappointed that the proxy server is less performant than the target server. When comparing other products like lighttpd I've seen the proxy achieve comparable results to the target so I'm confused about when Node (supposed to be lightening fast) is not achieving the same.
Here's my proxy code in Node v0.5.9: Am I missing something?
var server =
http.createServer(function(req, res){
var opts = { host: 'target-instance',
port: 80,
path: '/',
method: 'GET'};
var proxyRequest = http.get(opts, function(response){
response.on('data', function(chunk){
res.write(chunk);
});
response.on('end', function(){
res.end()
});
});
});
server.listen(80);
Reverse proxies help increase performance, reliability, and security. They provide load balancing for web applications and APIs. They can offload services from applications to improve performance through SSL acceleration, caching, and intelligent compression.
js as a platform has a few limitations on its own that we have to accept. However, with proper logging, monitoring, in-depth understanding of platforms and tooling you can scale & serve millions of customers in real-time.
js can handle ~15K requests per second, and the vanilla HTTP module can handle 70K rps.
Express. js, sometimes also referred to as “Express,” is a minimalist, fast, and Sinatra-like Node. js backend framework that provides robust features and tools for developing scalable backend applications.
While Node.js is very efficient, it is not multi-threaded so the proxy node is going to be handling more connections than the target but with only one thread and therefore become the bottleneck. There are two ways around this:
Try bouncy: https://github.com/substack/bouncy
It was optimized for very high performance.
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