I have 6 Linux box running RServe and serving same set of R Scripts.
192.168.0.1 : 6311
192.168.0.2 : 6311
...
...
192.168.0.6 : 6311
I connect from java to these Rserve using REngine (Rserve Java Client).
RConnection rServeConnection = new RConnection(R_SERVE_SERVER_ADDRESS, R_SERVE_SERVER_PORT);
Now how do I load balance this ? Preferably in Apache Mod Proxy?
I've tried with httpd websocket load balancing settings and no luck.
Update: Concluded httpd doesn't load balance TCP traffic(Rserve uses TCP, while there are options in Rserve to enable websocket mode, my use case don't need that extra layer). Moved to HAProxy for load balancing with config as in the below link and able to load balance R script requests coming to Rserve with fault tolerance.
HAProxy Loadbalancing TCP traffic
I'm unsure if this is achieveable with Apache mod_proxy. I think it will only work with HTTP protocol. Maybe you can try a proof of concept setup with nginx. It supports load balancing of ordinary TCP and UDP connections. It also allows you todefine load balancing methods (e.g. round-robin, etc.).
The configuration would be:
stream {
upstream myapp1 {
server 192.168.0.1:6311;
server 192.168.0.2:6311;
...
server 192.168.0.6:6311;
}
server {
listen 80;
proxy_connect_timeout 1s;
proxy_timeout 3s;
proxy_pass backend;
}
}
You can find more information in the nginx documentation: https://www.nginx.com/resources/admin-guide/tcp-load-balancing/ and here: https://nginx.org/en/docs/stream/ngx_stream_core_module.html
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