Created
February 24, 2022 10:08
-
-
Save marcocitus/ead423e18d5d16ec97a1315615a96076 to your computer and use it in GitHub Desktop.
Citus cluster response times function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE OR REPLACE FUNCTION latency(nodename text, nodeport int) | |
RETURNS double precision | |
AS $$ | |
DECLARE | |
start_time timestamptz; | |
end_time timestamptz; | |
BEGIN | |
/* warm up connection cache */ | |
perform master_run_on_worker(array[nodename], array[nodeport], array['select 1'], false); | |
/* measure response time of a simple query */ | |
start_time := clock_timestamp(); | |
perform master_run_on_worker(array[nodename], array[nodeport], array['select 1'], false); | |
end_time := clock_timestamp(); | |
/* return response time in milliseconds */ | |
return 1000. * (extract(epoch from end_time) - extract(epoch from start_time)); | |
END; | |
$$ LANGUAGE plpgsql; | |
select create_distributed_function('latency(text,int)'); | |
-- for each node n: run `select latency(n)` on all workers | |
select n.nodename AS fromhost, n.nodeport AS fromport, r.nodename AS tohost, r.nodeport AS toport, success, result::double precision | |
from pg_dist_node n, run_command_on_workers(format('select latency(%L, %L)', nodename, nodeport)) r; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment