Repository navigation
Send perf: trim per-email DB work, keep DB connections across batches, per-phase batch timings - #79
Merged
Merged
Conversation
alexeygrigorev
commented
Nov 9, 2026
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.