-
-
Notifications
You must be signed in to change notification settings - Fork 78
Open
Description
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.
procrastinate/procrastinate/worker.py
Lines 373 to 381 in 0ece824
| 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
Labels
No labels