Skip to content
This repository has been archived by the owner on Nov 2, 2022. It is now read-only.

postgrest: nginx + separate pg by default #27

Merged
merged 1 commit into from
Apr 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions postgrest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand All @@ -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
```

Expand All @@ -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)
Expand Down
35 changes: 12 additions & 23 deletions postgrest/deploy.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 <nixpkgs> {};
in {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion postgrest/k6/POSTBulk.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
7 changes: 5 additions & 2 deletions postgrest/shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
'';
}