Skip to content

Commit a90eb5f

Browse files
committed
add pgbench-tuned wrapper command
It wraps the host it should target and the number of jobs (-j) is tuned according to the PostgREST pool size.
1 parent cf6a78a commit a90eb5f

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

nixops.nix

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,16 @@ in {
258258
client = {nodes, resources, ...}: {
259259
environment.systemPackages = [
260260
pkgs.k6
261-
pkgs.postgresql_12 # only used for getting pgbench, no postgresql is started here
261+
(pkgs.writeShellScriptBin "pgbench-tuned"
262+
''
263+
set -euo pipefail
264+
265+
${pkgs.postgresql_12}/bin/pgbench postgres -U postgres \
266+
-h ${if env.withSeparatePg then "pg" else "pgrst"} \
267+
-T 30 --no-vacuum \
268+
--jobs ${builtins.toString (builtins.getAttr nodes.pgrst.config.deployment.ec2.instanceType (import ./postgrest/tuning.nix))} \
269+
$@
270+
'')
262271
];
263272
deployment = {
264273
targetEnv = "ec2";

shell.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ let
5555
set -euo pipefail
5656
5757
echo -e "\nRunning pgbench with $1 clients"
58-
host=$([ "$PGRSTBENCH_SEPARATE_PG" = "true" ] && echo "pg" || echo "pgrst")
5958
# uses the full cores of the instance and prepared statements
60-
nixops ssh -d ${prefix} client pgbench postgres -h "$host" -U postgres -j 16 -T 30 -c $1 --no-vacuum -f - < $2 || true
59+
# || true is added because the command might fail on lower instances with FATAL: sorry, too many clients already
60+
nixops ssh -d ${prefix} client pgbench-tuned -c $1 -f - < $2 || true
6161
'';
6262
clientPgBenchVaried =
6363
pkgs.writeShellScriptBin (prefix + "-pgbench-vary-clients")

0 commit comments

Comments
 (0)