Custom load balancing for RStudio Workbench / RStudio Server Pro


RStudio Workbench (previously RStudio Server Pro) gives you the ability to load balance by session, by user hash, or by server load. But it also gives you the ability to add your own custom load balancing script to make load balancing decisions. Specifics can be found in the RStudio Workbench admin guide.

First, configure RStudio Workbench to accept custom load balancing in /etc/rstudio/load-balancer(Note: As of the 2021.09.0 "Ghost Orchid" release, the [config] header is optional):

balancer = custom

Second, create a new bash script at:


This script will be passed two environment variables: RSTUDIO_USERNAME — The user on behalf or which the new R session is being created. RSTUDIO_NODES — Comma separated list of the IP address and port of available nodes. The script should return the node to start the new session on using its standard output. Note that the format of the returned node should be identical to its format as passed to the script (i.e., include the IP address and port).

The example below load balances by randomly selecting an RStudio node for each new session: 

#!/usr/bin/env bash

# Assuming input is comma-separated, no spaces

# reads node list into an array

# selects random node from array and returns it to stdout