Skip to content

Commit 4895c23

Browse files
committed
Setup for remote relationship benchmarks using sportsdb
1 parent 2d9b323 commit 4895c23

File tree

8 files changed

+750
-0
lines changed

8 files changed

+750
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
__pycache__
2+
test_output
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
2+
3+
### Setup ###
4+
5+
The test setup includes two Postgres databases with [sportsdb](https://www.thesportsdb.com/) schema and data, and two GraphQL engines running on the Postgres databases. Then one of the GraphQL engines is added as a remote schema to another GraphQL engine.
6+
7+
The data will be same in both the databases. But the tables will reside in different database schema in-order to avoid GraphQL schema conflicts.
8+
9+
The Python script `test_with_sportsdb.py` will help in setting up the databases, starting the Hasura GraphQL engines, and setting up relationships (both local and remote). This script will run databases on docker, and the GraphQL engines are run with `stack exec`.
10+
11+
#### Setup GraphQL Engines ####
12+
13+
Inorder to start GraphQL engines with sportsdb, run
14+
```sh
15+
python3 test_with_sportsdb.py
16+
```
17+
18+
This will setup Postgres databases and runs the main and remote GraphQL servers
19+
Pressing enter will teardown both Postgres database
20+
21+
The initial setup will take some time. The subsequent ones will be faster. The Postgres data is bind mounted from a volume in the host, which will be reused.
22+
23+
### Benchmarking ###
24+
25+
We may employ https://github.com/hasura/graphql-bench to do the benchmarks.
26+
27+
Create the `bench.yaml` file
28+
```
29+
- name: events_remote_affilications
30+
warmup_duration: 60
31+
duration: 300
32+
candidates:
33+
- name: hge-with-remote
34+
url: http://127.0.0.1:8081/v1/graphql
35+
query: events_remote_affiliations
36+
queries_file: queries.graphql
37+
rps:
38+
- 20
39+
- 40
40+
```
41+
42+
To run the benchmark, do
43+
```sh
44+
cat bench.yaml | docker run -i --rm -p 8050:8050 -v $(pwd)/queries.graphql:/graphql-bench/ws/queries.graphql hasura/graphql-bench:v0.3
45+
```
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import threading
2+
import socket
3+
4+
5+
class PortAllocator:
6+
7+
def __init__(self):
8+
self.allocated_ports = set()
9+
self.lock = threading.Lock()
10+
11+
def get_unused_port(self, start):
12+
port = start
13+
if self.is_port_open(port) or port in self.allocated_ports:
14+
return self.get_unused_port(port + 1)
15+
else:
16+
return port
17+
18+
def is_port_open(self, port):
19+
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
20+
res = sock.connect_ex(('127.0.0.1', port))
21+
return res == 0
22+
23+
def allocate_port(self, start):
24+
with self.lock:
25+
port = self.get_unused_port(start)
26+
self.allocated_ports.add(port)
27+
return port
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
query events_affiliations {
2+
hge_events(limit: 50){
3+
event_status
4+
last_update
5+
affiliations_events_by_event_id(limit: 2) {
6+
affiliation{
7+
publisher{
8+
publisher_name
9+
}
10+
}
11+
}
12+
}
13+
}
14+
15+
query events_remote_affiliations {
16+
hge_events(limit: 50){
17+
event_status
18+
last_update
19+
remote_affiliations_events_by_event_id(limit: 2) {
20+
affiliation{
21+
publisher{
22+
publisher_name
23+
}
24+
}
25+
}
26+
}
27+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
requests-cache
2+
docker
3+
psycopg2
4+
colorama
5+
inflection

0 commit comments

Comments
 (0)