Skip to content

Commit 387922e

Browse files
committed
chore: move bench testing to own SQL script
1 parent 16a7f47 commit 387922e

File tree

2 files changed

+39
-39
lines changed

2 files changed

+39
-39
lines changed

nix/bench.sql

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
create view pg_net_stats as
2+
select
3+
count(*) filter (where error_msg is null) as request_successes,
4+
count(*) filter (where error_msg is not null) as request_failures,
5+
(select error_msg from net._http_response where error_msg is not null order by id desc limit 1) as last_failure_error
6+
from net._http_response;
7+
8+
create or replace procedure repro_timeouts(number_of_requests int default 10000, url text default 'http://server/post') as $$
9+
declare
10+
last_id bigint;
11+
first_time timestamptz;
12+
second_time timestamptz;
13+
time_taken interval;
14+
begin
15+
delete from net._http_response;
16+
17+
with do_requests as (
18+
select
19+
net.http_post(url, jsonb_build_object('id', x, 'message', 'payload ' || x), headers:=jsonb_build_object('Content-Type', 'application/json')) as id
20+
from generate_series (1, number_of_requests) x
21+
)
22+
select id, clock_timestamp() into last_id, first_time from do_requests offset number_of_requests - 1;
23+
24+
commit;
25+
26+
raise notice 'Waiting until % requests complete', number_of_requests;
27+
28+
perform net._await_response(last_id);
29+
30+
select clock_timestamp() into second_time;
31+
32+
select age(second_time, first_time) into time_taken;
33+
34+
raise notice 'Stats: %', (select to_json(x) from pg_net_stats x limit 1);
35+
36+
raise notice 'Time taken: %', time_taken;
37+
end;
38+
$$ language plpgsql;

nix/nixops.nix

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -114,45 +114,7 @@ in {
114114
};
115115
initialScript = pkgs.writeText "init-sql-script" ''
116116
create extension pg_net;
117-
118-
create view pg_net_stats as
119-
select
120-
count(*) filter (where error_msg is null) as request_successes,
121-
count(*) filter (where error_msg is not null) as request_failures,
122-
(select error_msg from net._http_response where error_msg is not null order by id desc limit 1) as last_failure_error
123-
from net._http_response;
124-
125-
create or replace procedure repro_timeouts(number_of_requests int default 10000, url text default 'http://server/post') as ''$''$
126-
declare
127-
last_id bigint;
128-
first_time timestamptz;
129-
second_time timestamptz;
130-
time_taken interval;
131-
begin
132-
delete from net._http_response;
133-
134-
with do_requests as (
135-
select
136-
net.http_post(url, jsonb_build_object('id', x, 'message', 'payload ' || x), headers:=jsonb_build_object('Content-Type', 'application/json')) as id
137-
from generate_series (1, number_of_requests) x
138-
)
139-
select id, clock_timestamp() into last_id, first_time from do_requests offset number_of_requests - 1;
140-
141-
commit;
142-
143-
raise notice 'Waiting until % requests complete', number_of_requests;
144-
145-
perform net._await_response(last_id);
146-
147-
select clock_timestamp() into second_time;
148-
149-
select age(second_time, first_time) into time_taken;
150-
151-
raise notice 'Stats: %', (select to_json(x) from pg_net_stats x limit 1);
152-
153-
raise notice 'Time taken: %', time_taken;
154-
end;
155-
''$''$ language plpgsql;
117+
${builtins.readFile ./bench.sql}
156118
'';
157119
};
158120

0 commit comments

Comments
 (0)