-
Notifications
You must be signed in to change notification settings - Fork 24
/
_shared.py
287 lines (224 loc) · 8.11 KB
/
_shared.py
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
#
# Copyright (c) 2019 MagicStack Inc.
# All rights reserved.
#
# See LICENSE for details.
##
import argparse
import sys
import types
import typing
from _edgedb import queries_json as edgedb_queries_json
from _edgedb import queries_async as edgedb_queries_async
from _edgedb import queries_repack as edgedb_queries_repack
from _go.edgedb import queries_edgedb as edgedb_json_golang
from _go.postgres import queries_pq as postgres_pq_golang
from _go.postgres import queries_pgx as postgres_pgx_golang
from _go.http import queries_graphql as edgedb_graphql_golang
from _go.http import queries_hasura as postgres_hasura_golang
from _go.http import queries_postgraphile as postgres_postgraphile_golang
from _go.http import queries_http as edgedb_edgeql_golang
from _django import queries as django_queries
from _django import queries_restfw as django_queries_restfw
from _mongodb import queries as mongodb_queries
from _sqlalchemy import queries as sqlalchemy_queries
from _sqlalchemy import queries_asyncio as sqlalchemy_queries_asyncio
from _postgres import queries as postgres_queries
from _postgres import queries_psycopg as postgres_psycopg_queries
class impl(typing.NamedTuple):
language: str
title: str
module: typing.Optional[types.ModuleType]
IMPLEMENTATIONS = {
'edgedb_py_json':
impl('python', 'EdgeDB (Python, JSON)', edgedb_queries_json),
'edgedb_py_json_async':
impl('python', 'EdgeDB (Python, JSON, asyncio)', edgedb_queries_async),
'edgedb_py_sync':
impl('python', 'EdgeDB (Python)', edgedb_queries_repack),
'edgedb_go':
impl('go', 'EdgeDB (Go)', edgedb_json_golang),
'edgedb_go_json':
impl('go', 'EdgeDB (Go, JSON)', edgedb_json_golang),
'edgedb_go_graphql':
impl('go', 'EdgeDB (GraphQL)', edgedb_graphql_golang),
'edgedb_go_http':
impl('go', 'EdgeDB (HTTP)', edgedb_edgeql_golang),
'django':
impl('python', 'Django ORM', django_queries),
'django_restfw':
impl('python', 'Django (Rest Framework)', django_queries_restfw),
'mongodb':
impl('python', 'MongoDB (Python)', mongodb_queries),
'sqlalchemy':
impl('python', 'SQLAlchemy', sqlalchemy_queries),
'sqlalchemy_asyncio':
impl('python', 'SQLAlchemy (asyncio)', sqlalchemy_queries_asyncio),
'postgres_asyncpg':
impl('python', 'PostgreSQL (Python, asyncpg)', postgres_queries),
'postgres_psycopg':
impl('python', 'PostgreSQL (Python, psycopg2)', postgres_psycopg_queries),
'postgres_pq':
impl('go', 'PostgreSQL (Go, pq)', postgres_pq_golang),
'postgres_pgx':
impl('go', 'PostgreSQL (Go, pgx)', postgres_pgx_golang),
'postgres_hasura_go':
impl('go', 'Hasura + Postgres (Go)', postgres_hasura_golang),
'postgres_postgraphile_go':
impl('go', 'Postgraphile (Go)',
postgres_postgraphile_golang),
'edgedb_js':
impl('js', 'EdgeDB (Node.js)', None),
'edgedb_js_json':
impl('js', 'EdgeDB (Node.js, JSON mode)', None),
'edgedb_js_qb':
impl('js', 'EdgeDB (Node.js, query builder)', None),
'edgedb_js_qb_uncached':
impl('js', 'EdgeDB (Node.js, query builder, uncached)', None),
'typeorm':
impl('js', 'TypeORM', None),
'sequelize':
impl('js', 'Sequelize', None),
'postgres_pg':
impl('js', 'PostgreSQL (Node.js, pg)', None),
'prisma_untuned':
impl('js', 'Prisma (Untuned)', None),
'prisma':
impl('js', 'Prisma', None),
'drizzle':
impl('js', 'Drizzle', None),
'edgedb_dart':
impl('dart', 'EdgeDB (Dart)', None),
'edgedb_dart_json':
impl('dart', 'EdgeDB (Dart, JSON mode)', None),
'postgres_dart':
impl('dart', 'Postgres (Dart)', None),
}
class bench(typing.NamedTuple):
title: str
description: str
BENCHMARKS = {
'get_movie':
bench(
title="GET /movie/:id",
description=(
"Get information about a given movie: title, year, directors, "
"cast, recent reviews, and average review rating."
)
),
'get_person':
bench(
title="GET /person/:id",
description=(
"Get information about a given person: full name, bio, "
"list of movies acted in or directed."
)
),
'get_user':
bench(
title="GET /user/:id",
description=(
"Get information about a given user: name and a sample of "
"the latest movie reviews this user authored."
)
),
'update_movie':
bench(
title="PATCH /movie/:id",
description=(
"Update the title of a movie."
)
),
'insert_user':
bench(
title="POST /user",
description=(
"Create a new user record."
)
),
'insert_movie':
bench(
title="POST /movie (existing cast)",
description=(
"Create a new movie record, linking existing directors "
"and cast."
)
),
'insert_movie_plus':
bench(
title="POST /movie (new cast)",
description=(
"Create a new movie record, linking newly inserted directors "
"and cast."
)
),
}
def parse_args(*, prog_desc: str, out_to_json: bool = False,
out_to_html: bool = False):
parser = argparse.ArgumentParser(
description=prog_desc,
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument(
'-C', '--concurrency', type=int, default=1,
help='number of concurrent connections')
parser.add_argument(
'--async-split', type=int, default=1,
help='number of processes to split Python async connections')
parser.add_argument(
'--db-host', type=str, default='127.0.0.1',
help='host with databases')
parser.add_argument(
'-D', '--duration', type=int, default=30,
help='duration of test in seconds')
parser.add_argument(
'--timeout', default=2, type=int,
help='server timeout in seconds')
parser.add_argument(
'--warmup-time', type=int, default=5,
help='duration of warmup period for each benchmark in seconds')
parser.add_argument(
'--net-latency', default=0, type=int,
help='assumed p0 roundtrip latency between a database and a client')
parser.add_argument(
'--pg-port', type=int, default=15432,
help='PostgreSQL server port')
parser.add_argument(
'--edgedb-port', type=int, default=None,
help='EdgeDB server port')
parser.add_argument(
'--mongodb-port', type=int, default=27017,
help='MongoDB server port')
parser.add_argument(
'--number-of-ids', type=int, default=250,
help='number of random IDs to fetch data with in benchmarks')
parser.add_argument(
'--query', dest='queries', action='append',
help='queries to benchmark',
choices=list(BENCHMARKS.keys()) + ['all'])
parser.add_argument(
'benchmarks', nargs='+', help='benchmarks names',
choices=list(IMPLEMENTATIONS.keys()) + ['all'])
if out_to_json:
parser.add_argument(
'--json', type=str, default='',
help='filename to dump serialized results in JSON')
if out_to_html:
parser.add_argument(
'--html', type=str, default='',
help='filename to dump HTML report')
args = parser.parse_args()
argv = sys.argv[1:]
if not args.queries:
args.queries = list(BENCHMARKS.keys())
if args.concurrency % args.async_split != 0:
raise Exception(
"'--concurrency' must be an integer multiple of '--async-split'")
if 'all' in args.benchmarks:
args.benchmarks = list(IMPLEMENTATIONS.keys())
if out_to_json and args.json:
i = argv.index('--json')
del argv[i:i + 2]
if out_to_html and args.html:
i = argv.index('--html')
del argv[i:i + 2]
return args, argv