Command-Line Arguments
Template Worker uses command-line arguments for runtime configuration. All arguments can be passed using the-- prefix.
Worker Type
Type of worker to use. Options:
processpool(alias:process-pool): Uses a process pool for executing tasks. Recommended for productionthreadpool(alias:thread-pool): Uses a thread pool for executing tasksprocesspoolworker(alias:process-pool-worker): Single worker within a process pool (spawned automatically)register(alias:register-commands): Registers Discord commands and exitsmigrate(alias:apply-migration): Applies database migrations and exitsshell(alias:fauxpas): Spawns a Lua shell for debugging
Database Configuration
Maximum number of connections in the PostgreSQL connection poolAdjust based on your database capacity and expected load. Each worker process/thread will create its own pool.
Worker Pool Settings
Number of process workers to use for the process poolIf not specified, defaults to the shard count from Sandwich. Only used when
worker-type is processpool.The worker ID to use when running as a process pool workerOnly used when
worker-type is processpoolworker. Set automatically when spawned by the master process.Runtime Tuning
Number of Tokio runtime threads for the master processUsed by
processpool, threadpool, and shell worker types.Number of Tokio runtime threads for worker processesUsed by individual process pool workers. Each worker still uses a single thread for the Lua VM.
Debugging Options
Enable Tokio Console for async runtime debuggingWarning: May increase resource usage. Only enable when debugging async issues.
Enable debug logging for Lua workersProvides verbose output from Lua VM execution, useful for debugging templates.
Environment Variables
Logging
Rust logging level configurationExamples:
template-worker=info: Info level for the main applicationtemplate-worker=debug,sqlx=warn: Debug for app, warnings for SQLxdebug: Debug level for all modules
Process Pool Workers
Authentication token for Mesophyll IPC clientRequired when running as a process pool worker (
worker-type=processpoolworker). Set automatically by the master process when spawning workers.Usage Examples
Production Deployment (Process Pool)
Development (Thread Pool)
Register Discord Commands
Apply Database Migrations
Debug Shell
Process Pool Worker (Spawned Automatically)
Docker Configuration
When running in Docker, set environment variables indocker-compose.yml:
Configuration Validation
Template Worker validates configuration at startup:- Missing
config.yamlfile will cause immediate exit - Invalid worker type combinations (e.g.,
worker-idwithoutprocesspoolworker) will panic - Missing required environment variables (e.g.,
MESOPHYLL_CLIENT_TOKENfor workers) will panic
Performance Tuning
Database Connections
For production deployments:- Process pool:
--max-db-connectionsshould be 5-10 per process - Thread pool: Can use higher values (10-20) since all threads share one pool
- Monitor your PostgreSQL
max_connectionssetting
Tokio Threads
- Master process: 10 threads handles most workloads well
- Worker processes: 3 threads is sufficient since Lua execution is single-threaded per worker
- Increase if you see high task queue latency in Tokio Console
Process vs Thread Pool
- Process pool: Better isolation, required for production, slightly higher memory usage
- Thread pool: Simpler, good for development, faster startup, shared memory