Skip to content
Draft
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
12 changes: 12 additions & 0 deletions bench/response-cache/gateway-with-cache.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { defineConfig } from '@graphql-hive/gateway';

export const gatewayConfig = defineConfig({
responseCaching: {
ttl: 0,
ttlPerType: {
'Query.me': 2000,
},
session: () => null,
},
maskedErrors: false,
});
38 changes: 38 additions & 0 deletions bench/response-cache/gateway-with-redis.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { defineConfig } from '@graphql-hive/gateway';
import { openTelemetrySetup } from '@graphql-hive/gateway/opentelemetry/setup';
import { AsyncLocalStorageContextManager } from '@opentelemetry/context-async-hooks';
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';

const RESPONSE_CACHE_ENABLED = process.env['RESPONSE_CACHE_ENABLED'] == 'true';

openTelemetrySetup({
contextManager: new AsyncLocalStorageContextManager(),
resource: {
serviceName: RESPONSE_CACHE_ENABLED ? 'with-cache' : 'without-cache',
serviceVersion: '1.0.0',
},
traces: {
exporter: new OTLPTraceExporter({ url: 'http://localhost:4318/v1/traces' }),
// batching: false,
},
});
export const gatewayConfig = defineConfig({
openTelemetry: {
traces: true,
},
cache: {
type: 'redis',
url: process.env['REDIS_URL'], // The URL of the Redis server
lazyConnect: false,
},
responseCaching: RESPONSE_CACHE_ENABLED
? {
ttl: 0,
ttlPerType: {
'Query.me': 2000,
},
session: () => null,
}
: undefined,
maskedErrors: false,
});
13 changes: 13 additions & 0 deletions bench/response-cache/gateway-without-auto-invalidation.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { defineConfig } from '@graphql-hive/gateway';

export const gatewayConfig = defineConfig({
responseCaching: {
invalidateViaMutation: false,
ttl: 0,
ttlPerType: {
'Query.me': 2000,
},
session: () => null,
},
maskedErrors: false,
});
5 changes: 5 additions & 0 deletions bench/response-cache/gateway-without-cache.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { defineConfig } from '@graphql-hive/gateway';

export const gatewayConfig = defineConfig({
maskedErrors: false,
});
92 changes: 92 additions & 0 deletions bench/response-cache/response-cache.bench.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import { createExampleSetup, createTenv, GatewayOptions } from '@internal/e2e';
import { benchConfig } from '@internal/testing';
import { bench, describe, expect } from 'vitest';

describe('Response Cache', async () => {
const { runBench, container } = await makeRunner();
const redis = await container({
name: 'redis',
healthcheck: ['CMD', 'redis-cli', 'ping'],
env: {
LANG: '',
LC_ALL: '',
},
image: 'redis',
containerPort: 6379,
});

await runBench.skip(
'With in memory response cache',
'gateway-with-cache.config.ts',
);
await runBench.skip(
'Without response cache',
'gateway-without-cache.config.ts',
);

await runBench.skip(
'Without invalidation cache',
'gateway-without-auto-invalidation.config.ts',
);

await runBench('With redis response cache', 'gateway-with-redis.config.ts', {
env: {
RESPONSE_CACHE_ENABLED: 'true',
REDIS_URL: `redis://localhost:${redis.port}`,
},
});

await runBench(
'With redis but no response cache',
'gateway-with-redis.config.ts',
{
env: {
RESPONSE_CACHE_ENABLED: 'false',
REDIS_URL: `redis://localhost:${redis.port}`,
},
},
);
});

const makeRunner = async () => {
const { gateway, container } = createTenv(__dirname);
const exampleSetup = createExampleSetup(__dirname, 1000);

const supergraph = await exampleSetup.supergraph();

const { query, operationName, result } = exampleSetup;

const runBench = async (
name: string,
configFile: string,
options?: Partial<GatewayOptions>,
) => {
const { execute } = await gateway({
supergraph,
...options,
args: ['-c', configFile, ...(options?.args ?? [])],
});
return bench(
name,
async () => {
const response = await execute({
query,
operationName,
});
expect(response).toEqual(result);
},
benchConfig,
);
};

runBench.skip = async (
name: string,
_configFile: string,
_options?: GatewayOptions,
) => bench.skip(name);

return {
runBench,
container,
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ beforeAll(async () => {
containerPort: 6379,
healthcheck: ['CMD-SHELL', 'redis-cli ping'],
env: {
LANG: '', // fixes "Failed to configure LOCALE for invalid locale name."
// fixes "Failed to configure LOCALE for invalid locale name."
LANG: '',
LC_ALL: '',
},
});
redisEnv.REDIS_HOST = gatewayRunner.includes('docker')
Expand Down
3 changes: 2 additions & 1 deletion internal/e2e/src/tenv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,8 @@ export function createTenv(cwd: string): Tenv {
'node',
// use next available port when starting inspector (note that this does not start inspect, this still needs to be done manually)
// it's not set because in JIT mode because it does not work together (why? no clue)
args.includes('--jit') ? null : '--inspect-port=0',
args.includes('--jit') ? null : '--inspect-port=9999',
// '--inspect',
'--import',
'tsx',
path.resolve(__project, 'packages', 'gateway', 'src', 'bin.ts'),
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@
"tar-fs": "3.1.1",
"tmp": "0.2.4",
"tsx": "patch:tsx@npm%3A4.20.3#~/.yarn/patches/tsx-npm-4.20.3-7de67a623f.patch",
"vite": "7.1.9"
"vite": "7.1.9",
"@envelop/response-cache": "8.2.0-alpha-20251013081815-d6f74fceb1a32fd336b2664f90f87872e1bbf2fe",
"@graphql-mesh/cache-redis": "0.105.0-alpha-20251010093057-4eeae9412ec39cfbab6e001ecaf527cf94f4ea31"
}
}
Loading