You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Centos服务器Shiny Server多应用路径部署加载缓慢问题排查

Troubleshooting Slow Loading Shiny Apps in Subfolders on CentOS

Hey there, let's break down why your subfolder Shiny apps are lagging—this is a common issue with a few key configuration fixes you might have missed. Here's what to check step by step:

1. Adjust Worker Process Limits

By default, Shiny Server might be allocating too few worker processes per app, especially when multiple subfolder apps compete for resources. When a user accesses a subfolder app, Shiny spins up worker processes to handle the request; if the limit is too low, requests queue up and cause slow loads.

Edit your Shiny Server config file (/etc/shiny-server/shiny-server.conf) and tweak these settings in your location block:

server {
  listen 3838;
  location / {
    site_dir /srv/shiny-server;
    log_dir /var/log/shiny-server;
    directory_on; # Critical for recognizing subfolder apps
    
    # Worker tuning (adjust based on your server's CPU cores)
    workers 4; # Start with 1-2x your CPU core count
    app_init_timeout 60; # Give apps more time to initialize
    app_idle_timeout 300; # Keep idle apps alive longer to avoid re-spinning
    max_requests 500; # Recycle workers after a set number of requests to prevent memory leaks
  }
}

Restart Shiny Server after making changes:

sudo systemctl restart shiny-server

2. Fix File Permissions

If your subfolder apps have incorrect permissions, the shiny system user (which runs Shiny Server) might be stuck repeatedly trying to access files, causing delays. Ensure all subfolders and files under /srv/shiny-server are readable (and writable if your apps need it) by the shiny user:

sudo chown -R shiny:shiny /srv/shiny-server
sudo chmod -R 755 /srv/shiny-server

This eliminates permission-related bottlenecks that slow down app initialization.

3. Optimize R Package Loading

Each subfolder app might be loading the same R packages from separate locations or re-compiling them on startup, which adds significant lag. To fix this:

  • Set a global R library path for all Shiny apps by adding an env block to your shiny-server.conf:
    env {
      R_LIBS_USER="/usr/local/lib/R/site-library" # Use your system-wide R library path
    }
    
  • Preload frequently used packages in your apps with library(package, warn.conflicts = FALSE) to reduce startup checks.
  • Consider using packrat or renv for consistent package versions, but ensure the libraries are accessible to the shiny user.

4. Check Server Resource Constraints

If your server is low on CPU or memory, multiple subfolder apps competing for resources will load slowly. Use tools like htop or free -m to check:

  • htop: Monitor CPU and memory usage in real-time—if you see high CPU load or memory nearing 100%, you might need to upgrade your server or limit per-app resource usage.
  • Add a per_application_memory_limit to your config to prevent single apps from hogging resources:
    per_application_memory_limit 1024; # Limit each app to 1GB of memory (adjust as needed)
    

5. Verify Directory Listing is Enabled

Double-check that directory_on; is present in your location block. This tells Shiny Server to recognize subfolders as valid app locations—without it, the server might be doing extra work to resolve paths, contributing to slowdowns.


内容的提问来源于stack exchange,提问作者kanataki

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 08:48:59