-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathMakefile
331 lines (272 loc) · 10.7 KB
/
Makefile
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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
.ONESHELL:
SHELL = /bin/bash
.SHELLFLAGS += -Ee -o pipefail
.PHONY: all load new-dataset compile load-postgres-helpers
.PHONY: stop-docker reset-postgres
.PHONY: load-mongodb load-gel load-django load-sqlalchemy load-postgres
.PHONY: load-typeorm load-sequelize load-prisma
.PHONY: load-graphql load-hasura load-postgraphile
.PHONY: run-js run-py run-orms run-graphql run-gel
CURRENT_DIR = $(dir $(realpath $(firstword $(MAKEFILE_LIST))))
GEL_VERSION ?= latest
DOCKER ?= docker
PSQL ?= psql
MYSQL ?= mysql
PSQL_CMD = $(PSQL) -h localhost -p 15432 -U postgres
PYTHON ?= python
PP = PYTHONPATH=$(CURRENT_DIR) $(PYTHON)
BUILD=$(abspath dataset/build/)
# Parameters that can be passed to 'make new-dataset'
people?=100000
users?=100000
reviews?=500000
# about 7% of people are going to be directors
directors=$(shell expr ${people} \* 7 / 100)
# there's some overlap between directors and actors
directorsonly=$(shell expr ${people} \* 6 / 100)
movies=$(shell expr ${people} / 4)
all:
@echo "pick a target"
$(BUILD)/geldataset.json:
cd dataset && $(PP) cleandata.py
$(BUILD)/dataset.json:
cd dataset && $(PP) cleandata.py
new-dataset:
mkdir -p dataset/movies
cat dataset/templates/user.json \
| sed "s/%USERS%/$(users)/" > dataset/movies/user.json
cat dataset/templates/person.json \
| sed "s/%PEOPLE%/$(people)/" \
| sed "s/%STARTAT%/$(directorsonly)/" > dataset/movies/person.json
cat dataset/templates/director.json \
| sed "s/%DIRECTORS%/$(directors)/" > dataset/movies/director.json
cat dataset/templates/movie.json \
| sed "s/%MOVIES%/$(movies)/" > dataset/movies/movie.json
cat dataset/templates/review.json \
| sed "s/%REVIEWS%/$(reviews)/" \
| sed "s/%MOVIES%/$(movies)/" > dataset/movies/review.json
synth generate dataset/movies > $(BUILD)/protodataset.json
$(PP) dataset/cleandata.py
docker-network:
$(DOCKER) network inspect webapp-bench>/dev/null 2>&1 \
|| $(DOCKER) network create \
--driver=bridge \
--opt com.docker.network.bridge.name=br-webapp-bench \
webapp-bench
docker-network-destroy:
$(DOCKER) network inspect webapp-bench>/dev/null 2>&1 \
&& $(DOCKER) network rm webapp-bench
docker-postgres-volume:
$(DOCKER) volume inspect webapp-bench-postgres >/dev/null 2>&1 \
|| $(DOCKER) volume create webapp-bench-postgres
docker-postgres-volume-destroy:
$(DOCKER) volume inspect webapp-bench-postgres >/dev/null 2>&1 \
&& $(DOCKER) volume rm webapp-bench-postgres
docker-postgres: docker-network docker-postgres-volume
$(DOCKER) stop webapp-bench-postgres >/dev/null 2>&1 || :
$(DOCKER) run --rm -d --name webapp-bench-postgres \
-v webapp-bench-postgres:/var/lib/postgresql/data \
-e POSTGRES_HOST_AUTH_METHOD=trust \
--network=webapp-bench \
-p 15432:5432 \
postgres:17
sleep 10
$(DOCKER) exec webapp-bench-postgres pg_isready -t10
docker-postgres-stop:
-$(DOCKER) stop webapp-bench-postgres
docker-gel-volume:
$(DOCKER) volume inspect webapp-bench-gel >/dev/null 2>&1 \
|| $(DOCKER) volume create webapp-bench-gel
docker-gel-volume-destroy:
$(DOCKER) volume inspect webapp-bench-gel >/dev/null 2>&1 \
&& $(DOCKER) volume rm webapp-bench-gel
docker-gel: docker-network docker-gel-volume
$(DOCKER) stop webapp-bench-gel >/dev/null 2>&1 || :
$(DOCKER) run --rm -d --name webapp-bench-gel \
-v webapp-bench-gel:/var/lib/gel/data \
-e GEL_SERVER_SECURITY=insecure_dev_mode \
--network=webapp-bench \
-p 15656:5656 \
geldata/gel:$(GEL_VERSION)
gel -H localhost -P 15656 \
--tls-security=insecure --wait-until-available=120s \
query "SELECT 'Gel ready'"
docker-gel-stop:
$(DOCKER) stop webapp-bench-gel
stop-docker:
-$(DOCKER) stop hasura-bench
-$(DOCKER) stop postgraphile-bench
-$(DOCKER) stop webapp-bench-postgres
-$(DOCKER) stop webapp-bench-gel
docker-clean: stop-docker docker-network-destroy \
docker-postgres-volume-destroy docker-gel-volume-destroy
load-mongodb: $(BUILD)/geldataset.json
$(PP) -m _mongodb.loaddata $(BUILD)/geldataset.json
load-gel-nobulk: $(BUILD)/geldataset.json docker-gel
-gel project unlink
-gel instance destroy -I gel_bench --force
gel -H localhost -P 15656 instance link \
--non-interactive --trust-tls-cert --overwrite gel_bench \
&& gel -H localhost -P 15656 project init --link \
--non-interactive --no-migrations --server-instance gel_bench
gel query 'CREATE DATABASE temp'
gel -b temp query 'DROP DATABASE main'
gel -b temp query 'CREATE DATABASE main'
gel query 'DROP DATABASE temp'
gel migrate
$(PP) -m _gel.loaddata_nobulk $(BUILD)/geldataset.json
load-gel: $(BUILD)/geldataset.json docker-gel
-gel project unlink --non-interactive
-gel instance destroy -I gel_bench --force
gel -H localhost -P 15656 instance link \
--non-interactive --trust-tls-cert --overwrite gel_bench
gel -H localhost -P 15656 project init --link \
--non-interactive --no-migrations --server-instance gel_bench
gel query 'CREATE DATABASE temp'
gel -b temp query 'DROP DATABASE main'
gel -b temp query 'CREATE DATABASE main'
gel query 'DROP DATABASE temp'
gel migrate
$(PP) -m _gel.loaddata $(BUILD)/geldataset.json
cd _gel_js && npm i && npx @gel/generate edgeql-js --output-dir querybuilder --target cjs --force-overwrite
load-gel-nosetup:
$(PP) -m _gel.loaddata $(BUILD)/geldataset.json
load-django: $(BUILD)/dataset.json docker-postgres
$(PSQL_CMD) -tc \
"DROP DATABASE IF EXISTS django_bench;"
$(PSQL_CMD) -tc \
"DROP ROLE IF EXISTS django_bench;"
$(PSQL_CMD) -tc \
"CREATE ROLE django_bench WITH \
LOGIN ENCRYPTED PASSWORD 'gelbenchmark';"
$(PSQL_CMD) -tc \
"CREATE DATABASE django_bench WITH OWNER = django_bench;"
$(PP) _django/manage.py flush --noinput
$(PP) _django/manage.py migrate
$(PP) -m _django.loaddata $(BUILD)/dataset.json
load-sqlalchemy: $(BUILD)/dataset.json docker-postgres
$(PSQL_CMD) -tc \
"DROP DATABASE IF EXISTS sqlalch_bench;"
$(PSQL_CMD) -tc \
"DROP ROLE IF EXISTS sqlalch_bench;"
$(PSQL_CMD) -tc \
"CREATE ROLE sqlalch_bench WITH \
LOGIN ENCRYPTED PASSWORD 'gelbenchmark';"
$(PSQL_CMD) -tc \
"CREATE DATABASE sqlalch_bench WITH OWNER = sqlalch_bench;"
cd _sqlalchemy/migrations && $(PP) -m alembic.config upgrade head && cd ../..
$(PP) _sqlalchemy/loaddata.py $(BUILD)/dataset.json
load-postgres: docker-postgres reset-postgres $(BUILD)/dataset.json
$(PSQL_CMD) -U postgres_bench -d postgres_bench \
--file=$(CURRENT_DIR)/_postgres/schema.sql
$(PP) _postgres/loaddata.py $(BUILD)/dataset.json
cd _postgres && npm i
load-planetscale-prisma: export MYSQL_PWD=$(PLANETSCALE_PASSWORD)
load-planetscale-prisma: $(BUILD)/dataset.json
$(MYSQL) -h $(PLANETSCALE_HOST) -u $(PLANETSCALE_USER) \
< $(CURRENT_DIR)/_postgres/planetscale.sql
$(PP) _postgres/loaddata_planetscale.py $(BUILD)/dataset.json
cd _prisma && \
npm i && \
echo 'DATABASE_URL="mysql://$(PLANETSCALE_USER):$(PLANETSCALE_PASSWORD)@$(PLANETSCALE_HOST):3306/$(PLANETSCALE_DATABASE)?sslaccept=strict&schema=public"' > .env && \
npx prisma generate --schema=prisma/planetscale.prisma && npm i
reset-postgres: docker-postgres
$(PSQL_CMD) -tc \
"DROP DATABASE IF EXISTS postgres_bench;"
$(PSQL_CMD) -U postgres -tc \
"DROP ROLE IF EXISTS postgres_bench;"
$(PSQL_CMD) -U postgres -tc \
"CREATE ROLE postgres_bench WITH \
LOGIN ENCRYPTED PASSWORD 'gelbenchmark';"
$(PSQL_CMD) -U postgres -tc \
"CREATE DATABASE postgres_bench WITH OWNER = postgres_bench;"
load-postgres-helpers: docker-postgres
$(PSQL_CMD) -U postgres_bench -d postgres_bench -tc "\
CREATE OR REPLACE VIEW movie_view AS \
SELECT \
movies.id, \
movies.image, \
movies.title, \
movies.year, \
movies.description, \
movies.avg_rating AS avg_rating \
FROM movies; \
CREATE OR REPLACE VIEW person_view AS \
SELECT \
persons.id, \
persons.first_name, \
persons.middle_name, \
persons.last_name, \
persons.image, \
persons.bio, \
persons.full_name AS full_name \
FROM persons; \
"
load-hasura: load-postgres-helpers
$(PSQL_CMD) -d postgres_bench -tc \
"DROP SCHEMA IF EXISTS hdb_catalog CASCADE;"
$(PSQL_CMD) -d postgres_bench -tc \
"DROP SCHEMA IF EXISTS hdb_views CASCADE;"
$(PSQL_CMD) -d postgres_bench -tc \
"CREATE EXTENSION IF NOT EXISTS pgcrypto;"
_hasura/docker-run.sh
sleep 60s
(cd _hasura && ./send-metadata.sh)
load-prisma: docker-postgres
cd _prisma && \
npm i && \
echo 'DATABASE_URL="postgresql://postgres_bench:gelbenchmark@localhost:15432/postgres_bench?schema=public"' > .env && \
npx prisma generate && npm i
load-postgraphile: docker-postgres
cd _postgraphile && \
$(PSQL_CMD) -U postgres_bench -d postgres_bench \
--file=$(CURRENT_DIR)_postgraphile/helpers.sql && \
docker build -t postgraphile_bench:latest . && \
./run_postgraphile.sh
load-typeorm: $(BUILD)/dataset.json docker-postgres
$(PSQL_CMD) -tc \
"DROP DATABASE IF EXISTS typeorm_bench;"
$(PSQL_CMD) -tc \
"DROP ROLE IF EXISTS typeorm_bench;"
$(PSQL_CMD) -tc \
"CREATE ROLE typeorm_bench WITH \
LOGIN ENCRYPTED PASSWORD 'gelbenchmark';"
$(PSQL_CMD) -tc \
"CREATE DATABASE typeorm_bench WITH OWNER = typeorm_bench;"
cd _typeorm && \
npm i && \
npm run loaddata $(BUILD)/dataset.json && \
npm run build
load-sequelize: $(BUILD)/dataset.json docker-postgres
$(PSQL_CMD) -tc \
"DROP DATABASE IF EXISTS sequelize_bench;"
$(PSQL_CMD) -tc \
"DROP ROLE IF EXISTS sequelize_bench;"
$(PSQL_CMD) -tc \
"CREATE ROLE sequelize_bench WITH \
LOGIN ENCRYPTED PASSWORD 'gelbenchmark';"
$(PSQL_CMD) -tc \
"CREATE DATABASE sequelize_bench WITH OWNER = sequelize_bench;"
cd _sequelize && npm i && node loaddata.js $(BUILD)/dataset.json
load-drizzle: $(BUILD)/dataset.json load-postgres
cd _drizzle && npm i && npm run build
load: load-mongodb load-gel load-django load-sqlalchemy load-postgres \
load-typeorm load-sequelize load-prisma load-graphql load-drizzle
load-graphql: load-hasura load-postgraphile
compile:
make -C _go
RUNNER = python bench.py --query insert_movie --query get_movie --query get_user --concurrency 1 --duration 10 --net-latency 1
run-js:
$(RUNNER) --html docs/js.html --json docs/js.json typeorm sequelize prisma drizzle gel_js_qb
run-py:
$(RUNNER) --html docs/py.html --json docs/py.json django sqlalchemy gel_py_sync
run-sql:
$(RUNNER) --html docs/sql.html --json docs/sql.json gel_py_sync postgres_psycopg postgres_asyncpg postgres_pg postgres_pgx postgres_dart
run-graphql:
$(RUNNER) --html docs/py.html --json docs/py.json postgres_hasura_go postgres_postgraphile_go gel_go_graphql
run-orms:
$(RUNNER) --html docs/orms.html --json docs/orms.json typeorm sequelize prisma gel_js_qb django django_restfw mongodb sqlalchemy drizzle
run-gel:
$(RUNNER) --html docs/gel.html --json docs/gel.json gel_py_sync gel_py_json gel_py_json_async gel_go gel_go_json gel_go_graphql gel_go_http gel_js gel_js_json gel_js_qb gel_dart gel_dart_json
run-scratch:
python bench.py --query insert_movie --concurrency 1 --warmup-time 2 --duration 5 --html docs/scratch.html gel_go