-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
115 lines (95 loc) · 4.51 KB
/
Copy pathMakefile
File metadata and controls
115 lines (95 loc) · 4.51 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
# PLANET --- containerised PostgreSQL 18 with the extension built in.
#
# make up # build + start the server
# make demo # guided walkthrough of the whole interface
# make test # pg_regress suite against the running server
# make psql # a shell on it
#
# make dataset SCALE=2000000 # synthetic tables for the plan sweep
# make overhead ARGS="--mode ro --rounds 1 --time 5 --energy off"
# make pilot && make plot
# make down # stop (make clean also drops the data volume)
#
# Calibration is NOT here --- it needs a meter and runs on the host. See
# ../calibration, then `make coefficients` to push the fit into the container.
COMPOSE ?= docker compose
SCALE ?= 20000000
ARGS ?=
EVAL := /opt/planet/eval
RUN := $(COMPOSE) run --rm bench
.PHONY: build up down clean logs psql shell demo test compare \
dataset overhead pilot plot coefficients
# Bench containers run as the invoking user so results/ stays writable and the
# CSVs it drops there do not end up owned by root.
.env:
printf 'PLANET_UID=%s\nPLANET_GID=%s\n' "$$(id -u)" "$$(id -g)" > $@
results:
mkdir -p results
build: .env
$(COMPOSE) build
# The wait is not `pg_isready`, and cannot be. On first boot the entrypoint runs
# initdb and the init scripts against a TEMPORARY postmaster on the very same
# socket, then shuts it down and starts the real one. pg_isready says "ready" to
# the temp server, and the next command then fails with "No such file or
# directory" as the socket vanishes under it. The temp server is started with
# listen_addresses='' and the real one is not, which is the one difference a
# client can see.
up: .env results
$(COMPOSE) up -d --build db
@echo "planet: waiting for the server (first boot runs initdb, ~20s)"
@for i in $$(seq 1 180); do \
if [ -n "$$($(COMPOSE) exec -T -u postgres db \
psql -d bench -Atqc 'SHOW listen_addresses' 2>/dev/null)" ]; then \
exit 0; \
fi; \
sleep 1; \
done; \
echo "planet: server did not come up; try 'make logs'" >&2; exit 1
@echo "planet: server ready. Active coefficients (LOAD first --- nothing preloads planet):"
@$(COMPOSE) exec -u postgres db psql -d bench -Atc "LOAD 'planet';" \
-c "SELECT name || ' = ' || setting FROM pg_settings WHERE name LIKE 'planet.%' AND name NOT IN ('planet.enabled','planet.report');"
down:
$(COMPOSE) down
# Also drops pgdata: the next `up` re-runs initdb.d, which is how you pick up a
# changed planet.conf include or a freshly calibrated coefficients.json.
clean:
$(COMPOSE) down -v
logs:
$(COMPOSE) logs -f db
psql:
$(COMPOSE) exec -u postgres db psql -d bench
shell: .env results
$(RUN) bash
# ---- demo and tests --------------------------------------------------------
# Piped on stdin rather than bind-mounted, so `make demo` needs nothing in the
# image and the same file runs unchanged against your own server:
# psql -d yourdb -f docker/demo.sql
demo: up
@$(COMPOSE) exec -T -u postgres db psql -d bench -v ON_ERROR_STOP=1 -f - < demo.sql
# pg_regress from the build stage, against the db container over the socket.
# Exits non-zero on the first diff and leaves regression.diffs in the container.
test: up
$(COMPOSE) run --rm test
# Paired A/B comparison of two ways of running one query.
# make compare ARGS="-q 'SELECT ...' -A 'SET enable_seqscan=off' \
# --sweep /results/sweep.csv"
compare: .env results
$(RUN) python3 $(EVAL)/compare_energy.py -d bench $(ARGS)
# ---- Q3: dataset, plan sweep, Pareto front ---------------------------------
# 20M rows is the paper's scale (~3 GB). Drop SCALE for a laptop smoke test.
dataset: .env results
$(RUN) psql -v scale=$(SCALE) -f $(EVAL)/setup.sql
pilot: .env results
$(RUN) bash -c '$(EVAL)/run_pilot.sh $(EVAL)/queries/*.sql > /results/pilot.csv'
@echo "planet: wrote docker/results/pilot.csv"
plot: .env results
$(RUN) python3 $(EVAL)/plot_pareto.py /results/pilot.csv -o /results/pareto.pdf
# ---- Q2: overhead ----------------------------------------------------------
# Omits the mJ/tx column unless compose's `security_opt: systempaths=unconfined`
# is uncommented; see compose.yaml for why that is off by default.
overhead: .env results
$(RUN) python3 $(EVAL)/bench_overhead.py -d bench --out /results/overhead.csv $(ARGS)
# ---- calibration handoff ---------------------------------------------------
# Reads ../config/coefficients.json (bind-mounted read-only at /etc/planet).
coefficients:
$(COMPOSE) exec db planet-apply-coefficients