FOCUSCurrently working on ScheduleSomething and LayerdEvents algorithmsLearn More
FOCUSCurrently working on ScheduleSomething and LayerdEvents algorithmsLearn More
FOCUSCurrently working on ScheduleSomething and LayerdEvents algorithmsLearn More
FOCUSCurrently working on ScheduleSomething and LayerdEvents algorithmsLearn More
CONTRIBUTING.MdOperations & Runbooks
Performance & Tuning
DocsCONTRIBUTING.mdOperations & RunbooksPerformance & Tuning
GitHub Live Sync

Performance & Tuning

Live technical documentation fetched from GitHub repository omghante/metapilot/docs/operations/performance.md

Performance Tuning & Optimization Guide

This guide details database indexing, Celery worker concurrency, Redis channel tuning, and caching strategies for MetaPilot.

1. Database Indexing & Query Optimizations

Critical Database Indexes

  • users_user.email
    : Fast JWT login lookup.
  • messaging_conversation.customer_phone
    : Instant phone number matching on incoming webhooks.
  • messaging_message.wamid
    : Immediate status updates for incoming receipts (
    delivered
    ,
    read
    ).
  • tenants_tenantconfig.tenant_id
    : Rapid key retrieval during broadcast execution.

Query Tuning Rules

  • Always use
    select_related
    and
    prefetch_related
    in ViewSets to prevent N+1 query overhead:
    python
    queryset = Message.objects.select_related('conversation', 'conversation__tenant').all()
    

2. Celery Worker Concurrency & Batch Sizing

  • Concurrency: Set
    --concurrency=4
    per worker container (or 2x CPU cores).
  • Batch Sizing:
    SCHEDULER_BATCH_SIZE = 20
    (optimal for Meta Graph API REST throughput without triggering memory overhead).
  • Rate Limit Token Bucket: Enforce 50 msgs/sec in
    rate_limiter.py
    .

3. Redis Channel Layer Optimization

  • Capacity Tuning: Set
    capacity=1500
    in
    CHANNEL_LAYERS
    setting to handle peak WebSocket frame spikes.
  • Message Expiry: Set
    expiry=60
    seconds to automatically purge stale disconnected WebSocket frames.