Skip to content

Commit 49fb6e4

Browse files
authored
Merge pull request #5 from alexanderlaw/main
Implement support for running benchmarks with perf
2 parents 6591bf3 + 99922c1 commit 49fb6e4

6 files changed

+66
-15
lines changed

Dockerfile-pgapt

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
FROM ubuntu
2+
ARG FEATURES
23
ARG PG_VERSION
34
ARG PHASE1_ACTION
45
ARG PHASE2_ACTION
@@ -19,6 +20,8 @@ RUN p=$EXTRA_OS_PACKAGES; p="${p%\"}";p="${p#\"}"; \
1920
git gcc make libreadline-dev zlib1g-dev libicu-dev bison flex gettext \
2021
openjdk-17-jdk maven sysbench
2122

23+
RUN if (echo "$FEATURES" | grep -Eq "\bperf\b"); then apt install -y linux-tools-common linux-tools-`uname -r`; fi
24+
2225
RUN locale-gen en_US.UTF-8 && update-locale LANG=en_US.UTF-8
2326
ENV LANG en_US.UTF-8
2427
ENV LC_ALL en_US.UTF-8
@@ -76,7 +79,12 @@ printf "\n"\
7679
"host all all 0.0.0.0/0 md5\n"\
7780
"host all all ::1/128 trust\n" >> /etc/postgresql/$PG_VERSION/main/pg_hba.conf
7881

79-
RUN echo "/usr/lib/postgresql/$PG_VERSION/bin/postgres -D /var/lib/postgresql/$PG_VERSION/main -c config_file=/etc/postgresql/$PG_VERSION/main/postgresql.conf" >/usr/bin/pgmain && chmod a+x /usr/bin/pgmain
82+
RUN if (echo "$FEATURES" | grep -Eq "\bperf\b"); then \
83+
echo "perf record -o /home/postgres/results/perf.data --call-graph dwarf -- /usr/lib/postgresql/$PG_VERSION/bin/postgres -D /var/lib/postgresql/$PG_VERSION/main -c config_file=/etc/postgresql/$PG_VERSION/main/postgresql.conf >/home/postgres/results/perf.log 2>&1; sleep inf" >/usr/bin/pgmain && chmod a+x /usr/bin/pgmain; \
84+
echo "/usr/lib/postgresql/$PG_VERSION/bin/pg_ctl -w -D /var/lib/postgresql/$PG_VERSION/main stop" >/usr/bin/pg_ctl_stop && chmod a+x /usr/bin/pg_ctl_stop; \
85+
else \
86+
echo "/usr/lib/postgresql/$PG_VERSION/bin/postgres -D /var/lib/postgresql/$PG_VERSION/main -c config_file=/etc/postgresql/$PG_VERSION/main/postgresql.conf" >/usr/bin/pgmain && chmod a+x /usr/bin/pgmain; \
87+
fi
8088

8189
# Run the rest of the commands as the ``postgres`` user created by the ``postgres-$version`` package when it was ``apt installed``
8290
USER postgres

Dockerfile-proapt

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
FROM ubuntu
2+
ARG FEATURES
23
ARG PG_VERSION
34
ARG PHASE1_ACTION
45
ARG PHASE2_ACTION
@@ -21,6 +22,8 @@ RUN p=$EXTRA_OS_PACKAGES; p="${p%\"}";p="${p#\"}"; \
2122
git gcc make libreadline-dev zlib1g-dev libicu-dev bison flex gettext \
2223
openjdk-17-jdk maven sysbench
2324

25+
RUN if (echo "$FEATURES" | grep -Eq "\bperf\b"); then apt install -y linux-tools-common linux-tools-`uname -r`; fi
26+
2427
RUN locale-gen en_US.UTF-8 && update-locale LANG=en_US.UTF-8
2528
ENV LANG en_US.UTF-8
2629
ENV LC_ALL en_US.UTF-8
@@ -81,7 +84,12 @@ printf "\n"\
8184
"host all all 0.0.0.0/0 md5\n"\
8285
"host all all ::1/128 trust\n" >> /var/lib/pgpro/$PGPRO_EDN-$PG_VERSION/data/pg_hba.conf
8386

84-
RUN echo "/opt/pgpro/$PGPRO_EDN-$PG_VERSION/bin/postgres -D /var/lib/pgpro/$PGPRO_EDN-$PG_VERSION/data -c config_file=/var/lib/pgpro/$PGPRO_EDN-$PG_VERSION/data/postgresql.conf" >/usr/bin/pgmain && chmod a+x /usr/bin/pgmain
87+
RUN if (echo "$FEATURES" | grep -Eq "\bperf\b"); then \
88+
echo "perf record -o /home/postgres/results/perf.data --call-graph dwarf -- /opt/pgpro/$PGPRO_EDN-$PG_VERSION/bin/postgres -D /var/lib/pgpro/$PGPRO_EDN-$PG_VERSION/data -c config_file=/var/lib/pgpro/$PGPRO_EDN-$PG_VERSION/data/postgresql.conf >/home/postgres/results/perf.log 2>&1; sleep inf" >/usr/bin/pgmain && chmod a+x /usr/bin/pgmain; \
89+
echo "/opt/pgpro/$PGPRO_EDN-$PG_VERSION/bin/pg_ctl -w -D /var/lib/pgpro/$PGPRO_EDN-$PG_VERSION/data stop" >/usr/bin/pg_ctl_stop && chmod a+x /usr/bin/pg_ctl_stop; \
90+
else \
91+
echo "/opt/pgpro/$PGPRO_EDN-$PG_VERSION/bin/postgres -D /var/lib/pgpro/$PGPRO_EDN-$PG_VERSION/data -c config_file=/var/lib/pgpro/$PGPRO_EDN-$PG_VERSION/data/postgresql.conf" >/usr/bin/pgmain && chmod a+x /usr/bin/pgmain; \
92+
fi
8593

8694
# Run the rest of the commands as the ``postgres`` user created by the ``postgres*-$version`` package when it was ``apt installed``
8795
USER postgres

Dockerfile-src

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
FROM ubuntu
2+
ARG FEATURES
23
ARG PG_VERSION
34
ARG PHASE1_ACTION
45
ARG PHASE2_ACTION
@@ -20,6 +21,8 @@ RUN p=$EXTRA_OS_PACKAGES; p="${p%\"}";p="${p#\"}"; \
2021
git gcc make libreadline-dev zlib1g-dev libicu-dev bison flex gettext \
2122
openjdk-17-jdk maven sysbench
2223

24+
RUN if (echo "$FEATURES" | grep -Eq "\bperf\b"); then apt install -y linux-tools-common linux-tools-`uname -r`; fi
25+
2326
RUN locale-gen en_US.UTF-8 && update-locale LANG=en_US.UTF-8
2427
ENV LANG en_US.UTF-8
2528
ENV LC_ALL en_US.UTF-8
@@ -58,7 +61,12 @@ RUN cd /home/postgres/src/postgres && make -s install && \
5861

5962
ENV PATH "$PATH:/usr/local/pgsql/bin"
6063

61-
RUN echo "/usr/local/pgsql/bin/postgres -D /var/lib/postgresql/main -c config_file=/var/lib/postgresql/main/postgresql.conf" >/usr/bin/pgmain && chmod a+x /usr/bin/pgmain
64+
RUN if (echo "$FEATURES" | grep -Eq "\bperf\b"); then \
65+
echo "perf record -o /home/postgres/results/perf.data --call-graph dwarf -- /usr/local/pgsql/bin/postgres -D /var/lib/postgresql/main -c config_file=/var/lib/postgresql/main/postgresql.conf >/home/postgres/results/perf.log 2>&1; sleep inf" >/usr/bin/pgmain && chmod a+x /usr/bin/pgmain; \
66+
echo "/usr/local/pgsql/bin/pg_ctl -w -D /var/lib/postgresql/main stop" >/usr/bin/pg_ctl_stop && chmod a+x /usr/bin/pg_ctl_stop; \
67+
else \
68+
echo "/usr/local/pgsql/bin/postgres -D /var/lib/postgresql/main -c config_file=/var/lib/postgresql/main/postgresql.conf" >/usr/bin/pgmain && chmod a+x /usr/bin/pgmain; \
69+
fi
6270

6371
COPY ./$PHASE2_ACTION /bin/
6472
RUN $PHASE2_ACTION

config.xml

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
<os version="23.04" />
3131
</instance>
3232
<xi:include href="private_instances.xml" />
33+
<instance id="pg-src-master-perf" disabled="true" type="src" features="perf" git_branch="master" />
3334
<instance id="pg-src-15" type="src" pg_version="15devel" git_branch="REL_15_STABLE" />
3435
<instance id="pg-src-master" type="src" pg_version="16devel" git_branch="master" />
3536
</pg_instances>

prepare-instances.py

+13-9
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,16 @@ def get_repo_url(instance):
142142
encoding='UTF-8') as dockerfile:
143143
dockerfile.write(df_contents)
144144

145+
if instance.get('features') is not None:
146+
build_args += ["--build-arg",
147+
(f'FEATURES={instance.get("features")}')]
148+
145149
if instance.get('pg_version') is not None:
146-
build_args += ['--build-arg', ('PG_VERSION=' +
147-
instance.get('pg_version'))]
150+
build_args += ['--build-arg',
151+
(f'PG_VERSION={instance.get("pg_version")}')]
148152
if instance.get('pgpro_edition') is not None:
149-
build_args += ['--build-arg', ('PGPRO_EDN=' +
150-
instance.get('pgpro_edition'))]
153+
build_args += ['--build-arg',
154+
(f'PGPRO_EDN={instance.get("pgpro_edition")}')]
151155
pg_params = ''
152156
for param in instance.findall('config/pg_param'):
153157
pg_params += f"{param.get('name')} = '{param.get('value')}'\\n"
@@ -157,15 +161,15 @@ def get_repo_url(instance):
157161

158162
repo_url = get_repo_url(instance)
159163
if repo_url is not None:
160-
build_args += ['--build-arg', ('REPOSITORY=' + repo_url)]
164+
build_args += ['--build-arg', (f'REPOSITORY={repo_url}')]
161165

162166
extra = instance.find('extra')
163167
if extra is not None:
164168
if extra.find('source') is not None and \
165169
extra.find('source').get('type') == 'git':
166170
extra_git_url = extra.find('source').get('url')
167-
build_args += ['--build-arg', ('EXTRA_SRC_GIT=' +
168-
extra_git_url)]
171+
build_args += ['--build-arg',
172+
(f'EXTRA_SRC_GIT={extra_git_url}')]
169173
pg_modules = ''
170174
for pgm in extra.findall('pg_module'):
171175
pg_modules += (',' if pg_modules else '') + pgm.get('name')
@@ -182,8 +186,8 @@ def get_repo_url(instance):
182186
phase2_action = instance.find('os').get('phase2_action')
183187
if instance.find('os').get('extra_packages') is not None:
184188
extra_os_packages = instance.find('os').get('extra_packages')
185-
build_args += ['--build-arg', ('PHASE1_ACTION=' + phase1_action)]
186-
build_args += ['--build-arg', ('PHASE2_ACTION=' + phase2_action)]
189+
build_args += ['--build-arg', (f'PHASE1_ACTION={phase1_action}')]
190+
build_args += ['--build-arg', (f'PHASE2_ACTION={phase2_action}')]
187191
build_args += ['--build-arg',
188192
(f'EXTRA_OS_PACKAGES="{extra_os_packages}"')]
189193

run-benchmarks.py

+25-3
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ def main(configfile, instances, benchmarks, resultsfile, resultsdir):
106106
insts = {}
107107
if not instances:
108108
for inst in config.findall('./pg_instances//instance'):
109+
if inst.get('disabled') == 'true':
110+
continue
109111
insts[inst.get('id')] = inst
110112
else:
111113
inst_cnts = {}
@@ -155,8 +157,6 @@ def main(configfile, instances, benchmarks, resultsfile, resultsdir):
155157
bmbench.set('id', bench_id)
156158
for instance_uid, instance in insts.items():
157159
instance_id = instance.get('id')
158-
if instance.get('disabled') == 'true':
159-
continue
160160

161161
if re.match(r'^[\./]', instance_id):
162162
raise Exception(f'Invalid image id: {instance_id}')
@@ -188,7 +188,7 @@ def main(configfile, instances, benchmarks, resultsfile, resultsdir):
188188
f'-v {os.getcwd()}/resources:/home/postgres/resources '
189189
f'-v {os.getcwd()}/scripts:/home/postgres/scripts '
190190
f'-v {resultdir}:/home/postgres/results '
191-
f'--tty --cap-add=SYS_PTRACE '
191+
f'--tty --cap-add=SYS_PTRACE --cap-add=SYS_ADMIN '
192192
f'--shm-size=2g {envvars} {instance_id}',
193193
shell=True, check=True, stdout=subprocess.PIPE)
194194
container_id = res.stdout.decode('utf-8').strip()
@@ -247,6 +247,28 @@ def main(configfile, instances, benchmarks, resultsfile, resultsdir):
247247
print(output)
248248
raise Exception('Benchmark execution failed! (For details '
249249
'see benchmark-results/.)')
250+
251+
instance_features = instance.get('features')
252+
if re.match(r'\bperf\b', instance_features):
253+
res = run(f'docker exec -t {container_id} bash -c '
254+
f'pg_ctl_stop',
255+
shell=True, check=False, stdout=subprocess.PIPE)
256+
if res.returncode != 0:
257+
print(res.stdout.decode('utf-8'))
258+
raise Exception('Could not stop server.')
259+
sleep(10)
260+
res = run(f'docker exec -t {container_id} bash -c "'
261+
f'perf report --stdio -i'
262+
f' /home/postgres/results/perf.data'
263+
f' >/home/postgres/results/perf.out 2>&1; '
264+
f'perf script -i'
265+
f' /home/postgres/results/perf.data'
266+
f' >/home/postgres/results/perf.script 2>&1"',
267+
shell=True, check=False, stdout=subprocess.PIPE)
268+
if res.returncode != 0:
269+
print(res.stdout.decode('utf-8'))
270+
raise Exception('Could not get perf report.')
271+
250272
for metric in bench.findall('./results/metric'):
251273
mid = metric.get('id')
252274
mre = metric.get('regexp')

0 commit comments

Comments
 (0)