Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load balancing R requests coming to RServe

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

like image 793
Anand Avatar asked Jul 20 '16 10:07

Anand


1 Answers

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

like image 122
haddr Avatar answered Nov 02 '22 22:11

haddr