From 363365c66e554f589958625a23c6b7c0ed81bec3 Mon Sep 17 00:00:00 2001 From: Arda TANRIKULU Date: Thu, 26 Dec 2024 13:03:48 +0300 Subject: [PATCH] more --- benchmark/k6.js | 10 +++++++--- benchmark/start-server.ts | 41 ++++++++++++++++++++++++++------------- examples/egg/.gitignore | 2 +- 3 files changed, 35 insertions(+), 18 deletions(-) diff --git a/benchmark/k6.js b/benchmark/k6.js index 293e0f4512..e3b284fb83 100644 --- a/benchmark/k6.js +++ b/benchmark/k6.js @@ -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: { @@ -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) => { @@ -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}`; } diff --git a/benchmark/start-server.ts b/benchmark/start-server.ts index 79d66616bd..ee8b3903dd 100644 --- a/benchmark/start-server.ts +++ b/benchmark/start-server.ts @@ -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'; @@ -12,7 +12,7 @@ const basicYoga = createYoga({ multipart: false, }); -const yogaMap: Record = { +const yogaMap: Record> = { '/graphql': basicYoga, '/graphql-jit': createYoga({ schema, @@ -44,13 +44,14 @@ const yogaMap: Record = { 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); @@ -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); + } +}); diff --git a/examples/egg/.gitignore b/examples/egg/.gitignore index e81df5da9c..cec9879ff9 100644 --- a/examples/egg/.gitignore +++ b/examples/egg/.gitignore @@ -1,4 +1,4 @@ run logs app/**/*.js -config/**/*.js \ No newline at end of file +config/**/*.js