Skip to content

Commit f29abb0

Browse files
committed
add benchmark for response caching
1 parent 883cd5a commit f29abb0

File tree

5 files changed

+111
-1
lines changed

5 files changed

+111
-1
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { defineConfig } from '@graphql-hive/gateway';
2+
3+
export const gatewayConfig = defineConfig({
4+
responseCaching: {
5+
ttl: 0,
6+
ttlPerType: {
7+
'Query.me': 2000,
8+
},
9+
session: () => null,
10+
},
11+
maskedErrors: false,
12+
});
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { defineConfig } from '@graphql-hive/gateway';
2+
3+
export const gatewayConfig = defineConfig({
4+
cache: {
5+
type: 'redis',
6+
url: process.env['REDIS_URL'], // The URL of the Redis server
7+
lazyConnect: false,
8+
},
9+
responseCaching: {
10+
ttl: 0,
11+
ttlPerType: {
12+
'Query.me': 2000,
13+
},
14+
session: () => null,
15+
},
16+
maskedErrors: false,
17+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { defineConfig } from '@graphql-hive/gateway';
2+
3+
export const gatewayConfig = defineConfig({
4+
maskedErrors: false,
5+
});
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import { createExampleSetup, createTenv } from '@internal/e2e';
2+
import { benchConfig } from '@internal/testing';
3+
import { bench, describe, expect } from 'vitest';
4+
5+
describe('Response Cache', async () => {
6+
const { gateway, container } = createTenv(__dirname);
7+
const exampleSetup = createExampleSetup(__dirname, 1000);
8+
9+
const redis = await container({
10+
name: 'redis',
11+
healthcheck: ['CMD', 'redis-cli', 'ping'],
12+
env: {
13+
LANG: '',
14+
LC_ALL: '',
15+
},
16+
image: 'redis',
17+
containerPort: 6379,
18+
});
19+
20+
const supergraph = await exampleSetup.supergraph();
21+
22+
const { query, operationName, result } = exampleSetup;
23+
24+
const gatewayWithoutCache = await gateway({
25+
supergraph,
26+
args: ['-c', 'gateway-without-cache.config.ts'],
27+
});
28+
bench(
29+
'Without response cache',
30+
async () => {
31+
const response = await gatewayWithoutCache.execute({
32+
query,
33+
operationName,
34+
});
35+
expect(response).toEqual(result);
36+
},
37+
benchConfig,
38+
);
39+
40+
const gatewayWithCache = await gateway({
41+
supergraph,
42+
args: ['-c', 'gateway-with-cache.config.ts'],
43+
});
44+
bench(
45+
'With in memory response cache',
46+
async () => {
47+
const response = await gatewayWithCache.execute({
48+
query,
49+
operationName,
50+
});
51+
expect(response).toEqual(result);
52+
},
53+
benchConfig,
54+
);
55+
56+
const gatewayWithRedisCache = await gateway({
57+
supergraph,
58+
args: ['-c', 'gateway-with-redis.config.ts'],
59+
env: {
60+
REDIS_URL: `redis://localhost:${redis.port}`,
61+
},
62+
});
63+
bench(
64+
'With redis response cache',
65+
async () => {
66+
const response = await gatewayWithRedisCache.execute({
67+
query,
68+
operationName,
69+
});
70+
expect(response).toEqual(result);
71+
},
72+
benchConfig,
73+
);
74+
});

e2e/distributed-subscriptions-webhooks/distributed-subscriptions-webhooks.e2e.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ beforeAll(async () => {
2323
containerPort: 6379,
2424
healthcheck: ['CMD-SHELL', 'redis-cli ping'],
2525
env: {
26-
LANG: '', // fixes "Failed to configure LOCALE for invalid locale name."
26+
// fixes "Failed to configure LOCALE for invalid locale name."
27+
LANG: '',
28+
LC_ALL: '',
2729
},
2830
});
2931
redisEnv.REDIS_HOST = gatewayRunner.includes('docker')

0 commit comments

Comments
 (0)