Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions server/tests-py/remote_relationship_tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
__pycache__
test_output
45 changes: 45 additions & 0 deletions server/tests-py/remote_relationship_tests/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@


### Setup ###

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.

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.

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`.

#### Setup GraphQL Engines ####

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to add instructions for installing dependencies in a virtual environment:

$ python3 -m venv venv                                                                                                                                                                                                                     
$ source venv/bin/activate
$ pip3 install -r requirements.txt

and also to add that venv directory to the gitignore (there is probably a better name than "venv").

Also for some reason when I do the above I get some error messages:

Building wheels for collected packages: psycopg2, inflection
  Running setup.py bdist_wheel for psycopg2 ... error
  Complete output from command /home/me/Work/hasura/graphql-engine/server/tests-py/remote_relationship_tests/venv/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-bfabn9ae/psycopg2/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /tmp/tmpdkk7678ipip-wheel- --python-tag cp35:
  /usr/lib/python3.5/distutils/dist.py:261: UserWarning: Unknown distribution option: 'project_urls'
    warnings.warn(msg)
  usage: -c [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
     or: -c --help [cmd1 cmd2 ...]
     or: -c --help-commands
     or: -c cmd --help
  
  error: invalid command 'bdist_wheel'
  
  ----------------------------------------
  Failed building wheel for psycopg2
  Running setup.py clean for psycopg2
  Running setup.py bdist_wheel for inflection ... error
  Complete output from command /home/me/Work/hasura/graphql-engine/server/tests-py/remote_relationship_tests/venv/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-bfabn9ae/inflection/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /tmp/tmpez0s8qnepip-wheel- --python-tag cp35:
  usage: -c [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
     or: -c --help [cmd1 cmd2 ...]
     or: -c --help-commands
     or: -c cmd --help
  
  error: invalid command 'bdist_wheel'
  
  ----------------------------------------
  Failed building wheel for inflection
  Running setup.py clean for inflection

...but the overall pip3 command returns 0 status and the script seemed to start fine.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modified readme to add the instructions for installing dependencies in a virtual environment

I did not face the bdist_wheel error. Probably because I am using Python 3.7

Inorder to start GraphQL engines with sportsdb, run
```sh
python3 test_with_sportsdb.py
```

This will setup Postgres databases and runs the main and remote GraphQL servers
Pressing enter will teardown both Postgres database

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.

### Benchmarking ###

We may employ https://github.com/hasura/graphql-bench to do the benchmarks.

Create the `bench.yaml` file
```
- name: events_remote_affilications
warmup_duration: 60
duration: 300
candidates:
- name: hge-with-remote
url: http://127.0.0.1:8081/v1/graphql
query: events_remote_affiliations
queries_file: queries.graphql
rps:
- 20
- 40
```

To run the benchmark, do
```sh
cat bench.yaml | docker run -i --rm -p 8050:8050 -v $(pwd)/queries.graphql:/graphql-bench/ws/queries.graphql hasura/graphql-bench:v0.3
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be convenient if this bench,yaml or a variation that was a good default already existed somewhere, checked in to git.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An example benchmark file is included in the directory (example-bench.yaml)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be nice to remove the inline yaml from the Readme.md and just say "you can copy the example bench.yaml included at , and then run..."

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to understand what this is doing a little better. e.g. are we testing throughput? latency at different concurrency levels? If I run this script on a two-core machine will I receive sensible output? etc.

I'm sure some of this would be obvious if I got successful output. But maybe there are some docs that could be linked here.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is mainly testing the latency, the average, variance, 95 percentile etc. We can vary the number of request per second though.

```
27 changes: 27 additions & 0 deletions server/tests-py/remote_relationship_tests/port_allocator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import threading
import socket


class PortAllocator:

def __init__(self):
self.allocated_ports = set()
self.lock = threading.Lock()

def get_unused_port(self, start):
port = start
if self.is_port_open(port) or port in self.allocated_ports:
return self.get_unused_port(port + 1)
else:
return port

def is_port_open(self, port):
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
res = sock.connect_ex(('127.0.0.1', port))
return res == 0

def allocate_port(self, start):
with self.lock:
port = self.get_unused_port(start)
self.allocated_ports.add(port)
return port
27 changes: 27 additions & 0 deletions server/tests-py/remote_relationship_tests/queries.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
query events_affiliations {
hge_events(limit: 50){
event_status
last_update
affiliations_events_by_event_id(limit: 2) {
affiliation{
publisher{
publisher_name
}
}
}
}
}

query events_remote_affiliations {
hge_events(limit: 50){
event_status
last_update
remote_affiliations_events_by_event_id(limit: 2) {
affiliation{
publisher{
publisher_name
}
}
}
}
}
5 changes: 5 additions & 0 deletions server/tests-py/remote_relationship_tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
requests-cache
docker
psycopg2
colorama
inflection
Loading