Skip to content

Commit

Permalink
server service benchmarking (#566)
Browse files Browse the repository at this point in the history
Co-authored-by: typedarray <[email protected]>
  • Loading branch information
kyscott18 and 0xOlias authored Feb 13, 2024
1 parent 6cb06da commit 93eeda1
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 1 deletion.
83 changes: 83 additions & 0 deletions packages/core/src/server/service.bench.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { setupAnvil, setupContext, setupIndexingStore } from "@/_test/setup.js";
import { type TestContext, bench } from "vitest";
import { setup as serverSetup } from "./service.test.js";

let context: TestContext;
let teardownIndexing: () => Promise<void>;
let server: Awaited<ReturnType<typeof serverSetup>>;

const setup = async () => {
context = {} as TestContext;

setupContext(context);
await setupAnvil(context);

teardownIndexing = await setupIndexingStore(context);
server = await serverSetup({
common: context.common,
indexingStore: context.indexingStore,
});

for (let i = 0; i < 100; i++) {
await server.createTestEntity({ id: i });
}
};

const teardown = async () => {
await teardownIndexing();
await server.service.kill();
};

bench(
"Server singular requests",
async () => {
for (let i = 0; i < 100; i++) {
await server.gql(`
testEntity (id: ${i}) {
id
string
int
float
boolean
bytes
bigInt
}
`);
}
},
{
setup,
teardown,
iterations: 5,
warmupIterations: 1,
time: 60_000,
warmupTime: 10_000,
},
);

bench(
"Server plural requests",
async () => {
for (let i = 0; i < 100; i++) {
await server.gql(`
testEntitys {
id
string
int
float
boolean
bytes
bigInt
}
`);
}
},
{
setup,
teardown,
iterations: 5,
warmupIterations: 1,
time: 60_000,
warmupTime: 10_000,
},
);
2 changes: 1 addition & 1 deletion packages/core/src/server/service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const s = createSchema((p) => ({

const graphqlSchema = buildGqlSchema(s);

const setup = async ({
export const setup = async ({
common,
indexingStore,
options = {
Expand Down

0 comments on commit 93eeda1

Please sign in to comment.