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

export const gatewayConfig = defineConfig({
cache: {
type: 'redis',
url: process.env['REDIS_URL'], // The URL of the Redis server
lazyConnect: false,
},
responseCaching: {
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,
});
74 changes: 74 additions & 0 deletions bench/response-cache/response-cache.bench.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { createExampleSetup, createTenv } from '@internal/e2e';
import { benchConfig } from '@internal/testing';
import { bench, describe, expect } from 'vitest';

describe('Response Cache', async () => {
const { gateway, container } = createTenv(__dirname);
const exampleSetup = createExampleSetup(__dirname, 1000);

const redis = await container({
name: 'redis',
healthcheck: ['CMD', 'redis-cli', 'ping'],
env: {
LANG: '',
LC_ALL: '',
},
image: 'redis',
containerPort: 6379,
});

const supergraph = await exampleSetup.supergraph();

const { query, operationName, result } = exampleSetup;

const gatewayWithoutCache = await gateway({
supergraph,
args: ['-c', 'gateway-without-cache.config.ts'],
});
bench(
'Without response cache',
async () => {
const response = await gatewayWithoutCache.execute({
query,
operationName,
});
expect(response).toEqual(result);
},
benchConfig,
);

const gatewayWithCache = await gateway({
supergraph,
args: ['-c', 'gateway-with-cache.config.ts'],
});
bench(
'With in memory response cache',
async () => {
const response = await gatewayWithCache.execute({
query,
operationName,
});
expect(response).toEqual(result);
},
benchConfig,
);

const gatewayWithRedisCache = await gateway({
supergraph,
args: ['-c', 'gateway-with-redis.config.ts'],
env: {
REDIS_URL: `redis://localhost:${redis.port}`,
},
});
bench(
'With redis response cache',
async () => {
const response = await gatewayWithRedisCache.execute({
query,
operationName,
});
expect(response).toEqual(result);
},
benchConfig,
);
});
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
Loading