forked from quarkusio/spring-quarkus-perf-comparison
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinfra.sh
More file actions
executable file
·250 lines (211 loc) · 6.45 KB
/
infra.sh
File metadata and controls
executable file
·250 lines (211 loc) · 6.45 KB
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
#!/usr/bin/env bash
set -euo pipefail
thisdir="$(realpath $(dirname "$0"))"
help() {
echo "This script starts the necessary services for the app in question"
echo
echo "Syntax: infra.sh [options]"
echo "options:"
echo " -c <DB_CPUS> The number of cpus to allocate to the database container"
echo " -d Destroy the services"
echo " -g <OTEL_CPUSET_CPUS> Otel CPUs in which to allow execution (0-3, 0,1)"
echo " -h Prints this help message"
echo " -l <OTEL_CPUS> The number of cpus to allocate to the Otel container"
echo " -m <DB_MEMORY> Memory to allocate to the database container"
echo " Default: ${DB_MEMORY}"
echo " -n Use host networking instead of port mapping on infra containers"
echo " -o Output the Otel process host PID"
echo " -p <DB_CPUSET_CPUS> Database CPUs in which to allow execution (0-3, 0,1)"
echo " -r Output the PostgreSQL process host PID"
echo " -s Start the services"
echo " -t <OTEL_MEMORY> Memory to allocate to the Otel container"
echo " Default: ${OTEL_MEMORY}"
}
exit_abnormal() {
echo
help
exit 1
}
get_postgres_host_pid() {
echo $(${engine} inspect -f '{{.State.Pid}}' ${DB_CONTAINER_NAME})
}
get_otel_host_pid() {
echo $(${engine} inspect -f '{{.State.Pid}}' ${OTEL_CONTAINER_NAME})
}
# Wrapper to handle rootless podman cgroup issues on Linux
run_with_cgroup_support() {
# Check if we're on Linux with rootless podman
if [ "$(uname)" = "Linux" ] && [ "$engine" = "podman" ] && [ "$(id -u)" -ne 0 ]; then
# Linux rootless podman - use systemd-run for proper cgroup delegation
if command -v systemd-run >/dev/null 2>&1; then
systemd-run --user --scope --quiet -- "$@"
else
# systemd-run not found, running without cgroup delegation (resource limits may not work)
"$@"
fi
else
# macOS, Docker, or rootful podman - run directly
"$@"
fi
}
start_otel() {
echo "Starting Otel stack"
local cpuset_flag=""
local cpus_flag=""
local networking_flags=""
if [ -n "$OTEL_CPUS" ]; then
cpus_flag="--cpus ${OTEL_CPUS}"
fi
if [ -n "${OTEL_CPUSET_CPUS}" ] && [ "$(uname)" = "Linux" ]; then
# Only use --cpuset-cpus on Linux (if set at all)
cpuset_flag="--cpuset-cpus ${OTEL_CPUSET_CPUS}"
fi
if [ "${USE_HOST_NETWORKING}" = "true" ]; then
networking_flags="--network host"
else
networking_flags="-p 4317:4317 -p 4318:4318 -p 3000:3000 -p 4040:4040 -p 9090:9090"
fi
local pid=$(run_with_cgroup_support ${engine} run \
${cpus_flag} \
${cpuset_flag} \
--memory ${OTEL_MEMORY} \
-d \
--rm \
--name ${OTEL_CONTAINER_NAME} \
${networking_flags} \
docker.io/grafana/otel-lgtm@sha256:205bfb9b4907c9acac5b99a407ad5fc4bf528a73dc735fa39ffc2c3a9335cbe9)
echo "Grafana Otel LGTM process: $pid"
echo "Waiting for Grafana Otel LGTM to be ready..."
# timeout 90s bash -c "until curl -sf http://localhost:3000/api/health > /dev/null; do sleep 5; done" || {
timeout 90s bash -c "until ${engine} exec $OTEL_CONTAINER_NAME curl -sf http://localhost:3000/api/health > /dev/null; do sleep 5 ; done" || {
echo "Error: Otel LGTM failed to become ready"
exit 1
}
}
start_postgres() {
echo "Starting PostgreSQL database '${DB_CONTAINER_NAME}'"
local cpuset_flag=""
local cpus_flag=""
local networking_flags=""
if [ -n "$DB_CPUS" ]; then
cpus_flag="--cpus ${DB_CPUS}"
fi
if [ -n "${DB_CPUSET_CPUS}" ] && [ "$(uname)" = "Linux" ]; then
# Only use --cpuset-cpus on Linux (if set at all)
cpuset_flag="--cpuset-cpus ${DB_CPUSET_CPUS}"
fi
if [ "${USE_HOST_NETWORKING}" = "true" ]; then
networking_flags="--network host"
else
networking_flags="-p 5432:5432"
fi
local pid=$(run_with_cgroup_support ${engine} run \
${cpus_flag} \
${cpuset_flag} \
--memory ${DB_MEMORY} \
-d \
--rm \
--name ${DB_CONTAINER_NAME} \
${networking_flags} \
ghcr.io/quarkusio/postgres-17-perf@sha256:25547aa2c1a44685066f552e1c262929cf629cbc2f3a82bd18fa791a03f7cd48 \
-c fsync=off \
-c synchronous_commit=off \
-c autovacuum=off \
-c full_page_writes=off \
-c wal_level=minimal \
-c archive_mode=off \
-c max_wal_senders=0 \
-c max_wal_size=4GB \
-c track_counts=off \
-c checkpoint_timeout=1h \
-c work_mem=32MB \
-c maintenance_work_mem=256MB)
echo "PostgreSQL DB process: $pid"
echo "Waiting for PostgreSQL to be ready..."
timeout 90s bash -c "until ${engine} exec $DB_CONTAINER_NAME pg_isready -h localhost -U fruits; do sleep 5 ; done" || {
echo "Error: PostgreSQL failed to become ready"
exit 1
}
}
stop_otel() {
echo "Stopping Otel stack"
${engine} stop ${OTEL_CONTAINER_NAME}
}
stop_postgres() {
echo "Stopping PostgreSQL database '${DB_CONTAINER_NAME}'"
${engine} stop ${DB_CONTAINER_NAME}
}
start_services() {
echo "Using $engine to start containers"
echo "-----------------------------------------"
echo "[$(date +"%m/%d/%Y %T")]: Starting services"
echo "-----------------------------------------"
start_postgres
start_otel
}
stop_services() {
echo "Using $engine to stop containers"
echo "-----------------------------------------"
echo "[$(date +"%m/%d/%Y %T")]: Stopping services"
echo "-----------------------------------------"
stop_postgres
stop_otel
}
DB_CONTAINER_NAME="fruits_db"
OTEL_CONTAINER_NAME="otel_lgtm"
OTEL_CPUS=""
OTEL_CPUSET_CPUS=""
OTEL_MEMORY="2g"
DB_CPUS=""
DB_CPUSET_CPUS=""
DB_MEMORY="2g"
engine=""
IS_STARTING=true
USE_HOST_NETWORKING=false
if command -v podman >/dev/null 2>&1; then
engine="podman"
elif command -v docker >/dev/null 2>&1; then
engine="docker"
else
echo "Error: Neither podman nor docker can be found"
exit_abnormal
fi
# Process the input options
while getopts "c:dg:hl:m:nop:rst:" option; do
case $option in
c) DB_CPUS=$OPTARG
;;
d) IS_STARTING=false
;;
g) OTEL_CPUSET_CPUS=$OPTARG
;;
h) help
exit
;;
l) OTEL_CPUS=$OPTARG
;;
m) DB_MEMORY=$OPTARG
;;
n) USE_HOST_NETWORKING=true
;;
o) get_otel_host_pid
exit
;;
p) DB_CPUSET_CPUS=$OPTARG
;;
r) get_postgres_host_pid
exit
;;
s) IS_STARTING=true
;;
t) OTEL_MEMORY=$OPTARG
;;
*) exit_abnormal
;;
esac
done
if [ "${IS_STARTING}" = true ]; then
start_services
else
stop_services
fi