Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

community: add graphql benchmark #9401

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
15 changes: 15 additions & 0 deletions community/sample-apps/graphql-benchmark/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# GraphQL Benchmarking

Uses the [Chinook sample database](https://github.com/lerocha/chinook-database). Tested on macOS Ventura 13.1.

## Instructions

1. Checkout [https://github.com/hasura/graphql-bench](https://github.com/hasura/graphql-bench) and build the docker container with `make build_local_docker_image`

1. Run `docker compose -f docker-compose.hasura.yml up -d` to bootstrap Postgres with Chinook.

1. After a few minutes check the Hasura docker logs to see if Hasura is running, which implies the database is now bootstrapped. Run `docker compose -f docker-compose.hasura.yml down`

1. Run the benchmarks `sh benchmark.sh`

1. Open the results on the GraphQL bench website [https://hasura.github.io/graphql-bench/app/web-app/](https://hasura.github.io/graphql-bench/app/web-app/)
31 changes: 31 additions & 0 deletions community/sample-apps/graphql-benchmark/benchmark.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/sh

docker compose -f docker-compose.hasura.yml up -d --build

echo "Running Hasura Benchmark"

sleep 5

docker run --net=host -v "$PWD":/app/tmp -it \
graphql-bench-local query \
--config="./tmp/config.query.hasura.yaml" \
--outfile="./tmp/report.hasura.json"

docker compose -f docker-compose.hasura.yml down

echo "Hasura Benchmark done"

docker compose -f docker-compose.node.yml up -d --build

echo "Running Nodejs Benchmark"

sleep 5

docker run --net=host -v "$PWD":/app/tmp -it \
graphql-bench-local query \
--config="./tmp/config.query.node.yaml" \
--outfile="./tmp/report.nodejs.json"

docker compose -f docker-compose.node.yml down

echo "Node.js Benchmark done"
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# url: "http://host.docker.internal:8080/v1/graphql"
url: https://benchmark-hasura-rso3d2ja7a-uc.a.run.app/v1/graphql
headers:
content-type: application/json
# "Debug" mode enables request and response logging for Autocannon and K6
# This lets you see what is happening and confirm proper behavior.
# This should be disabled for genuine benchmarks, and only used for debugging/visibility.
debug: false
queries:
# Name: Unique name for the query
- name: GetAllArtistsAlbumsAndTracks
# Tools: List of benchmarking tools to run: ['autocannon', 'k6', 'wrk2']
tools: [k6]
execution_strategy: REQUESTS_PER_SECOND
rps: 2000
duration: 10s
connections: 50
query: |
query GetAllArtistsAlbumsTracks_Genres {
Artist {
ArtistId
Name
Albums {
AlbumId
Title
Tracks {
TrackId
Name
Composer
Genre {
GenreId
Name
}
}
}
}
}
- name: AlbumByPK
tools: [k6]
execution_strategy: FIXED_REQUEST_NUMBER
requests: 10000
query: |
query AlbumByPK {
Album_by_pk(AlbumId: 1) {
AlbumId
Title
}
}
- name: AlbumByPKMultiStage
tools: [k6]
execution_strategy: MULTI_STAGE
initial_rps: 0
stages:
- duration: 5s
target: 100
- duration: 5s
target: 1000
query: |
query AlbumByPK {
Album_by_pk(AlbumId: 1) {
AlbumId
Title
}
}
64 changes: 64 additions & 0 deletions community/sample-apps/graphql-benchmark/config.query.node.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# url: "http://host.docker.internal:8080/v1/graphql"
url: https://benchmark-node-rso3d2ja7a-ul.a.run.app/v1/graphql
headers:
content-type: application/json
# "Debug" mode enables request and response logging for Autocannon and K6
# This lets you see what is happening and confirm proper behavior.
# This should be disabled for genuine benchmarks, and only used for debugging/visibility.
debug: false
queries:
# Name: Unique name for the query
- name: GetAllArtistsAlbumsAndTracks
# Tools: List of benchmarking tools to run: ['autocannon', 'k6', 'wrk2']
tools: [k6]
execution_strategy: REQUESTS_PER_SECOND
rps: 2000
duration: 10s
connections: 10
query: |
query GetAllArtistsAlbumsTracks_Genres {
Artist {
ArtistId
Name
Albums {
AlbumId
Title
Tracks {
TrackId
Name
Composer
Genre {
GenreId
Name
}
}
}
}
}
- name: AlbumByPK
tools: [k6]
execution_strategy: FIXED_REQUEST_NUMBER
requests: 10000
query: |
query AlbumByPK {
Album_by_pk(AlbumId: 1) {
AlbumId
Title
}
}
- name: AlbumByPKMultiStage
tools: [k6]
execution_strategy: MULTI_STAGE
initial_rps: 0
stages:
- duration: 5s
target: 100
- duration: 5s
target: 1000
query: |
query AlbumByPK {
Album_by_pk(AlbumId: 1) {
AlbumId
Title
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
services:
postgres:
image: postgres:15
restart: always
volumes:
- db_data:/var/lib/postgresql/data
ports:
- "5432:5432"
environment:
POSTGRES_PASSWORD: postgrespassword
graphql-engine:
image: hasura/graphql-engine:v2.18.0.cli-migrations-v3
volumes:
- ./hasura/migrations:/hasura-migrations
- ./hasura/metadata:/hasura-metadata
ports:
- "8080:8080"
depends_on:
- "postgres"
restart: always
environment:
## postgres database to store Hasura metadata
HASURA_GRAPHQL_METADATA_DATABASE_URL: postgres://postgres:postgrespassword@postgres:5432/postgres
## this env var can be used to add the above postgres database to Hasura as a data source. this can be removed/updated based on your needs
PG_DATABASE_URL: postgres://postgres:postgrespassword@postgres:5432/postgres
## enable the console served by server
HASURA_GRAPHQL_ENABLE_CONSOLE: "true" # set to "false" to disable console
## enable debugging mode. It is recommended to disable this in production
HASURA_GRAPHQL_DEV_MODE: "true"
HASURA_GRAPHQL_ENABLED_LOG_TYPES: startup, http-log, webhook-log, websocket-log, query-log
## uncomment next line to run console offline (i.e load console assets from server instead of CDN)
# HASURA_GRAPHQL_CONSOLE_ASSETS_DIR: /srv/console-assets
## uncomment next line to set an admin secret
# HASURA_GRAPHQL_ADMIN_SECRET: myadminsecretkey
volumes:
db_data:
18 changes: 18 additions & 0 deletions community/sample-apps/graphql-benchmark/docker-compose.node.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
services:
postgres:
image: postgres:15
restart: always
volumes:
- db_data:/var/lib/postgresql/data
ports:
- "5432:5432"
environment:
POSTGRES_PASSWORD: postgrespassword
node:
build: ./nodejs
ports:
- "8080:8080"
depends_on:
- "postgres"
volumes:
db_data:
6 changes: 6 additions & 0 deletions community/sample-apps/graphql-benchmark/hasura/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 3
endpoint: http://localhost:8080
metadata_directory: metadata
actions:
kind: synchronous
handler_webhook_baseurl: http://localhost:3000
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
actions: []
custom_types:
enums: []
input_objects: []
objects: []
scalars: []
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
- name: default
kind: postgres
configuration:
connection_info:
database_url:
from_env: PG_DATABASE_URL
isolation_level: read-committed
use_prepared_statements: false
tables: "!include default/tables/tables.yaml"
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
table:
name: Album
schema: public
object_relationships:
- name: Artist
using:
foreign_key_constraint_on: ArtistId
array_relationships:
- name: Tracks
using:
foreign_key_constraint_on:
column: AlbumId
table:
name: Track
schema: public
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
table:
name: Artist
schema: public
array_relationships:
- name: Albums
using:
foreign_key_constraint_on:
column: ArtistId
table:
name: Album
schema: public
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
table:
name: Customer
schema: public
object_relationships:
- name: Employee
using:
foreign_key_constraint_on: SupportRepId
array_relationships:
- name: Invoices
using:
foreign_key_constraint_on:
column: CustomerId
table:
name: Invoice
schema: public
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
table:
name: Employee
schema: public
object_relationships:
- name: Employee
using:
foreign_key_constraint_on: ReportsTo
array_relationships:
- name: Customers
using:
foreign_key_constraint_on:
column: SupportRepId
table:
name: Customer
schema: public
- name: Employees
using:
foreign_key_constraint_on:
column: ReportsTo
table:
name: Employee
schema: public
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
table:
name: Genre
schema: public
array_relationships:
- name: Tracks
using:
foreign_key_constraint_on:
column: GenreId
table:
name: Track
schema: public
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
table:
name: Invoice
schema: public
object_relationships:
- name: Customer
using:
foreign_key_constraint_on: CustomerId
array_relationships:
- name: InvoiceLines
using:
foreign_key_constraint_on:
column: InvoiceId
table:
name: InvoiceLine
schema: public
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
table:
name: InvoiceLine
schema: public
object_relationships:
- name: Invoice
using:
foreign_key_constraint_on: InvoiceId
- name: Track
using:
foreign_key_constraint_on: TrackId
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
table:
name: MediaType
schema: public
array_relationships:
- name: Tracks
using:
foreign_key_constraint_on:
column: MediaTypeId
table:
name: Track
schema: public
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
table:
name: Playlist
schema: public
array_relationships:
- name: PlaylistTracks
using:
foreign_key_constraint_on:
column: PlaylistId
table:
name: PlaylistTrack
schema: public
Loading