Performance
Startup Pipeline
Section titled “Startup Pipeline”- Fiber server binds and exposes
/api/v1/health/live. - Database migrations run while pgx + Redis pools warm (
MaxConns=15,MinConns=2). - Default admin allowlist, templates, and share-link caches load asynchronously.
- WebSocket hub spins up Redis pub/sub channels.
Key toggles (defaults shown):
LAZY_INIT_ADMIN=trueASYNC_TEMPLATE_SEED=trueSKIP_MIGRATION_CHECK=falseREDIS_POOL_SIZE=10Disable async flags only when deterministic ordering is required for benchmarking.
Crypto & Storage Hot Paths
Section titled “Crypto & Storage Hot Paths”- Client traces handle bulk encryption; the backend’s heavy operations are Argon2id password checks and HMAC keyword search. Reserve at least one full CPU core for the backend or Argon2 throttles.
- Monitor PostgreSQL with
pg_stat_statements;leaflock_notes_totalspikes often indicate imports or key rotation jobs. - Maintain healthy indexes—see
/architecture/database-schemafor expected partial indexes.
WebSocket Throughput
Section titled “WebSocket Throughput”- Collaboration traffic depends on low-latency Redis pub/sub. Keep network RTT < 50 ms.
- Align load balancer idle timeouts ≥ 120 s; otherwise sockets close and users see cursor drops.
- Track
leaflock_websocket_connectionsvsleaflock_active_users; divergence suggests ingress issues.
Caching & Pools
Section titled “Caching & Pools”- Permission lookups batch inside
services/workspace_service.go. EnsureCACHE_WORKSPACE_PERMISSIONS=truein production. - Increase
REDIS_POOL_SIZEgradually and watchleaflock_redis_connections_activeto avoid hitting ulimit. - For high export volume, raise
IMPORT_EXPORT_WORKERS(backend env) to parallelize encryption tasks.
Observability Checklist
Section titled “Observability Checklist”- Set
LOG_LEVEL=info. Switch todebugonly during incident response. - Key metrics to watch (see
/operations/monitoring):leaflock_http_request_duration_secondsp95 < 500 ms.leaflock_backup_duration_secondswithin established SLO.leaflock_db_connections_activenearMaxConns→ tune pool or database size.
- Use
docs/grafana-dashboard.jsonas a baseline; add custom panels per deployment.
Troubleshooting Slow Boots
Section titled “Troubleshooting Slow Boots”- Long migration window → run
make migratemanually before scaling replicas; keepSKIP_MIGRATION_CHECK=falsein production. - Redis handshake delays → observe logs for
pubsub handshake took; increaseREDIS_DIAL_TIMEOUTor move Redis closer. - Aggressive health probes → liveness should hit
/api/v1/health/live, readiness/api/v1/health/ready; wrong probes churn pods. - CPU throttling → on Kubernetes request ≥
500mCPU; Argon2id needs consistent CPU access.
LeafLock ships with safe defaults. Use metrics to justify every tuning change and document the outcome for future operators.