Skip to content

Suggestion: Consider changing worker polling to deadline-based scheduling #702

@bhamiltoncx

Description

@bhamiltoncx

Each pg-boss worker currently polls the database every pollingIntervalSeconds seconds (defaulting to 2) checking for new work. This is pretty heavy-weight on the CPU (not to mention having to open a DB connection, etc.).

As an alternative for efficiency (and testability), consider having each worker do a single pass at startup to calculate the next deadline at which work is due, then sleep until either:

  1. The deadline is reached, or
  2. A new job is scheduled, or
  3. An existing job is modified / cancelled

For 2) and 3), we can recalculate the next deadline and update the affected worker(s).

I don't know if this might be impacted by database replication, of course, so we'd have to take that into account.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions