Theshinyloadtestpackage and the accompanyingshinycannoncommand line tool make it possible toload testdeployed Shiny apps. Load testing helps developers and administratorsestimate how many users their application can support. If an applicationrequires tuning, load testing and load test result analysis can be usedto identify performance bottlenecks and to guide changes toinfrastructure, configuration, or code.
Scientific load testing helps put to rest the common misconceptionthat “Shiny doesn’t scale”. As rstudio::conf(2018) Sean Lopp presentedonScalingShiny which shows how to to horizontally scale an app to handle tensof thousands of users.
To perform a load test you’ll need two pieces of software:
shinyloadtest is an R package used to generaterecordings and analyze results. You should install it on yourdevelopment machine withinstall.packages("shinyloadtest").shinycannon is a command-line used to replay recordingsin parallel. You can install it on your development machine for testing,but for best results we recommend installing it on a server, andpreferably not the one the application under test is also on. Seeinstallationinstructions for operating specific install instructions..The process for load testing a Shiny application consists of threesteps:
Rinse and repeat as necessary. Each step is described below.
Record a session usingshinyloadtest::record_session(),which takes the URL of thedeployed application as anargument:
shinyloadtest::record_session("https://shinyapp.example.com/")Running the function will open a browser displaying the app. Onceopen, interact with the application as a typical user might then closethe browser. After closing the app, a file (recording.logby default) will be created that contains a recording of the session.This recording will serve as the basis for the load test.
If your application requires authentication, consult theauthenticationarticle. Also be aware thatcertainShiny features are not compatible with shinyloadtest.
With the recording in hand, we’re ready to run the load test. Theactual test is conducted outside of R using theshinycannoncommand-line tool. You can run it using your system’s terminal orconsole program, or you can run it from the RStudio IDE’s terminal tab.A typical run looks like this:
shinycannon recording.log https://shinyapp.example.com/ --workers 5 --loaded-duration-minutes 2 --output-dir run1(On Windows, you will need to replace “shinycannon” withjava -jar shinycannon-VERSION.jar.)
Seetheshinycannon article for details.
Now we can analyse our results by reading the data intoshinyloadtest::load_runs() and create a report withshinyloadtest_report():
df<- shinyloadtest::load_runs("run1")shinyloadtest::shinyloadtest_report(df,"run1.html")This self contained html report will be opened in your browser forinspection. For further analysis explanation, please visitAnalysingload test logs.
