`findOne` optimization
See original GitHub issueTo quote from an earlier specs
issue:
One of the main usecases of
PhotonPrisma Client is to use it inside a GraphQL server. The resolver system of a GraphQL server is prone to suffer from the N+1 problem. To mitigate this problem users can choose to implement the DataLoader pattern within the application server. This burdens our users with unnecessary work that is not related to their core domain. This issue explores how we could include a DataLoader implementation withinPhotonPrisma Client.
As a first step we want to look specifically into optimizing findOne
queries by batching them.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:5
- Comments:18 (11 by maintainers)
Top Results From Across the Web
Optimize Query Performance — MongoDB Manual
Optimize Query Performance · Create Indexes to Support Queries · Limit the Number of Query Results to Reduce Network Demand · Use Projections...
Read more >How to Optimize MongoDB Queries Using find() & Indexes
Help optimize MongoDB queries with this advanced tutorial on how to use the find() method and indexes to spot slow queries.
Read more >How to optimize MongoDB & Mongoose for Performance
So its usually optimal for GET endpoints and .find() operations that don't use .save() or virtuals. 2. Create custom Indexes for your queries....
Read more >How to Find & Optimize Your MVPs (Most Valuable Pages)
Your most valuable pages can bring the greatest business impact. Find out what MVPs are and how to optimize them here.
Read more >Optimization Problems - Calculus - YouTube
This calculus video explains how to solve optimization problems. It explains how to solve the fence along the river problem, ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Memo: unsurprisingly faster with optimization.
Green: batching without optimization
Purple: with optimization
Y: response time in nanoseconds
X: requests per second
Tested three queries in batches of 100,
$user_id
randomized from 1 to 3000. 3000 users, 30000 posts and 30000 comments.@mavilein We didn’t really solve it, we just added timings just before and just after resolvers to see how fast queries were resolved.
I do agree that it’s a hefty query. But production workloads are gonna go way beyond this I think 😄 The N+1 is definitely the big slowdown in this case, the worst thing about the N+1 is probably the overhead it takes for every query to resolve and go back and forth between Prisma-client and the database. (Which both run on localhost, so also shouldn’t be an issue, deployed on GCP both running in Cloud Run we have similar timings)
My example is also a findMany on activities, I don’t think a findOne would be as bad as a findMany. Think batching would be much more usefull in findMany than a findOne. But then again, the logic from findOne would probably be reuseable in de findMany
I don’t mind open ended comments, performance surely isn’t as straightforward as it seems!