Skip to content

Commit

Permalink
[debug] Print out documentStore stats every 60 seconds.
Browse files Browse the repository at this point in the history
In an effort to see how effective this cache is in production during this
alpha phase, we'll print out the stats on the document store every 60
seconds.
  • Loading branch information
abernix committed Jan 16, 2019
1 parent be71620 commit 7a0d0e6
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions packages/apollo-server-core/src/ApolloServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -500,15 +500,31 @@ export class ApolloServerBase {
}

private initializeDocumentStore(): void {
this.documentStore = new InMemoryLRUCache<DocumentNode>({
let disposedInLastCycle = 0;
const maxSize = Math.pow(2, 20) * 30;
const documentStore = (this.documentStore = new InMemoryLRUCache<
DocumentNode
>({
// Create ~about~ a 30MiB InMemoryLRUCache. This is less than precise
// since the technique to calculate the size of a DocumentNode is
// only using JSON.stringify on the DocumentNode (and thus doesn't account
// for unicode characters, etc.), but it should do a reasonable job at
// providing a caching document store for most operations.
maxSize: Math.pow(2, 20) * 30,
maxSize,
sizeCalculator: approximateObjectSize,
});
onDispose() {
disposedInLastCycle += 1;
},
}));

setInterval(async () => {
const currentDocumentStoreSize = await documentStore.getTotalSize();
const percent = Math.round((currentDocumentStoreSize / maxSize) * 100);
console.debug(
`[documentStore] ${currentDocumentStoreSize} / ${maxSize} (${percent}%). Disposed of ${disposedInLastCycle} documents this interval.`,
);
disposedInLastCycle = 0;
}, 60000);
}

// This function is used by the integrations to generate the graphQLOptions
Expand Down

0 comments on commit 7a0d0e6

Please sign in to comment.