Skip to content

Commit d26fa0b

Browse files
authored
benchmarks (#298)
* init: benchmarks * ci: remove cargo and cache * ci: add setup project * ci: add back cache * ci: change to pnpm * ci: * * ci: change hash files * ci: loud install debug * ci: empty command * ci: remove install for npm as pnpm manages this * package: * * fix: add peer graphql * * * *
1 parent adc1f78 commit d26fa0b

File tree

23 files changed

+1501
-4
lines changed

23 files changed

+1501
-4
lines changed

.github/workflows/benchmarks.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Run benchmarks
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
8+
paths-ignore:
9+
- README.md
10+
11+
jobs:
12+
benchmarks:
13+
runs-on: ubuntu-latest
14+
timeout-minutes: 30
15+
steps:
16+
- uses: actions/checkout@v3
17+
- uses: ./.github/actions/setup-project
18+
- uses: fregante/setup-git-user@v2
19+
- uses: cachix/install-nix-action@v24
20+
with:
21+
nix_path: nixpkgs=channel:nixos-unstable
22+
- uses: actions/cache@v3
23+
with:
24+
path: |
25+
~/.ivy2/cache
26+
~/.sbt
27+
key: ${{ runner.os }}-sbt-${{ hashFiles('**/build.sbt') }}
28+
- uses: actions/cache@v3
29+
with:
30+
path: |
31+
~/.cargo/bin/
32+
~/.cargo/registry/index/
33+
~/.cargo/registry/cache/
34+
~/.cargo/git/db/
35+
async-graphql/target
36+
juniper/target
37+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
38+
- uses: actions/cache@v3
39+
with:
40+
path: ~/.npm
41+
key: ${{ runner.os }}-node-${{ hashFiles('**/package.json') }}
42+
- name: Run benchmarks
43+
working-directory: ./benchmarks
44+
run: nix-shell --quiet --run ./run.cr
45+
- name: Push readme
46+
if: ${{ github.event_name == 'push' }}
47+
run: |
48+
git add README.md
49+
git commit -m "update readme"
50+
git push

.turbo/daemon/b418ceec9a896940-turbo.log.2024-04-29

Whitespace-only changes.

benchmarks/README.ecr

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<!-- README.md is generated from README.ecr, do not edit -->
2+
3+
# GraphQL Debugger Benchmarks
4+
5+
https://www.graphql-debugger.com
6+
7+
Graphql server benchmarks in many frameworks.
8+
9+
All servers implement a simple schema:
10+
11+
```graphql
12+
type Query {
13+
hello: String!
14+
}
15+
```
16+
17+
The returned string is always `world`.
18+
19+
The API is served over HTTP using a common web server and load tested using [bombardier](https://github.com/codesenberg/bombardier).
20+
21+
### Results
22+
23+
| Name | Language | Server | Latency avg | Requests |
24+
| ---------------------------- | ------------- | --------------- | ---------------- | ------------- |
25+
<%- benchmarks.each do |b| -%>
26+
| [<%= b.name %>](<%= b.url %>) | <%= b.lang %> | <%= b.server %> | <%= b.latency %> | <%= b.reqs %> |
27+
<%- end -%>

benchmarks/README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<!-- README.md is generated from README.ecr, do not edit -->
2+
3+
# GraphQL Debugger Benchmarks
4+
5+
https://www.graphql-debugger.com
6+
7+
Graphql server benchmarks in many frameworks.
8+
9+
All servers implement a simple schema:
10+
11+
```graphql
12+
type Query {
13+
hello: String!
14+
}
15+
```
16+
17+
The returned string is always `world`.
18+
19+
The API is served over HTTP using a common web server and load tested using [bombardier](https://github.com/codesenberg/bombardier).
20+
21+
### Results
22+
23+
| Name | Language | Server | Latency avg | Requests |
24+
| -------------------------------------------------------------------- | -------- | ------- | ----------- | -------- |
25+
| [yoga](https://github.com/dotansimha/graphql-yoga) | Node.js | http | 15.25ms | 13kps |
26+
| [apollo](https://github.com/apollographql/apollo-server) | Node.js | Express | 33.20ms | 6.0kps |
27+
| [yoga-otel](https://github.com/open-telemetry/opentelemetry-js/) | Node.js | http | 34.11ms | 5.8kps |
28+
| [helix](https://github.com/contra/graphql-helix) | Node.js | http | 46.29ms | 4.3kps |
29+
| [yoga-debugger](https://graphql-debugger.com/docs/plugins/yoga) | Node.js | http | 89.22ms | 2.2kps |
30+
| [apollo-debugger](https://graphql-debugger.com/docs/plugins/apollo) | Node.js | Express | 100.57ms | 2.0kps |
31+
| [helix-debugger](https://github.com/rocket-connect/graphql-debugger) | Node.js | http | 106.46ms | 1.9kps |
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { graphqlDebuggerPlugin } from "@graphql-debugger/apollo-server";
2+
3+
import { ApolloServer } from "apollo-server";
4+
import cluster from "cluster";
5+
import { cpus } from "os";
6+
7+
process.env.PORT = "8000";
8+
9+
if (cluster.isPrimary) {
10+
for (let i = 0; i < cpus().length; i++) {
11+
cluster.fork();
12+
}
13+
} else {
14+
const server = new ApolloServer({
15+
typeDefs: `
16+
type Query {
17+
hello: String!
18+
}
19+
`,
20+
resolvers: {
21+
Query: {
22+
hello: () => "world",
23+
},
24+
},
25+
plugins: [graphqlDebuggerPlugin()],
26+
});
27+
28+
server.listen(8000);
29+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"peerDependencies": {
3+
"graphql": "^16.0.0 || ^17.0.0"
4+
},
5+
"dependencies": {
6+
"@graphql-debugger/apollo-server": "workspace:^",
7+
"apollo-server": "3.13.0"
8+
},
9+
"type": "module"
10+
}

benchmarks/apollo/index.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { ApolloServer } from "apollo-server";
2+
import cluster from "cluster";
3+
import { cpus } from "os";
4+
5+
process.env.PORT = "8000";
6+
7+
if (cluster.isPrimary) {
8+
for (let i = 0; i < cpus().length; i++) {
9+
cluster.fork();
10+
}
11+
} else {
12+
const server = new ApolloServer({
13+
typeDefs: `
14+
type Query {
15+
hello: String!
16+
}
17+
`,
18+
resolvers: {
19+
Query: {
20+
hello: () => "world",
21+
},
22+
},
23+
});
24+
25+
server.listen(8000);
26+
}

benchmarks/apollo/package.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"peerDependencies": {
3+
"graphql": "^16.0.0 || ^17.0.0"
4+
},
5+
"dependencies": {
6+
"apollo-server": "3.13.0"
7+
},
8+
"type": "module"
9+
}

benchmarks/benchmarks.yaml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
- id: helix
2+
name: helix
3+
url: https://github.com/contra/graphql-helix
4+
lang: Node.js
5+
server: http
6+
run:
7+
cmd: node
8+
args: ["index.js"]
9+
- id: helix-debugger
10+
name: helix-debugger
11+
url: https://github.com/rocket-connect/graphql-debugger
12+
lang: Node.js
13+
server: http
14+
run:
15+
cmd: node
16+
args: ["index.js"]
17+
- id: yoga
18+
name: yoga
19+
url: https://github.com/dotansimha/graphql-yoga
20+
lang: Node.js
21+
server: http
22+
run:
23+
cmd: node
24+
args: ["--no-warnings", "index.js"]
25+
- id: yoga-debugger
26+
name: yoga-debugger
27+
url: https://graphql-debugger.com/docs/plugins/yoga
28+
lang: Node.js
29+
server: http
30+
run:
31+
cmd: node
32+
args: ["--no-warnings", "index.js"]
33+
- id: yoga-otel
34+
name: yoga-otel
35+
url: https://github.com/open-telemetry/opentelemetry-js/
36+
lang: Node.js
37+
server: http
38+
run:
39+
cmd: node
40+
args: ["--no-warnings", "index.js"]
41+
- id: apollo
42+
name: apollo
43+
url: https://github.com/apollographql/apollo-server
44+
lang: Node.js
45+
server: Express
46+
run:
47+
cmd: node
48+
args: ["--no-warnings", "index.js"]
49+
- id: apollo-debugger
50+
name: apollo-debugger
51+
url: https://graphql-debugger.com/docs/plugins/apollo
52+
lang: Node.js
53+
server: Express
54+
run:
55+
cmd: node
56+
args: ["--no-warnings", "index.js"]

benchmarks/helix-debugger/index.js

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import { ProxyAdapter } from "@graphql-debugger/adapter-proxy";
2+
import {
3+
GraphQLDebuggerContext,
4+
traceSchema,
5+
} from "@graphql-debugger/trace-schema";
6+
7+
import cluster from "cluster";
8+
import express from "express";
9+
import { GraphQLObjectType, GraphQLSchema, GraphQLString } from "graphql";
10+
import {
11+
getGraphQLParameters,
12+
processRequest,
13+
sendResult,
14+
} from "graphql-helix";
15+
import { cpus } from "os";
16+
17+
if (cluster.isPrimary) {
18+
for (let i = 0; i < cpus().length; i++) {
19+
cluster.fork();
20+
}
21+
} else {
22+
var schema = new GraphQLSchema({
23+
query: new GraphQLObjectType({
24+
name: "Query",
25+
fields: {
26+
hello: {
27+
type: GraphQLString,
28+
resolve() {
29+
return "world";
30+
},
31+
},
32+
},
33+
}),
34+
});
35+
36+
var tracedSchema = traceSchema({
37+
schema,
38+
adapter: new ProxyAdapter(),
39+
shouldExportSchema: false,
40+
});
41+
42+
var app = express();
43+
app.use(express.json());
44+
45+
app.use("/graphql", async (req, res) => {
46+
const request = {
47+
body: req.body,
48+
headers: req.headers,
49+
method: req.method,
50+
query: req.query,
51+
};
52+
53+
const { operationName, query, variables } = getGraphQLParameters(request);
54+
55+
const result = await processRequest({
56+
operationName,
57+
query,
58+
variables,
59+
request,
60+
schema: tracedSchema,
61+
contextFactory: () => ({
62+
GraphQLDebuggerContext: new GraphQLDebuggerContext({
63+
schema,
64+
}),
65+
}),
66+
});
67+
68+
sendResult(result, res);
69+
});
70+
71+
app.listen(8000);
72+
}

0 commit comments

Comments
 (0)