Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@zlaoz
Created May 17, 2014 11:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zlaoz/4a730bfe7f322f6442fd to your computer and use it in GitHub Desktop.
Save zlaoz/4a730bfe7f322f6442fd to your computer and use it in GitHub Desktop.
slow requests using node-http-proxy on ubuntu
var http = require('http');
var httpProxy = require('http-proxy');
//
// Proxy Server
//
var agent = new http.Agent();
agent.maxSockets = 10000;
var options = {
agent: agent,
target:'http://localhost:9003'
};
var proxy = httpProxy.createProxyServer(options);
var proxyServer = http.createServer(function(req, res) {
proxy.web(req, res, options);
});
proxyServer.on('connection', function (socket) {
'use strict';
socket.setNoDelay(true);
});
proxyServer.listen(8003);
//
// Target Http Server
//
var httpServer = http.createServer(function (req, res) {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.write('request successfully proxied to: ' + req.url + '\n' + JSON.stringify(req.headers, true, 2));
res.end();
});
httpServer.on('connection', function (socket) {
'use strict';
socket.setNoDelay(true);
});
httpServer.listen(9003);
/*
client machine (running wrk from) AND server machine (running proxy.js):
- "Linux user1 3.11.0-12-generic #19-Ubuntu SMP Wed Oct 9 16:20:46 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux, Ubuntu 13.10"
- Node v0.10.28
kernel-tuning done on both machines:
- (/etc/sysctl.conf):
fs.file-max = 999999
net.ipv4.tcp_rmem = 4096 4096 16777216
net.ipv4.tcp_wmem = 4096 4096 16777216
net.ipv4.ip_local_port_range = 1024 65535
- (/etc/security/limits.conf):
#<domain> <type> <item> <value>
* soft nofile 10000
* hard nofile 30000
benchmark with wrk (v3.1.0):
(direct):
wkr -c 100 -t 1 http://10.10.10.1:9003/ :
Running 10s test @ http://10.10.10.1:9003/
1 threads and 100 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 23.68ms 5.15ms 61.28ms 80.80%
Req/Sec 4.30k 559.95 5.50k 73.33%
41758 requests in 10.00s, 8.44MB read
Requests/sec: 4175.61
Transfer/sec: 864.48KB
(via proxy):
wkr -c 100 -t 1 http://10.10.10.1:8003/ :
Running 10s test @ http://10.10.10.1:8003/
1 threads and 100 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 275.81ms 20.41ms 331.75ms 74.06%
Req/Sec 363.44 33.51 463.00 87.50%
3614 requests in 10.00s, 854.09KB read
Requests/sec: 361.40
Transfer/sec: 85.41KB
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment