Apéndice G — Performance tuning¶
G.1. Postgres (VPS 8GB RAM)¶
shared_buffers = 2GB
effective_cache_size = 6GB
work_mem = 16MB
maintenance_work_mem = 256MB
wal_buffers = 16MB
checkpoint_completion_target = 0.9
random_page_cost = 1.1
effective_io_concurrency = 200
max_connections = 100
G.2. Índices recomendados¶
CREATE INDEX CONCURRENTLY idx_saleinvoice_ecf_encf
ON accounting_saleinvoice(ecf_encf) WHERE ecf_encf IS NOT NULL;
CREATE INDEX CONCURRENTLY idx_saleinvoice_trackid
ON accounting_saleinvoice(ecf_trackid) WHERE ecf_trackid IS NOT NULL;
CREATE INDEX CONCURRENTLY idx_ecfenvio_trackid ON accounting_ecfenviodgii(trackid);
CREATE INDEX CONCURRENTLY idx_ecfenvio_created ON accounting_ecfenviodgii(created_at DESC);
CREATE INDEX CONCURRENTLY idx_saleinvoice_fecha_estado
ON accounting_saleinvoice(fecha_emision, ecf_estado)
WHERE ecf_estado IN ('ACEPTADO', 'ACEPTADO_CONDICIONAL');
CREATE INDEX CONCURRENTLY idx_stockmove_almacen_producto
ON inventory_stockmove(almacen_id, producto_id, tipo_movimiento);
CREATE INDEX CONCURRENTLY idx_padron_rnc ON accounting_padrondgii(rnc);
G.3. Gunicorn workers¶
Fórmula: workers = (2 × CPU) + 1, threads = 2. Para VPS 4 vCPU: 9 workers × 2 threads = 18 concurrent.
G.4. Redis tuning¶
G.5. Cache de templates Django¶
TEMPLATES[0]['OPTIONS']['loaders'] = [
('django.template.loaders.cached.Loader', [
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
]),
]