Skip to content

Process Scaling and Concurrency

Interactive content (Shiny, Streamlit, Dash, Bokeh, APIs) runs in worker processes. Connect decides how many processes to start and how many client connections each one takes. When an app "just stops accepting users" while the VM still has free CPU and memory, the answer is almost always these settings.

The model

For a single app on a single Connect node:

maximum concurrent connections = MaxProcesses x MaxConnsPerProcess

A connection beyond that is rejected or times out, regardless of spare CPU or memory.

Setting Server default Per content override Meaning
Scheduler.MaxProcesses 3 Yes Max worker processes per app, per node
Scheduler.MaxConnsPerProcess 20 Yes Max client connections per process
Scheduler.LoadFactor 0.5 Yes How aggressively new processes start (0 = early, 1 = only when full)
MinProcesses 0 Per content only Processes kept warm (avoids cold starts)
Scheduler.IdleTimeout 5s Yes How long an idle process lives before it is retired
Scheduler.InitTimeout 120s Yes How long an app may take to start
Scheduler.MaxProcessesLimit 20 No Ceiling on any app's MaxProcesses
Scheduler.MinProcessesLimit 10 No Ceiling on any app's MinProcesses

Server values set defaults. Publishers and admins override per app in the content's Settings, Runtime panel, up to the limits.

With the defaults, one app on one node serves 3 x 20 = 60 concurrent connections.1

Worked example

A heavily used Streamlit dashboard behind two Connect nodes:

Parameter Before After
Max connections per process 20 100
Max processes 11 20
Capacity per node 220 2,000
Capacity across 2 nodes 440 4,000

Raising MaxProcesses above 20 also needs Scheduler.MaxProcessesLimit raised in the server config.1 Raising MaxConnsPerProcess only helps if the app can actually serve that many users from one process. Shiny and Streamlit process requests on a single thread per process, so one slow computation blocks every user on that process. For CPU heavy apps, more processes with fewer connections each is better than fewer, fuller processes.

flowchart LR
    C1(["Clients"]) --> LB(["Load balancer<br/>(sticky sessions)"])
    LB --> N1("Node 1")
    LB --> N2("Node 2")
    N1 --> P1("Process 1 ... Process 20<br/>100 connections each")
    N2 --> P2("Process 1 ... Process 20<br/>100 connections each")
    style N1 fill:#fdf1e3,stroke:#c9822b,stroke-width:2px,color:#1a1a1a
    style N2 fill:#fdf1e3,stroke:#c9822b,stroke-width:2px,color:#1a1a1a
    style P1 fill:#fdf1e3,stroke:#c9822b,stroke-width:2px,color:#1a1a1a
    style P2 fill:#fdf1e3,stroke:#c9822b,stroke-width:2px,color:#1a1a1a

Memory is the real ceiling

Each process loads the app and its data. A Shiny app that holds 1.5 GB in memory and runs 20 processes needs 30 GB on that node for one app. Size MaxProcesses from memory first:

MaxProcesses <= (node memory reserved for this app) / (memory per process)

In native (non Kubernetes) execution, Scheduler.MemoryLimit caps a process with setrlimit(RLIMIT_AS), which limits virtual address space, not resident memory.1 Some runtimes reserve large virtual address spaces at startup and fail under a limit that looks generous. Test before applying it broadly.

Watch processes during a load test:

ps -eo pid,user,rss,etime,cmd --sort=-rss | head -20

Load balancers and scaling

Connect HA requires cookie based sticky sessions and websocket support at the load balancer.2 Shiny holds state in a specific process on a specific node; without stickiness, a user bounces between nodes and their session breaks. Do not turn stickiness off to "spread load".

Things to know about cloud load balancers (Azure Application Gateway, AWS ALB):

  • Balancing is per new session, using round robin or least connections. They do not know an app's internal connection limit, so a nearly full node still receives new users.
  • Health probes should hit a lightweight endpoint. Connect answers /__ping__ without authentication; check it against your version.3
  • A node that is restarting or resizing must fail its probe and drain before it stops. Otherwise the users on it are dropped.

Horizontal scaling (adding nodes behind a load balancer) requires the Enhanced license tier or higher. Posit recommends tuning and vertical scaling (bigger VMs) first, then moving to horizontal scaling once a single node's compute is no longer the bottleneck.45 If you are already running HA, prefer adding a node over resizing an existing one. Resizing removes the node from the pool, and during that window all the traffic lands on the remaining nodes. This may push them over the per-app limits mentioned above.

Timeouts

Defaults below are from the [Scheduler] section of the configuration reference.1

Setting Default Notes
Scheduler.ConnectionTimeout 1h Max time with no data across a client connection; 0 disables (not recommended)
Scheduler.ReadTimeout 1h Max time without data received from the client
Scheduler.InitTimeout 120s Raise for apps that load large data at startup, or better, move the data load to a pin or database
Scheduler.IdleTimeout 5s Raise (or use MinProcesses) to avoid cold starts on rarely used apps

Checklist for a slow or rejecting app

  1. Read the app's logs in the Connect dashboard; look for startup time and errors
  2. Compare peak concurrent users with MaxProcesses x MaxConnsPerProcess x nodes
  3. Check memory per process and node memory headroom
  4. Check whether one long computation blocks a process (move it to an async task, a database, or a scheduled job)
  5. Set MinProcesses for apps that must respond instantly
  6. Confirm load balancer stickiness and health probes
  7. Add a node before resizing the existing ones

Connect exposes Shiny session counts, job queue depth, and HTTP request metrics through Prometheus and OpenTelemetry for capacity planning; see Operational metrics.