Persistence to MongoDB slows quite alot #2895
avinoam134
started this conversation in
Discussions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hey all! I'm integrating langgraph into my server with persistence to my MongoDB using langgraph's new default AsyncMongoDBSaver. However some stress tests i made show that it increases my latency quite significatly compared to a MemorySaver.
Running a single user request (i.e 1 full graph run from START to END) takes ~3 seconds with the checkpointer, and ~2 seconds with a MemorySaver. So that seems pretty legit to me
However this scales badly. running 20 users requests (i.e 20 full graph runs) concurrently with the checkpointer raises latency to ~9.5seconds, while the MemorySaver is still on ~2.5 sec latency.
It's worth noting each of my graph iterations go through ~5 "super steps" untill completion (depending on the user prompt, navigation through nodes may vary a little).
Is this latency considered normal? If not can you help me try figuring out why this is happening?
I have tried eliminating the suspicion that locks on the DB are the issue by creating a collection per thread-id in the DB so that each user request would get it's memory persisted to it's own collection (and hence cancel race condition on the entire DB) but this have barely improved the ~9.5 sec latency to ~9sec.
Also, it's worth mentioning that the DB is made solely for the langgraphs runs and the only endpoints triggered in the tests are ones that just trigger a gaph.ainvoke(config) with no other tasks. So there's nothing else that slows things down except for the graph runs.
I also have a suspicion to why this is happening and would like some conformation:
The way i understood things - langgraph is writing intermidiate checkpoints for every super-step passed through the graph. If that's the case, could this explain the issue? If so why are those intermidiate writes made for, aside from protection against unexpected server shutdowns mid graph runs (which isn't significant to me)? Is there a way to cancel it and make writes only at the end of the graph run?
Beta Was this translation helpful? Give feedback.
All reactions