fix: only notify pollers when a job becomes eligible - #137
Merged
Conversation
The job_executions UPDATE trigger fired pg_notify('job_events',
'execution_ready') on every execute_at change. The poll query's own
UPDATE sets execute_at = NULL when taking a job, and reclaim/reschedule
writes do the same — so every job taken woke every poller (including
the taker) to immediately re-poll, multiplying poll load linearly with
throughput. At 10 jobs/s that is 10+ self-triggered polls/s.
Restrict the UPDATE branch to rows that remain in the pending set
(NEW.state = 'pending'), i.e. genuine (re-)schedules. INSERT and
DELETE behavior is unchanged.
nicolasburtey
marked this pull request as ready for review
July 28, 2026 13:10
nicolasburtey
force-pushed
the
fix/notify-only-when-eligible
branch
from
July 28, 2026 13:11
6f0c0b5 to
b136d48
Compare
bodymindarts
approved these changes
Jul 28, 2026
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.
Motivation
During a 10 loans/s stress test of a lana-bank sandbox (
stress-testingpreset), thejob_executionspoll query showed a mean execution time of 320–374ms and the poller was one of the top DB-time consumers. Analysis of the wake-up path shows the poller wakes itself up: thejob_executionsUPDATE trigger firespg_notify('job_events', 'execution_ready')on everyexecute_atchange — including the poll query's ownUPDATE ... SET execute_at = NULLwhen taking a job,reclaim_lost_jobsreschedules, and per-attempt failure reschedules.Every job taken therefore notifies every poller to immediately re-poll. Poll load scales multiplicatively with job throughput: at 10 jobs/s that is 10+ self-triggered polls/s on top of organic wake-ups.
Change
Restrict the UPDATE branch of
notify_job_event()to rows that remain eligible —NEW.state = 'pending'— so only genuine (re-)schedules notify:state: pending → running,execute_at → NULL): no notify ✅ (was notify)pending, newexecute_at): notify (unchanged)reclaim_lost_jobs(state → pending, newexecute_at): notify (unchanged)execution_readyto free queue-blocked jobs)Notes
lana/app/migrations/20250904065521_job_setup.sql) need the same edit when bumping the crate.