Open Unitech opened 8 years ago
Just did a CPU profiling while benchmarking
I did some research on the toppic of request proxying/loadbalancing
https://gist.github.com/Unitech/e27cca4e5b906be25c7dc4356126ef97
Doing a simple tcp proxying is the more efficient data forwarding:
var net = require('net');
var targets = [{
host: '127.0.0.1',
port: 8001
}, {
host: '127.0.0.1',
port: 8002
}];
var rri = 0;
var server = net.createServer(function(socket) {
var target_process = targets[rri++ % targets.length];
console.log('Redirecting connection to %s:%s',
target_process.host,
target_process.port);
var proxy = net.createConnection(target_process);
socket.setNoDelay(true);
proxy.setNoDelay(true);
proxy.pipe(socket).pipe(proxy);
socket.on('error', function(err) {
console.error(err);
socket.end();
});
proxy.on('error', function(err) {
console.error(err);
socket.end();
});
});
server.listen(7000);
I guess this does not support websocket upgrade
Thanks for the comments. I will answer you asap with some metrics too.
Hello h2non,
I'm trying to use rocky as a loadbalancer, before digging into using http middlewares for traffic replay.
I did a benchmark before going further with this code:
Then the test http application listening on port 8001:
I did a benchmark with wrk. The first one without rocky and the second by hitting rocky for traffic balancing:
The result is quite different with and without rocky. Without rocky (builting node http server) I get 246000 requests processed in 10 seconds. By using rocky It goes to 14997 requests in 10 seconds, 16x less performant than the raw http server.
Do you have any tips on enhancing overall performance? Aside from performance, rocky is clearly robust!
Thanks