Skip to content

Slow worker start for large jobs table #1454

@frisia-mtz

Description

@frisia-mtz

We noticed a slow start of procrastinate when the procrastinate_jobs table has a huge number of rows.

Procrastinate tries to prune stalled workers and deletes all entries in the procrastinate_workers table.

async def run(self):
"""
Run the worker
This will run forever until asked to stop/cancelled, or until no more job is available is configured not to wait
"""
logger.debug("Pruning stalled workers with old heartbeats")
pruned_workers = await self.app.job_manager.prune_stalled_workers(
self.stalled_worker_timeout
)

The procrastinate_workers.id is referenced by a foreign key in the procrastinate_jobs table column worker_id which is set to NULL if the worker entry is deleted.

worker_id bigint REFERENCES procrastinate_workers(id) ON DELETE SET NULL,

With ~13 million succeeded jobs which still have a worker_id, this delete-operation takes several minutes per worker.

My suggestion would be to set the procrastinate_jobs.worker_id to NULL if the state of the job changes from doing to anything else.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions