MongoDB Atlas Serverless Database | Serverless Instance Costs | RPU cost explanation
Asked Answered
O

1

5

Can someone explain how RPUs are getting calculated by an example ?

Let's say I have a mongo collection that has 5 million documents. So if i do a findOne to the collection, the RPUs generated would be 5M or 1 ?

Offside answered 2/5, 2022 at 8:15 Comment(0)
C
13

It depends on a crucially import step that I could not find anywhere in Mongo's pricing information.

I had 4000 daily visits with a user database of 25,000 users. I was using findOne on the database two times per page load. What I thought would be 8000 RPUs turned out to be 170 million RPUs. That's right - 42,500 RPUs per page visit.

So the critically important step is: add indexes for the keys you're matching on.

Yes this is an obvious step to optimize performance, but also easy to overlook the first go-around of creating a database.

I was in the MongoDD dashboard daily to check user stats and was never alerted to any abnormalities. Searching online for over an hour, I could not find any mention of this from Mongo. But when I reached out to support, this is the first thing they pointed out. So they know it's an issue. They know it's a gotcha. They know how simple it'd be to point out that a single call is resulting in 40,000 RPUs. Doesn't seem that they care. Rather it seems to be a sleezy business model they've intentionally adopted.

So if you do a findOne on a 5 million document database, will you get 1 RPU charged or 5 Million RPUs charged? Depends if you remembered to index.

Coppery answered 4/5, 2022 at 15:50 Comment(5)
So if you had no index, and every document was 4kb, a findOne WOULD result in 5M RPUs used?Aplite
If you do index the 5 million documents on the findOne query. Is it only 1RPU for a findOne?Misspeak
Yes J.Doe. You would also get charged the same even if each document was 0.25kb. Yes @jacktim. 5 million X pricing if OP forgets to index. I learned the hard way (luckily with only 20,000x pricing).Coppery
_id is automatically indexed. But if you're trying to findOne on a field other than _id that is not indexed (for example "name" or "email"), then it will "read" every single item in your database until it finds a match.Coppery
Luckly the serverless is kinda cheap. I'm glad I've found this question before starting with the serverless databaseIives

© 2022 - 2024 — McMap. All rights reserved.