0

I have an Opencpu server with my package in it. This package contains a function which generates a plot image. When I send a POST request to this function via Opencpu, I get the session id in response which in turns is actually a folder on the Opencpu server containing the resources, image be the one. I pass on this image url (being served by Opencpu server) to my application and it uses that to create a PDF report.

Now, I have scaled this whole scenario by creating multiple instances of Opencpu containing my package. The instances are behind a Load Balancer. When I do the same, I get the image url. When my application uses this image url, it may not be found because now the request may have gone to some another instance of the Opencpu.

How can I approach the solution of this problem? One thing I have done for now is uploading the image to some public instance and return the corresponding path to the application. But that is too coupled.

Thanks.

Harsh Choudhary
  • 475
  • 5
  • 12

1 Answers1

0

Load balancing is always a bit complicated, so if possible, it is easier to just move to a larger server. Most (cloud) providers offer (virtual) instances with many cores and 100GB+ RAM, which will allow you to support many users.

If you really need load balancing there are a few methods. One approach is to map the ocpu-store directory on the ocpu servers to a shared NSF server. By default opencpu stores all sessions in the /tmp/ocpu-store directory on the server. You can set a different location by setting the tmpdir option in your /etc/opencpu/server.conf. There is an example configuration file that sets tmpdir in the /etc/opencpu/server.conf.d/ec2.conf.disabled on your server (rename to activate).

If you don't want to setup an NSF server, a simpler approach is to configure your load balancer to always send particular clients to a particular backend. For example if you use nginx you can set the load balancing method to ip-hash.

Obviously this method requires that clients do not change ip address during the session. And it will only be effective if you have clients connecting from a variation of ip addresses.

Jeroen Ooms
  • 31,998
  • 35
  • 134
  • 207