Skip to content

Send perf: trim per-email DB work, keep DB connections across batches, per-phase batch timings - #79

Merged
alexeygrigorev merged 1 commit into
mainfrom
relay-fix-send-perf-v2
Nov 9, 2026
Merged

alexeygrigorev merged 1 commit into
mainfrom
relay-fix-send-perf-v2

Conversation

@alexeygrigorev

Copy link
Copy Markdown
Member
  • tokens.py: ensure_campaign_recipient_tokens(locked=True) skips the second SELECT FOR UPDATE when the sender already holds the row lock. Queries/email (sqlite marginal, test-measured): 10 -> 9 (Postgres +1 FOR SHARE in both).
  • campaign_sender.py: persistent sender thread pool (Django connections are per-thread) so DB connections survive across batches; close_old_connections hygiene at drain end. Campaign is loaded once per batch (already from Cut per-message send CPU ~60% (GIL-bound worker: 30 -> 45+ msg/s) #73; asserted in test).
  • Batch log line now carries per-phase sum/p50/p95 (lock_sql, render_mime, limiter_wait, ses_call, commit), emails, and worker CPU (process_time); no PII.
  • ses.py: thread-local build/limiter timings; conftest: close pool before test DB drop.
  • SES call stays inside the transaction (out of scope).

…cross batches, per-phase batch timings + worker CPU log
@alexeygrigorev
alexeygrigorev merged commit 5595352 into main Nov 9, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant