-
Notifications
You must be signed in to change notification settings - Fork 24
/
Makefile
331 lines (272 loc) · 11 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-edgedb 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-edgedb
CURRENT_DIR = $(dir $(realpath $(firstword $(MAKEFILE_LIST))))
EDGEDB_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)/edbdataset.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:14
sleep 3
$(DOCKER) exec webapp-bench-postgres pg_isready -t10
docker-postgres-stop:
-$(DOCKER) stop webapp-bench-postgres
docker-edgedb-volume:
$(DOCKER) volume inspect webapp-bench-edgedb >/dev/null 2>&1 \
|| $(DOCKER) volume create webapp-bench-edgedb
docker-edgedb-volume-destroy:
$(DOCKER) volume inspect webapp-bench-edgedb >/dev/null 2>&1 \
&& $(DOCKER) volume rm webapp-bench-edgedb
docker-edgedb: docker-network docker-edgedb-volume
$(DOCKER) stop webapp-bench-edgedb >/dev/null 2>&1 || :
$(DOCKER) run --rm -d --name webapp-bench-edgedb \
-v webapp-bench-edgedb:/var/lib/edgedb/data \
-e EDGEDB_SERVER_SECURITY=insecure_dev_mode \
--network=webapp-bench \
-p 15656:5656 \
edgedb/edgedb:$(EDGEDB_VERSION)
edgedb -H localhost -P 15656 \
--tls-security=insecure --wait-until-available=120s \
query "SELECT 'EdgeDB ready'"
docker-edgedb-stop:
$(DOCKER) stop webapp-bench-edgedb
stop-docker:
-$(DOCKER) stop hasura-bench
-$(DOCKER) stop postgraphile-bench
-$(DOCKER) stop webapp-bench-postgres
-$(DOCKER) stop webapp-bench-edgedb
docker-clean: stop-docker docker-network-destroy \
docker-postgres-volume-destroy docker-edgedb-volume-destroy
load-mongodb: $(BUILD)/edbdataset.json
$(PP) -m _mongodb.loaddata $(BUILD)/edbdataset.json
load-edgedb-nobulk: $(BUILD)/edbdataset.json docker-edgedb
-edgedb project unlink
-edgedb instance destroy edgedb_bench --force
edgedb -H localhost -P 15656 instance link \
--non-interactive --trust-tls-cert --overwrite edgedb_bench \
&& edgedb -H localhost -P 15656 project init --link \
--non-interactive --no-migrations --server-instance edgedb_bench
edgedb query 'CREATE DATABASE temp'
edgedb -d temp query 'DROP DATABASE edgedb'
edgedb -d temp query 'CREATE DATABASE edgedb'
edgedb query 'DROP DATABASE temp'
edgedb migrate
$(PP) -m _edgedb.loaddata_nobulk $(BUILD)/edbdataset.json
load-edgedb: $(BUILD)/edbdataset.json docker-edgedb
-edgedb project unlink --non-interactive
-edgedb instance destroy edgedb_bench --force
edgedb -H localhost -P 15656 instance link \
--non-interactive --trust-tls-cert --overwrite edgedb_bench
edgedb -H localhost -P 15656 project init --link \
--non-interactive --no-migrations --server-instance edgedb_bench
edgedb query 'CREATE DATABASE temp'
edgedb -d temp query 'DROP DATABASE edgedb'
edgedb -d temp query 'CREATE DATABASE edgedb'
edgedb query 'DROP DATABASE temp'
edgedb migrate
$(PP) -m _edgedb.loaddata $(BUILD)/edbdataset.json
cd _edgedb_js && npm i && npx @edgedb/generate edgeql-js --output-dir querybuilder --target cjs --force-overwrite
load-edgedb-nosetup:
$(PP) -m _edgedb.loaddata $(BUILD)/edbdataset.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 'edgedbbenchmark';"
$(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 'edgedbbenchmark';"
$(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-stop 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 'edgedbbenchmark';"
$(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:edgedbbenchmark@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 'edgedbbenchmark';"
$(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 'edgedbbenchmark';"
$(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-edgedb 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 edgedb_js_qb
run-py:
$(RUNNER) --html docs/py.html --json docs/py.json django sqlalchemy edgedb_py_sync
run-sql:
$(RUNNER) --html docs/sql.html --json docs/sql.json edgedb_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 edgedb_go_graphql
run-orms:
$(RUNNER) --html docs/orms.html --json docs/orms.json typeorm sequelize prisma edgedb_js_qb django django_restfw mongodb sqlalchemy drizzle
run-edgedb:
$(RUNNER) --html docs/edgedb.html --json docs/edgedb.json edgedb_py_sync edgedb_py_json edgedb_py_json_async edgedb_go edgedb_go_json edgedb_go_graphql edgedb_go_http edgedb_js edgedb_js_json edgedb_js_qb edgedb_dart edgedb_dart_json
run-scratch:
python bench.py --query insert_movie --concurrency 1 --warmup-time 2 --duration 5 --html docs/scratch.html edgedb_go