I've set up a very basic load-balancing test with Nginx and multiple Shiny-Server 'server' instances, but it seems all traffic gets routed to only a single process, despite multiple servers.
First, the Shiny-Server setup (conf) is as follows:
run_as shiny;
server {
listen 9001;
location /users {
run_as :HOME_USER:;
user_dirs;
directory_index on;
}
location / {
site_dir /srv/shiny-server;
log_dir /var/log/shiny-server;
directory_index on;
}
}
server {
listen 9002;
location /users {
run_as :HOME_USER:;
user_dirs;
directory_index on;
}
location / {
site_dir /srv/shiny-server;
log_dir /var/log/shiny-server;
directory_index on;
}
}
The (very) simple Shiny app has a server that looks like so:
library(shiny)
server_pid <- Sys.getpid()
server_id <- uuid::UUIDgenerate()
server <- function(input, output, session) {
output$debug <- renderPrint({
print(sprintf("pid: %s, id: %s", server_pid, server_id))
})
}
And the UI simply displays those two values.
Now, regardless of hitting that test application on localhost:9001
or localhost:9002
, I see the same IDs for both connections. To verify this, I indeed only see a single R process in the background, despite having two simultaneous connections to both ports.
My thought had been that each server block in the Shiny Server config file specifies a new 'source' for firing up R processes for each app, but apparently regardless of the server instance, all traffic for a specific app goes to the same R server process ... can anyone else verify this? And if so, is there a way to actually load balance such that multiple connections to the same app are spread across multiple R server processes?
Also (to answer the inevitable question), yes: I realize already that having distinct R server processes for the same app means no shared server state, and that's all right for my application. The goal is to handle many possible connections and with R being single-threaded I want to spread the load across multiple R server processes.