From a140ae2306deee19b8df733b59b7e4c0fed8fad8 Mon Sep 17 00:00:00 2001 From: steve-chavez Date: Wed, 6 Apr 2022 16:00:14 -0500 Subject: [PATCH] postgrest: nginx + separate pg by default * make the instances types configurable through env vars * make the pool size configurable through env var * Use ?columns in POSTBulk --- postgrest/README.md | 14 ++++++++++---- postgrest/deploy.nix | 35 ++++++++++++----------------------- postgrest/k6/POSTBulk.js | 2 +- postgrest/shell.nix | 7 +++++-- 4 files changed, 28 insertions(+), 30 deletions(-) diff --git a/postgrest/README.md b/postgrest/README.md index f38f5c5..b1be432 100644 --- a/postgrest/README.md +++ b/postgrest/README.md @@ -65,7 +65,7 @@ pgrbench-k6 t3anano k6/GETSingle.js To load test with nginx included do: ```bash -export PGRBENCH_SETUP="with-nginx" +export PGRBENCH_WITH_NGINX="true" pgrbench-deploy ``` @@ -74,14 +74,14 @@ pgrbench-deploy To load test connecting pgrest to pg with unix socket, and pgrest to nginx with unix socket. ```bash -export PGRBENCH_CONN_TYPE="unix-socket" +export PGRBENCH_WITH_UNIX_SOCKET="true" pgrbench-deploy ``` To use tcp instead, you can do: ```bash -export PGRBENCH_CONN_TYPE="tcp" +export PGRBENCH_WITH_UNIX_SOCKET="false" pgrbench-deploy ``` @@ -94,13 +94,19 @@ export PGRBENCH_SEPARATE_PG="true" pgrbench-deploy ``` -To change its EC2 instance type(t3a.nano by default): +## Change EC2 instance types + +To change pg and PostgREST EC2 instance types(both t3a.nano by default): ```bash export PGRBENCH_PG_INSTANCE_TYPE="t3a.xlarge" +export PGRBENCH_PGRST_INSTANCE_TYPE="t3a.xlarge" + pgrbench-deploy ``` +Don't try with ARM-based instances, these don't work currently for NixOps. + ## Scenarios to test - [x]read heavy workload(with resource embedding) diff --git a/postgrest/deploy.nix b/postgrest/deploy.nix index 312ebf2..71f7f43 100644 --- a/postgrest/deploy.nix +++ b/postgrest/deploy.nix @@ -2,13 +2,13 @@ let region = "us-east-2"; accessKeyId = "default"; ## aws profile env = { - #export PGRBENCH_SETUP="with-nginx" - withNginx = builtins.getEnv "PGRBENCH_SETUP" == "with-nginx"; - withUnixSocket = builtins.getEnv "PGRBENCH_CONN_TYPE" == "unix-socket"; - #export PGRBENCH_SEPARATE_PG="true" - withSeparatePg = builtins.getEnv "PGRBENCH_SEPARATE_PG" == "true"; - #export PGRBENCH_PG_INSTANCE_TYPE="t3a.nano" - pgInstanceType = builtins.getEnv "PGRBENCH_PG_INSTANCE_TYPE"; + withNginx = builtins.getEnv "PGRBENCH_WITH_NGINX" == "true"; + withUnixSocket = builtins.getEnv "PGRBENCH_WITH_UNIX_SOCKET" == "true"; + withSeparatePg = builtins.getEnv "PGRBENCH_SEPARATE_PG" == "true"; + + pgInstanceType = builtins.getEnv "PGRBENCH_PG_INSTANCE_TYPE"; + pgrstInstanceType = builtins.getEnv "PGRBENCH_PGRST_INSTANCE_TYPE"; + pgrstPool = builtins.getEnv "PGRBENCH_PGRST_POOL"; }; pkgs = import {}; in { @@ -73,7 +73,10 @@ in { targetEnv = "ec2"; ec2 = { inherit region accessKeyId; - instanceType = "t3a.nano"; + instanceType = + if builtins.stringLength env.pgrstInstanceType == 0 + then "t3a.nano" + else env.pgrstInstanceType; associatePublicIpAddress = true; ebsInitialRootDiskSize = 10; keyPair = resources.ec2KeyPairs.pgrstBenchKeyPair; @@ -115,21 +118,7 @@ in { db-schema = "public" db-anon-role = "postgres" db-use-legacy-gucs = false - ${ - if env.withSeparatePg then - with nodes.pg.config.deployment.ec2; - ## these db-pool values haven't been proven to increase performance - if instanceType == "t3a.nano" then - "db-pool = 20" - else - if instanceType == "t3a.xlarge" then - "db-pool = 30" - else - if instanceType == "t3a.2xlarge" then - "db-pool = 40" - else "" - else "" - } + db-pool = ${if builtins.stringLength env.pgrstPool == 0 then "20" else env.pgrstPool} ${ if env.withNginx && env.withUnixSocket diff --git a/postgrest/k6/POSTBulk.js b/postgrest/k6/POSTBulk.js index b4a45c4..74b1c82 100644 --- a/postgrest/k6/POSTBulk.js +++ b/postgrest/k6/POSTBulk.js @@ -33,7 +33,7 @@ export default function() { , fax: '+1 (403) 246-9899' , email: 'vu' + __ITER + '@chinookcorp.com' })); - let res = http.post(URL + "/employee", body, {headers: { 'Content-Type': 'application/json' }}); + let res = http.post(URL + "/employee?columns=employee_id,first_name,last_name,title,reports_to,birth_date,hire_date,address,city,state,country,postal_code,phone,fax,email", body, {headers: { 'Content-Type': 'application/json' }}); myFailRate.add(res.status !== 201); } diff --git a/postgrest/shell.nix b/postgrest/shell.nix index 63097c7..b05d69d 100644 --- a/postgrest/shell.nix +++ b/postgrest/shell.nix @@ -19,7 +19,7 @@ let nixops create deploy.nix -d pgrbench fi - nixops deploy -k -d pgrbench + nixops deploy -k -d pgrbench --allow-reboot --confirm ''; info = pkgs.writeShellScriptBin "pgrbench-info" @@ -67,6 +67,9 @@ pkgs.mkShell { shellHook = '' export NIX_PATH="nixpkgs=${nixpkgs}:." export NIXOPS_STATE=".deployment.nixops" - export PGRBENCH_CONN_TYPE="unix-socket" + + export PGRBENCH_WITH_NGINX="true" + export PGRBENCH_WITH_UNIX_SOCKET="true" + export PGRBENCH_SEPARATE_PG="true" ''; }