Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shiny app unstable at many simultaneous requests

I have built a quiz system using Shiny Server on Amazon Web Services. The system runs reliably when I tested it on one or two devices at home. However when I used it in the classroom with more than 10 students the system broke down. The questions and widgets loaded correctly, but when the students tried to submit their answers (after 30 - 40 minutes looking at them) the data was not handled correctly (results are saved in a csv file so I could see that).

I understand that there can be many causes for this, but I would like to know whether one might be that Shiny server is just not designed to handle many simultaneous requests. This would mean I can just forget about using Shiny for my purposes and look elsewhere. For those who are interested in the system, here is the code:

https://github.com/witusj/CFA-2/tree/master/WK4

Many thanks!

like image 915
user3819568 Avatar asked Sep 23 '14 19:09

user3819568


2 Answers

It depends on the complexity of your app and the server you host it on. There is an explanation by one of their developers here, although there are no clear guidelines.

Since you have students you can test on, you may be able to get an estimate of how many users the application will be able to handle correctly, and use this number to set a limit to the number of people who can join. If you look at the manual you will find the "Simple Scheduler" to do this. To use the example out of the manual, if you want to limit the number of connected students to 5, you would add simple_scheduler to you configuration:

location / {
  # Define the scheduler to use for this location
  simple_scheduler 5; 
  ...
}

Since you have more than 5 students, set multiple copies of the application under a number of different locations. You can extend this using the load balancing idea of Huidong Tang, or an implementation of that idea by sjewo.

like image 110
FvD Avatar answered Sep 28 '22 21:09

FvD


What @FvD said. But additionally, bear in mind that there's shinyapps.io if you want someone else to host your application in a scalable way, or Shiny Server Pro if you want to back a Shiny application with multiple R processes.

Shiny Server itself can certainly handle plenty of requests (we've seen a single Shiny Server instance gracefully handle up to a thousand concurrent users) -- and it had plenty of room for more -- but as @FvD described, it all comes down to how well your R application scales.

One caveat here: there is a bit of complexity to think through in an application like yours. If you write all your data out to a single .csv file, then you can't safely run multiple instances of the application simultaneously (the processes would be overwriting each other's file). Instead, you could consider writing out the results into a bunch of distinct CSV files which can be aggregated together later, or you could look at using something like a relational database to really do this right. This problem is described in more detail here.

like image 24
Jeff Allen Avatar answered Sep 28 '22 22:09

Jeff Allen