Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Handler ¶
Handler returns an http.Handler that proxies requests to Shiny app workers. It manages session cookies, cold-starts workers on demand, and forwards HTTP and WebSocket traffic.
The returned handler captures a shared WsCache and http.Transport that persist for the server's lifetime.
func RedirectTrailingSlash ¶
func RedirectTrailingSlash(w http.ResponseWriter, r *http.Request)
RedirectTrailingSlash redirects /app/{name} to /app/{name}/. Shiny apps use relative URLs for assets and WebSocket connections, so the trailing slash is required for correct path resolution.
func RunAutoscaler ¶ added in v0.0.2
RunAutoscaler runs as a background goroutine alongside health polling. On each tick it:
- Sweeps sessions that have been idle longer than the configured TTL.
- Marks workers with zero sessions as idle (sets IdleSince).
- Evicts workers that have been idle beyond idle_worker_timeout.
- Evicts workers that have crashed (health check fails).
- Spawns a new worker if all existing workers are at capacity and the per-app and global limits allow it (eager scale-up).
- Maintains pre-warmed worker pools for configured apps.
Blocks until ctx is cancelled.
Types ¶
type LoadBalancer ¶ added in v0.0.2
type LoadBalancer struct{}
LoadBalancer assigns new sessions to workers using a least-loaded strategy. Stateless — decisions are based on current worker and session state at call time.
func (*LoadBalancer) Assign ¶ added in v0.0.2
func (lb *LoadBalancer) Assign( appID string, workers server.WorkerMap, sessions session.Store, maxSessionsPerWorker int, maxWorkersPerApp *int, ) (string, error)
Assign picks a worker for a new session belonging to appID.
Returns a worker ID when an existing worker has available capacity. Returns ("", nil) when no worker has capacity but the per-app limit has not been reached — the caller should spawn a new worker. Returns errCapacityExhausted when all workers are full and the per-app limit has been reached.
type WsCache ¶
type WsCache struct {
// contains filtered or unexported fields
}
WsCache holds backend readers after client disconnect. Keyed by session ID. Entries expire after a configurable TTL.
func NewWsCache ¶
func NewWsCache() *WsCache