-
Notifications
You must be signed in to change notification settings - Fork 0
/
shell.nix
163 lines (138 loc) · 4.66 KB
/
shell.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
let
nixpkgs = builtins.fetchTarball {
name = "nixos-20.03";
url = "https://github.com/nixos/nixpkgs/archive/7bc3a08d3a4c700b53a3b27f5acd149f24b931ec.tar.gz";
sha256 = "1kiz37052zsgvw7a378zg08mpbi1wk8dkgm5j6dy0x4mxvcg8ws3";
};
pkgs = import nixpkgs {};
global = import ./global.nix;
prefix = global.prefix;
deploy =
pkgs.writeShellScriptBin (prefix + "-deploy")
''
set -euo pipefail
set +e && nixops info -d ${prefix} > /dev/null 2> /dev/null
info=$? && set -e
if test $info -eq 1
then
echo "Creating deployment..."
nixops create deploy.nix -d ${prefix}
fi
nixops deploy -k -d ${prefix} --allow-reboot --confirm
'';
info =
pkgs.writeShellScriptBin (prefix + "-info")
''
set -euo pipefail
nixops info -d ${prefix}
'';
k6 =
pkgs.writeShellScriptBin (prefix + "-k6")
''
set -euo pipefail
nixops ssh -d ${prefix} client k6 run -q --vus $1 - < $2
'';
k6VariedVus =
pkgs.writeShellScriptBin (prefix + "-k6-vary-vus")
''
set -euo pipefail
for i in '10' '50' '100'; do
echo -e "\n"
${prefix}-k6 $i $1
done
'';
clientPgBench =
pkgs.writeShellScriptBin (prefix + "-pgbench")
''
set -euo pipefail
host=$([ "$PGRSTBENCH_SEPARATE_PG" = "true" ] && echo "pg" || echo "pgrst")
# uses the full cores of the instance and prepared statements
nixops ssh -d ${prefix} client pgbench postgres -h $host -U postgres -j 16 -T 30 -c $1 --no-vacuum -f - < $2
'';
clientPgBenchVaried =
pkgs.writeShellScriptBin (prefix + "-pgbench-vary-clients")
''
set -euo pipefail
for i in '10' '50' '100'; do
echo -e "\n"
${prefix}-pgbench $i $1
done
'';
## execute a command by varing the size of pg instances, currently hardcoded to some m5a instances
## pgrstbench-vary-pg pgrstbench-pgbench-varied-clients pgbench/GETSingle.sql > pgbench/results/PGBENCH_GET_SINGLE.txt
executeVaryAllPgInstances =
pkgs.writeShellScriptBin (prefix + "-vary-pg")
''
set -euo pipefail
for instance in 'm5a.large' 'm5a.xlarge' 'm5a.2xlarge' 'm5a.4xlarge' 'm5a.8xlarge'; do
export PGRSTBENCH_PG_INSTANCE_TYPE="$instance"
${prefix}-deploy
echo -e "\nInstance: $PGRSTBENCH_PG_INSTANCE_TYPE\n"
$@
done
'';
## execute a command by varing the size of pg and pgrst instances, currently hardcoded to some m5a instances
## pgrstbench-vary-pg-pgrst pgrbench-k6-varied-vus k6/GETSingle.js > k6/results/LB_K6_GET_SINGLE.txt
executeVaryAllPgPgrstInstances =
pkgs.writeShellScriptBin (prefix + "-vary-pg-pgrst")
''
set -euo pipefail
counter=0
for instance in 'm5a.large' 'm5a.xlarge' 'm5a.2xlarge' 'm5a.4xlarge' 'm5a.8xlarge' 'm5a.12xlarge' 'm5a.16xlarge'; do
export PGRSTBENCH_PG_INSTANCE_TYPE="$instance"
export PGRSTBENCH_PGRST_INSTANCE_TYPE="$instance"
export PGRSTBENCH_PGRST_POOL=$((100 + counter*50))
counter=$((counter + 1))
${prefix}-deploy
sleep 2s # TODO: sleep until pgrest establishes a connection to pg, this should be handled in a k6 setup
echo -e "\nPostgreSQL instance: $PGRSTBENCH_PG_INSTANCE_TYPE\n"
echo -e "PostgREST instance: $PGRSTBENCH_PGRST_INSTANCE_TYPE\n"
echo -e "PostgREST Pool: $PGRSTBENCH_PGRST_POOL\n"
$@
done
'';
ssh =
pkgs.writeShellScriptBin (prefix + "-ssh")
''
set -euo pipefail
nixops ssh -d ${prefix} $1
'';
destroy =
pkgs.writeShellScriptBin (prefix + "-destroy")
''
set -euo pipefail
nixops destroy -d ${prefix} --confirm
nixops delete -d ${prefix}
rm .deployment.nixops
'';
in
pkgs.mkShell {
buildInputs = [
pkgs.nixops
deploy
info
k6
k6VariedVus
ssh
destroy
clientPgBench
clientPgBenchVaried
executeVaryAllPgInstances
executeVaryAllPgPgrstInstances
];
shellHook = ''
export NIX_PATH="nixpkgs=${nixpkgs}:."
export NIXOPS_STATE=".deployment.nixops"
export HISTFILE=.history
export PGRSTBENCH_AWS_PROFILE="default"
export PGRSTBENCH_WITH_NGINX="true"
export PGRSTBENCH_WITH_UNIX_SOCKET="true"
export PGRSTBENCH_SEPARATE_PG="true"
export PGRSTBENCH_CLIENT_INSTANCE_TYPE="m5a.xlarge"
export PGRSTBENCH_PG_INSTANCE_TYPE="t3a.nano"
export PGRSTBENCH_PGRST_INSTANCE_TYPE="t3a.nano"
export PGRSTBENCH_PGRST_POOL="200"
export PGRSTBENCH_PGRST_NGNIX_LBS="false"
export PGRSTBENCH_PG_LOGGING="false"
'';
}