Skip to content

Commit

Permalink
more
Browse files Browse the repository at this point in the history
  • Loading branch information
ardatan committed Dec 26, 2024
1 parent f508510 commit 363365c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 18 deletions.
10 changes: 7 additions & 3 deletions benchmark/k6.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function getOptionsForScenario(scenario, index) {
env: { MODE: scenario },
tags: { mode: scenario },
};
if (scenario === 'graphql-no-parse-validate-cache') {
if (scenario.endsWith('graphql-no-parse-validate-cache')) {
return {
scenario: scenarioField,
thresholds: {
Expand All @@ -54,7 +54,10 @@ const scenarioNames = [
'graphql-jit',
'graphql-response-cache',
'graphql-no-parse-validate-cache',
'uws',
'uws-graphql',
'uws-graphql-jit',
'uws-graphql-response-cache',
'uws-graphql-no-parse-validate-cache',
];

scenarioNames.forEach((name, index) => {
Expand Down Expand Up @@ -105,7 +108,8 @@ export function handleSummary(data) {
export function run() {
let url = 'http://localhost:4000/graphql';
if (__ENV.MODE.startsWith('uws')) {
url = 'http://localhost:4001/graphql';
const mode = __ENV.MODE.substring(4);
url = `http://localhost:4001/${mode}`;
} else {
url = `http://localhost:4000/${__ENV.MODE}`;
}
Expand Down
41 changes: 27 additions & 14 deletions benchmark/start-server.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable */
import { createServer, type RequestListener } from 'http';
import { createServer } from 'http';
import { createYoga } from 'graphql-yoga';
import { App } from 'uWebSockets.js';
import { useGraphQlJit } from '@envelop/graphql-jit';
Expand All @@ -12,7 +12,7 @@ const basicYoga = createYoga<Context>({
multipart: false,
});

const yogaMap: Record<string, RequestListener> = {
const yogaMap: Record<string, ReturnType<typeof createYoga>> = {
'/graphql': basicYoga,
'/graphql-jit': createYoga<Context>({
schema,
Expand Down Expand Up @@ -44,13 +44,14 @@ const yogaMap: Record<string, RequestListener> = {
parserAndValidationCache: false,
graphqlEndpoint: '/graphql-no-parse-validate-cache',
}),
'/ping': (_, res) => {
res.writeHead(200);
res.end();
},
};

const server = createServer((req, res) => {
if (req.url === '/ping') {
res.writeHead(200);
res.end('pong');
return;
}
const yoga = yogaMap[req.url!];
if (yoga) {
yoga(req, res);
Expand All @@ -60,14 +61,26 @@ const server = createServer((req, res) => {
}
});

server.once('error', err => {
console.error('node:http error', err);
process.exit(1);
});

server.listen(4000, () => {
console.log('ready');
console.log('node:http ready');
});

App()
.any('/*', basicYoga)
.listen(4001, listenSocket => {
if (listenSocket) {
console.log('ready');
}
});
const uwsApp = App();

for (const [path, yoga] of Object.entries(yogaMap)) {
uwsApp.any(path, yoga);
}

uwsApp.listen(4001, listenSocket => {
if (listenSocket) {
console.log('uws ready');
} else {
console.error('uws failed to listen');
process.exit(1);
}
});
2 changes: 1 addition & 1 deletion examples/egg/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
run
logs
app/**/*.js
config/**/*.js
config/**/*.js

0 comments on commit 363365c

Please sign in to comment.