This guide provides comprehensive performance optimization strategies for Readur deployments, from small personal instances to large enterprise installations.
# postgresql.confmax_connections=200shared_buffers=256MB# 25% of available RAMeffective_cache_size=1GB# 50-75% of available RAMwork_mem=4MB
maintenance_work_mem=64MB
# Write performancecheckpoint_segments=32checkpoint_completion_target=0.9
wal_buffers=16MB
# Query optimizationrandom_page_cost=1.1# For SSD storageeffective_io_concurrency=200# For SSDdefault_statistics_target=100
-- Essential indexes for performanceCREATEINDEXCONCURRENTLYidx_documents_user_createdONdocuments(user_id,created_atDESC);CREATEINDEXCONCURRENTLYidx_documents_ocr_statusONdocuments(ocr_status)WHEREocr_statusIN('pending','processing');CREATEINDEXCONCURRENTLYidx_documents_searchONdocumentsUSINGgin(to_tsvector('english',content));-- Partial indexes for common queriesCREATEINDEXCONCURRENTLYidx_recent_documentsONdocuments(created_atDESC)WHEREcreated_at>CURRENT_DATE-INTERVAL'30 days';
#!/bin/bash# maintenance.sh - Run weekly# Vacuum and analyzedocker-composeexecpostgresvacuumdb-Ureadur-dreadur-z-v
# Reindex for better performancedocker-composeexecpostgresreindexdb-Ureadur-dreadur
# Update statisticsdocker-composeexecpostgrespsql-Ureadur-dreadur-c"ANALYZE;"# Clean up old data via database queriesdocker-composeexecreadurpsql-Ureadur-dreadur-c\"DELETE FROM sessions WHERE last_activity < NOW() - INTERVAL '30 days';"# Check for orphaned filesdocker-composeexecreadurpsql-Ureadur-dreadur-c\"SELECT COUNT(*) FROM documents WHERE file_path NOT IN (SELECT path FROM files);"
# Optimize based on CPU cores and RAMOCR_WORKERS=4# Number of parallel workersOCR_MAX_PARALLEL=8# Max concurrent OCR operationsOCR_QUEUE_SIZE=1000# Queue buffer sizeOCR_BATCH_SIZE=10# Documents per batchOCR_TIMEOUT=300# Seconds per document# Memory managementOCR_MAX_MEMORY_MB=1024# Per worker memory limitOCR_TEMP_DIR=/tmp/ocr# Use fast storage for temp files# Tesseract optimizationTESSERACT_THREAD_LIMIT=2# Threads per OCR jobTESSERACT_PSM=3# Page segmentation modeTESSERACT_OEM=1# OCR engine mode (LSTM)
# Mount options for better performance/dev/sdb1/dataext4defaults,noatime,nodiratime,nobarrier02# For XFS/dev/sdb1/dataxfsdefaults,noatime,nodiratime,allocsize=64m02# Enable compression (Btrfs)mount-ocompress=lzo/dev/sdb1/data
# Gunicorn settingsGUNICORN_WORKERS=4# 2-4 x CPU coresGUNICORN_WORKER_CLASS=uvicorn.workers.UvicornWorker
GUNICORN_WORKER_CONNECTIONS=1000GUNICORN_MAX_REQUESTS=1000GUNICORN_MAX_REQUESTS_JITTER=50GUNICORN_TIMEOUT=30GUNICORN_KEEPALIVE=5# Thread poolGUNICORN_THREADS=4GUNICORN_THREAD_WORKERS=2
upstreamreadur_backend{least_conn;# Or ip_hash for session affinityserverbackend1:8000weight=5max_fails=3fail_timeout=30s;serverbackend2:8000weight=5max_fails=3fail_timeout=30s;serverbackend3:8000weight=3backup;keepalive32;}