-
-
Notifications
You must be signed in to change notification settings - Fork 677
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
Memory usage grows to extremely large values for queries that return big JSONs #456
Comments
Looks like a duplicate of #254 - TypeGraphQL builds a reach field resolver for each field, so when you return big JSON, it creates tons of class type instances to call the getters with all midlewares pipeline. |
@MichalLytek nice. Should we add a way to opt-out of the middlewares ? Have a sort of context variable/symbol, that states the request is middlewareless? |
What do you mean? |
@MichalLytek what you mentioned It can be marked at Query/Mutation level, maybe via context injection?
|
@theodorDiaconu |
Describe the bug
Recently, we introduced this library to our GraphQL service which was using string schema representation until now. After this change task running this service on aws ecs started crashing regularly due to running out of memory. While debugging locally I noticed that the related node process goes from ~20mb when idle, to values close to 500mb (or even more) when processing query that returns large json file (2 to 3 mb). When I run the same query with version of the app before introducing type-graphql memory still rises more than I would like but instead of hundreds of megabytes it rises approximately by 20mb. The issue happens every time I run the query not just the first time.
To Reproduce
I created a minimal example repository https://github.com/Crhaj/type-graphql-memory where you can play around and see the issue is real. I've included most of the libraries we use so that you can see if it isn't issue of some interaction. This example app has only one query resolver which fetches large array of jsons (random data from some test site). In master there is version with type-graphql library but I've also created branch which is not using type-graphql to demonstrate the difference. Each of the branches contains reports (flamegraph) created by the 0x tool. When I run this app locally and run the query using type-graphql version the memory usage of the node process goes over 1gb which is simply not usable. Without the library it goes to ~60mb. Once the app starts, you can run the query easily from graphql playground like this:
query exampleData { exampleData { country indicator value year } }
Expected behavior
I expect the memory usage should be close to values produced by app which is not using the library when there are no other differences.
Enviorment (please complete the following information):
Additional context
Any help appreciated, thank you.
The text was updated successfully, but these errors were encountered: