DataFetchingEnvironment getDataLoader Performance issues #1447
Replies: 2 comments
-
Yes, you are right that the DataLoader should be scoped to a single request, and caching it statically or on a thread local can cause issues under moderate to high load. One solution to this problem is to batch the data fetching requests, which means instead of making a separate request for each parent object, you can group the parent objects and make a single request to fetch all the child objects related to them. This can significantly reduce the number of calls to the getDataLoader method and improve the performance of your application. To implement batching, you can create a custom BatchLoader for your data loader that can accept a list of parent IDs and return a list of child objects. Here's an example:
}) In your data fetcher method, you can then retrieve the data loader and call its load method with a list of parent IDs instead of a single parent ID: @DgsData(parentType = "parent") This will fetch all the child objects related to the given parent ID and return them as a list. By batching the data fetching requests, you can reduce the number of calls to the getDataLoader method and improve the performance of your application. |
Beta Was this translation helpful? Give feedback.
-
Thanks, will try this out and let you know |
Beta Was this translation helpful? Give feedback.
-
I am having major performance issues with getDataLoader method on the DataFetchingEnvironment. Each request for dfe.getDataLoader("child") seems quick in isolation but if we have 1000 parent objects we end up with a lot of calls to this method. this can turn a 60ms request into a 300ms request
this is an example of the code
Solutions tired:
My question is,has any one else experienced this and have any solutions?
My next thoughts are Is it possible to define @DgsData or something similar at a context that gives you access to all of the parent object in one go, meaning we only have to call getDataLoader once. some thing like this for example
Beta Was this translation helpful? Give feedback.
All reactions