hoangvvo / benzene

⌬ Fast, minimal, agnostic GraphQL Servers ⌬
https://benzene.vercel.app
Other
164 stars 6 forks source link

Hyper-Express + Benzene benchmark #78

Open dougg0k opened 2 years ago

dougg0k commented 2 years ago

Just tried out what is in the title, gave the best result.

https://github.com/kartikk221/hyper-express

https://github.com/kartikk221/hyper-express/blob/master/docs/Benchmarks.md

Machine: Linux 5.15.25-xanmod1 x86_64 | 16 vCPUs | 32GB
Node: v16.13.0

apollo-server
  Slowest:  0.0564 secs
  Fastest:  0.0038 secs
  Average:  0.0192 secs
  Requests/sec: 5204.7523

benzene-http
  Slowest:  0.0230 secs
  Fastest:  0.0036 secs
  Average:  0.0070 secs
  Requests/sec: 14187.0487

benzene-jit-http
  Slowest:  0.0165 secs
  Fastest:  0.0032 secs
  Average:  0.0041 secs
  Requests/sec: 24527.6361

express-graphql
  Slowest:  0.0818 secs
  Fastest:  0.0039 secs
  Average:  0.0323 secs
  Requests/sec: 3092.1393

graphql-helix
  Slowest:  0.0779 secs
  Fastest:  0.0045 secs
  Average:  0.0316 secs
  Requests/sec: 3153.4511

hyper-express-benzene
  Slowest:  0.0128 secs
  Fastest:  0.0004 secs
  Average:  0.0036 secs
  Requests/sec: 27913.0988

mercurius
  Slowest:  0.0259 secs
  Fastest:  0.0029 secs
  Average:  0.0050 secs
  Requests/sec: 19885.1838

All with their latest version

  "dependencies": {
    "@benzene/http": "0.4.1",
    "@benzene/jit": "0.1.4",
    "apollo-server": "3.6.3",
    "express-graphql": "^0.12.0",
    "fastify": "3.27.2",
    "graphql-helix": "1.11.0",
    "hyper-express": "5.8.2",
    "mercurius": "9.3.3"
  }

I might not open a PR, but if someone wants, here is what I did.

const { Benzene, makeHandler, parseGraphQLBody } = require("@benzene/http");
const { makeCompileQuery } = require("@benzene/jit");
const HyperExpress = require("hyper-express");
const schema = require("../schema");

const server = new HyperExpress.Server();

const GQL = new Benzene({ schema, compileQuery: makeCompileQuery() });

const graphqlHTTP = makeHandler(GQL);

server.post("/graphql", async (request, response) => {
  const body = await request.json();
  graphqlHTTP({
    method: request.method,
    headers: request.headers,
    body,
  }).then((result) => {
    response.setHeaders(result.headers);
    response.status(result.status).json(result.payload);
  });
});

server.listen(4000);
redbar0n commented 1 year ago

Check out Elysia (on Bun), it’s now faster than even hyper-express: https://twitter.com/saltyaom/status/1658368305240096769