Skip to content

5.9ms drift per second on job with interal of '1 second' #401

@kairoswater-jason

Description

@kairoswater-jason

I'm not sure if this is expected behavior or not.

Using pg_cron 1.6.4 (the version is installed by default in PostgreSQL 16.6 databases in AWS RDS).
I'm not sure if it would apply to 1.6.5

When I schedule a job to occur at an interval of '1 second' the number of times it executes per second is slightly slower than one second. In the testcase below the actual interval averages out to 1.0059 seconds over a time span of 1000 seconds.

Information for reproduction

CREATE SCHEMA cron_test AUTHORIZATION jason;
CREATE SEQUENCE cron_test.table_seconds_id_seq
	INCREMENT BY 1
	MINVALUE 1
	MAXVALUE 9223372036854775807
	START 1
	CACHE 1
	NO CYCLE;-- cron_test.table_seconds definition

CREATE TABLE cron_test.table_seconds (
	id bigserial NOT NULL,
	"time" timestamptz NOT NULL,
	CONSTRAINT table_seconds_pk PRIMARY KEY (id)
);

INSERT INTO cron.job
(jobid, schedule, command, nodename, nodeport, "database", username, active, jobname)
VALUES(1, '1 second', '
	INSERT INTO cron_test.table_seconds
	("time")
	VALUES(now());
', 'localhost', 5432, 'jason_test', 'jason', false, 'test-every-1-second');
--after letting run for a short while
SELECT EXTRACT(EPOCH FROM (t2.time - t1.time) ) AS time_delta 
FROM jason_test.cron_test.table_seconds AS t1, jason_test.cron_test.table_seconds AS t2 
WHERE t1.id = 2000 AND t2.id = 3000

-- Result: time_delta = 1005.902082

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