R Shiny at IQSS
  • Introduction
  • Getting started
    • Determining your resource requirements
    • Applying for an account
  • Deploying
    • Setup your environment
    • Deploying an example Shiny app
    • Bootstrapping a new Shiny app or migrating a pre-existing Shiny application
    • Developing locally with RStudio
    • Developing locally using Docker
    • Speeding up deployments with Packrat
  • Configuration
    • Setting up a custom domain for your Shiny app
    • Installing additional system-level packages
    • Limiting the number of R Threads
  • Best Practices
    • File storage
    • Using promises
    • Adding routes
  • Troubleshooting
    • Resolving Application Error screen
    • Viewing app logs
    • Viewing resource consumption
    • Configuring Shiny session auto-reconnect
    • Getting support
Powered by GitBook
On this page
  1. Configuration

Limiting the number of R Threads

PreviousInstalling additional system-level packagesNextBest Practices

Last updated 5 years ago

R is single threaded, meaning that R can only execute one instruction at a time. This makes developing web applications in R which users expect to be highly performant hard. Long running computations will prevent multiple users from viewing your site concurrently.

There are a few design suggestions explored in that can make a large impact, however, the IQSS Shiny toolchain enables basic concurrency for your Shiny applications through the use of load balancing.

The Shiny IQSS toolchain launches as many R processes as there are CPUs, divided by two. Shiny by itself takes up around 60 to 100MiB of memory without performing any work, so using a 1:1 mapping of R process to CPU would most likely result in an out of memory error in most cases.

If your application uses a lot of memory, the default of CPUs / 2 may still result in out of memory errors. You can manually set the number of R processes to launch by adding the environment variable R_NUM_PROCS to your Heroku depoyment.

Using only 1 R process.

Open the settings tab of your Shiny app on Heroku and click Reveal Config Vars.

In KEY, enter R_NUM_PROCS.

In VALUE, enter 1.

Then, click ADD

Click More in the upper-right hand corner and select Restart all dynos. This is disruptive - if you only have one dyno, user connections will be severed. When your application is restarted, your application will only launch 1 R process.

Best Practices
Click Reveal config vars under Settings
Click Restart all dynos