Polished hosting now has a load balancer! Our load balancer distributes user sessions across multiple running instances of your Shiny app. The load balancer keeps your app running quickly as you scale to more and more users.
The Polished Hosting load balancer uses a "max_sessions" option to determine when to spin up
additional Shiny app instances. Once your app reaches the maximum number of user sessions, the load balancer
automatically starts a new instance. The max number of
sessions can be set with the "max_sessions" argument of
polished::deploy_app(). For example, if you
set "max_sessions" to 5, then the first 5 user sessions are directed to the first app instance, and
Polished Hosting will start a second app instance for the 6th session. This second app instance will
serve sessions 6 through 10, and a 3rd app instance will be started for the 11th session, etc.
The load balancer detects when sessions become inactive and allocates new sessions to the instance with the fewest active sessions.
To monitor the load balancer, we created a very basic dashboard at "your app url/__polished__" where you can view your app instances and see a summary of total and active sessions per instance. This is what it looks like with 2 app instances running:
The 2 gray boxes above are the 2 running app instances of my app on Polished Hosting. For the above example, I have "max_sessions" set to 2, and there are 3 total user sessions (2 on the first instance and 1 on the second instance).
To enable the load balancer on your Shiny app, install the latest dev version of polished from GitHub with:
Then set the "max_sessions" argument of
deploy_app() to any positive integer to deploy your
app with load balancing enabled. e.g.
polished::deploy_app( app_name = "your_app_name", api_key = "your Polished API key", max_sessions = 7 )
For apps with long running R calculations you will want to set the "max_sessions" to a low value. You can even set it to 1 to have only 1 session per app instance. Just keep in mind that setting "max_sessions" to 1 will start a new app instance for every session. The more app instances you start, the more CPU you use and the slower your server runs. For best performance you'll want to set the "max_sessions" to the highest amount of sessions that your app can handle before significant performace degredation.
This is still a very early release, so we'd love to hear your feedback. Let us know if you have questions or feature requests.