9
votes

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

3
I don't think rserve is http?Jeroen
yes.. Rserve is not http. It connects via TCP/IP socket. IP:6311 @jeroenAnand
Looks like more people are looking for same solution. Here is a working solution. Thumps up if it helps. stackoverflow.com/a/39052040/1057093Anand
Great to hear that! I think the lesson here was to find a proper TCP and not just HTTP load balancing.haddr

3 Answers

1
votes

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

0
votes

If you haven't already done so and since you are already working in Java, start off by connecting to your RServe servers from Java and run a simple "hello world" script on them, as given in the CRAN examples

Once the RServe instances are working fine, then you need to either load balance from Java or create one Java program per server and let Apache load balance between them. In either case your Java programs will need to serve http because you still need a link between html and RServe.

0
votes

Looks like more people are looking for a solution to load balancing R scripts. Here is a working solution to loadbalance R via Rserve and HAproxy TCP load balancer.

Thumps up if it helps.

https://stackoverflow.com/a/39052040/1057093