-
Notifications
You must be signed in to change notification settings - Fork 114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Degraded performance with Apollo Server and v1 #1724
Comments
@dackland Since ApolloServer isn't able to take a custom execute function in favor of You can give a try "Envelop" that might help you to take your tracing and other stuff out of your server thanks to its plugin system; |
Just to add to that, we created a PR for adding support for custom |
Thanks for the responses, @ardatan and @dotansimha! The two rounds of execution caused by We're at a bit of a crossroads moving forward with the upgrade to
Apologies if I'm missing something, but is this correct? Or is there a way to get the Apollo Studio features working with |
The solution I can suggest is something like the following (Not sure if this code will work but the idea is to get the context and destroy it) const { typeDefs, resolvers } = createApplication(...);
const contextDestroyMap = new WeakMap();
const server = new ApolloServer({
typeDefs,
resolvers,
context: inputContext => {
const { context, destroy } = createOperationController({ inputContext });
contextDestroyMap.set(context, destroy);
return context;
},
formatResponse: (res, { context}) => {
const destroy = contextDestroyMap.get(context);
destroy();
contextDestroyMap.delete(context);
return res;
}
}) |
Thanks for the suggestion @ardatan. The above snippet almost works. The However, since it's just the const server = new ApolloServer({
typeDefs,
resolvers,
context: (inputContext) => {
const { context } = createOperationController({
inputContext,
autoDestroy: true,
});
return context;
},
}); |
@ardatan or @dotansimha, can you comment on the above code snippet? It has addressed our performance problems, and we're seeing field usage and tracing in Apollo Studio again. I'd appreciate some feedback if this implementation is safe, or if we'll be looking at memory leaks. If it is indeed safe, it would be great to see some official guidance in the docs 😃 Thanks! |
Since you are keeping the Apollo Executor as-is, you get the Apollo features, so it makes sense that it works now. The
@kamilkisiela can you please elaborate on this? specifically on |
@dackland do you have the latest specs on performance after v1 upgrade with this suggested solution? I'm thinking of using gq modules for an enterprise grade client project and just want to make sure it's safe to use and is future proof. thank you. |
@sahanatroam We deployed the |
hey @dackland do you think you could kindly update your sample repo with the fix you applied? This would be super useful as I'm still getting degraded performance :( |
That's obvious, using context+resolvers will always be faster then having dependency injection on top of it. The point of modules is to give you tools to create schema in teams. |
Describe the bug
Apollo Server with GraphQL Modules
v1
appears to be twice as slow as it was withv0
.To Reproduce
I've created a simple repo with three basic servers to demonstrate the performance differences. A load testing script performs as many requests as possible within 10 seconds.
Each server uses the same schema, resolver, and JSON dataset. See the repo for more details and instructions. The test uses a larger dataset (3MB), but we observed a similar 100% latency increase even with smaller payloads.
Expected behavior
Using Apollo Server with GraphQL Modules
v1
is similar or better performance tov0
.Environment:
1.4.2
16.3.0
Additional context
Using
createApolloExecutor
(as implemented here) instead ofcreateSchemaForApollo
seems to address the performance problem. However, using the custom executor broke field usage and resolver tracing in Apollo Studio.I noticed your benchmarks for Apollo Server are all using
createApolloExecutor
, so it isn't capturing the slowdown that seems to happen when usingcreateSchemaForApollo
.The docs recommend
createSchemaForApollo
for Apollo Server, but the API Reference calls bothcreateSchemaForApollo
andcreateApolloExecutor
experimental.Is there a recommended way of using
v1
with Apollo Server that is performant and works with Apollo Studio? Thanks!The text was updated successfully, but these errors were encountered: