Skip to content
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

Explore migrating from pymongo to motor as an async python libary for mongodb #787

Open
mkshah605 opened this issue Nov 21, 2024 · 4 comments
Assignees
Labels
enhancement New feature or request

Comments

@mkshah605
Copy link
Collaborator

Given that there is now "official" guidance from MongoDB Inc. on using their official async python library for mongodb, i.e. motor, with FastAPI, explore pros/cons of migrating from using the older, more-stable-but-not-async pymongo library in order to take full performance advantage of FastAPI's async support.

The implication of this would be that a single-container deployment of the runtime would:

  • support a higher rate of requests (avoid having to run multiple containers)
  • in turn, potentially help avoid having to consider race conditions wrt multiple runtime containers accessing the same backing mongodb instance

Goal: take some time to compare both approaches to better inform a path forward

@mkshah605 mkshah605 added the enhancement New feature or request label Nov 21, 2024
@mkshah605 mkshah605 self-assigned this Nov 21, 2024
@dwinston
Copy link
Collaborator

Given that there is now "official" guidance from MongoDB Inc. on using their official async python library for mongodb, i.e. motor, with FastAPI

i.e. https://github.com/mongodb-developer/farm-stack-to-do-app

@eecavanna
Copy link
Collaborator

eecavanna commented Nov 27, 2024

Hello, @mkshah605 — welcome to the project!

@mkshah605 and @dwinston — While working on migrating nmdc-runtime from pip-tools to Poetry (still very much a work in progress, here), I came across both motor and pymongo in the dependency tree. Based on the digging I did at the time, I (to my surprise) came away thinking that the Runtime was actually already using motor and it was only some miscellaneous experiments that were using pymongo.

from motor.motor_asyncio import AsyncIOMotorClient, AsyncIOMotorDatabase

So, today, I was surprised when I noticed this ticket in the repo.

@eecavanna
Copy link
Collaborator

Oops... correction: it is using both (and I think it's using pymongo for most things—as opposed to the opposite, which I suggested in my previous message).

from pymongo.errors import OperationFailure, AutoReconnect
from motor.motor_asyncio import AsyncIOMotorClient, AsyncIOMotorDatabase

from pymongo import MongoClient, ReplaceOne
from pymongo.database import Database as MongoDatabase

Maybe someone was experimenting with motor and left their experimentation in the code base.

@dwinston
Copy link
Collaborator

@eecavanna yes, @elais was leading the experimentation with motor before he was eaten by JAWS... 🦈

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants