pg_cron icon indicating copy to clipboard operation
pg_cron copied to clipboard

Crons not running in parallel

Open slightwv opened this issue 2 years ago • 2 comments

When cron.use_background_workers is on, all cron jobs wait for the longest running job then kick off again.

Setup: create a procedure that only sleeps:

create or replace procedure test_cron(sleep_time integer)
language plpgsql
as $$
begin
	perform pg_sleep(sleep_time);
end;
$$;

Schedule several crons that sleep different times:

select schedule('test_a', '* * * * *', 'call cron.test_cron(25);');
select schedule('test_b', '* * * * *', 'call cron.test_cron(55);');
select schedule('test_c', '* * * * *', 'call cron.test_cron(85);');
select schedule('test_d', '* * * * *', 'call cron.test_cron(300);');

When cron.use_background_workers is off, test_a runs every minute as expected. test_d runs every 5 minutes as expected.

When cron.use_background_workers is on, all 4 run every 5 minutes.

slightwv avatar Aug 25 '22 11:08 slightwv

Looks like that https://github.com/citusdata/pg_cron/pull/152 introduced the issue. Did a few tests and the issue was not there on v1.3.1.

bdrouvotAWS avatar Sep 16 '22 07:09 bdrouvotAWS

@marcocitus what do you think about making the QUEUE_SIZE configurable and revert the fix in https://github.com/citusdata/pg_cron/pull/152?

bdrouvotAWS avatar Sep 16 '22 07:09 bdrouvotAWS

This place is very strange, something doesn't feel right

image

TsinghuaLucky912 avatar Dec 15 '22 03:12 TsinghuaLucky912

@marcocitus I think the completion of the task has no necessary relationship with the state of GetBackgroundWorkerPid, right?

TsinghuaLucky912 avatar Dec 15 '22 03:12 TsinghuaLucky912

Definitely hope to see this bug fixed as I just discovered it in the worst way possible today. Will use connections rather than background workers for now.

caseyandgina avatar Jan 01 '23 07:01 caseyandgina