I recently upgraded Apollo Server from v3 to v4 and noticed significant performance issues
The performance issues were most apparent when running on a low-powered machine. At one point it was taking 12seconds to return a query. The graph shown above is after I upgraded the machine but it still shows a 2x degradation.
The query that I tested on has 1000’s of fields that are returned and was the same for both my v3 and v4 tests.
Here is a snippet of my apollo server code
// Setup the Apollo Server once (different from Apollov3)
const apolloServer = new ApolloServer({
...(import.meta.env.VITE_USE_MOCKS && {
schema: addMocksToSchema({
schema: makeExecutableSchema({ typeDefs, resolvers }),
mocks,
preserveResolvers: false
})
}),
...{
cache: new InMemoryLRUCache({
// ~100MiB
maxSize: Math.pow(2, 20) * 100,
// 5 minutes (in milliseconds)
ttl: 300_000
}),
introspection: true,
typeDefs,
resolvers,
// TODO: look at making this more secure
csrfPrevention: false
}
});
await apolloServer.start();
Are there some setup options that would help with performance? Or am I doing it all wrong?
Hey @obgibson, thanks for the report. Any chance you have something you can share with me so I can reproduce locally?
I only have one good guess for now (but it’s a pretty good one), so let’s start there:
Did you also upgrade graphql
(or any other dependencies) as well during the upgrade process? There is a known performance issue in graphql@16
which is my initial suspicion.
IF you were on v3 + v15 and switched to v4 + v16, would you mind testing v3 + v15 → v3 + v16 and seeing if you get similar results in performance drop? I’d like to make best attempts at isolating this problem first.
If you weren’t on v15 before and had no other notable changes besides v3 → v4 we’ll probably need to get a bit more sophisticated to really dig in to this - either a way for me to reproduce, or a flame chart that I can explore.
Thanks!
Thanks for getting back to me Trevor. I have been on grapphql@16 for a few months now. I will try pinning back to 15 and let you know if I see a difference.
Hi @obgibson,
I realize this is a late reply, but recently we faced the same scenario. Not sure this is the same case, but I am writing my answer here should someone else face the same problem as ours.
We recently migrated from Apollo server 2.x to 4.x and we were surprised how slow Apollo 4 was. A single query took 60+ seconds if it succeeded at all. most queries just timed-out after a long wait.
After a long and tedious tinkering, we finally pin-pointed the problem to be related to introspection being enabled on the server. This caused the Apollo studio to pull the schema continuously while Apollo was trying to the serve the request. In our case Apollo studio was trying to refresh the schema each 5 seconds – which was an overkill to say the least.
Thanks for the insight. We just bypassed graphql and used REST for any serious API’s. Did you work out a fix for the extra introspections?