Hi folks, about a year ago I asked something similar when serverless was brand new, but seems that things have evolved.
I’m still debating whether I migrate my m2 cluster to serverless.
One question I have is regarding the RPUs. If I have a query with skip(20).limit(20) from the explain plan I see I get 20 results, with 40 scanned indexes. What is the RPU for such query?
The reason for this ask, is that I expect that a lot of queries from my app will rely on pagination using limit/skip (I know I should probably be using a timestamp field, but this is my reality at the moment).
Another one is regarding aggregations, specially with groups where the entire collection sometimes needs to be scanned. Will I be billed for the size of my collection in RPUs once aggregations are executed?
Thank you
For instance take this aggregation I run on a 110k docs collection. The first stage traverses all documents, but only 26 documents are returned from the aggregation, what is the RPU cost here?
{
"explainVersion": "1",
"stages": [
{
"$cursor": {
"queryPlanner": {
"indexFilterSet": false,
"parsedQuery": {},
"queryHash": "7023421D",
"planCacheKey": "737D18C4",
"maxIndexedOrSolutionsReached": false,
"maxIndexedAndSolutionsReached": false,
"maxScansToExplodeReached": false,
"winningPlan": {
"stage": "PROJECTION_SIMPLE",
"transformBy": {
"issue_date": 1,
"_id": 0
},
"inputStage": {
"stage": "COLLSCAN",
"direction": "forward"
}
},
"rejectedPlans": []
},
"executionStats": {
"executionSuccess": true,
"nReturned": 111579,
"executionTimeMillis": 181,
"totalKeysExamined": 0,
"totalDocsExamined": 111579,
"executionStages": {
"stage": "PROJECTION_SIMPLE",
"nReturned": 111579,
"executionTimeMillisEstimate": 53,
"works": 111581,
"advanced": 111579,
"needTime": 1,
"needYield": 0,
"saveState": 116,
"restoreState": 116,
"isEOF": 1,
"transformBy": {
"issue_date": 1,
"_id": 0
},
"inputStage": {
"stage": "COLLSCAN",
"nReturned": 111579,
"executionTimeMillisEstimate": 21,
"works": 111581,
"advanced": 111579,
"needTime": 1,
"needYield": 0,
"saveState": 116,
"restoreState": 116,
"isEOF": 1,
"direction": "forward",
"docsExamined": 111579
}
},
"allPlansExecution": []
}
},
"nReturned": 111579,
"executionTimeMillisEstimate": 109
},
{
"$group": {
"_id": {
"year": {
"$year": {
"date": "$issue_date"
}
}
},
"total": {
"$sum": {
"$const": 1
}
}
},
"maxAccumulatorMemoryUsageBytes": {
"total": 1872
},
"totalOutputDataSizeBytes": 11908,
"usedDisk": false,
"nReturned": 26,
"executionTimeMillisEstimate": 178
},
{
"$project": {
"_id": true,
"year": "$_id.year",
"total": "$total"
},
"nReturned": 26,
"executionTimeMillisEstimate": 178
},
{
"$sort": {
"sortKey": {
"year": 1
}
},
"totalDataSizeSortedBytesEstimate": 13156,
"usedDisk": false,
"nReturned": 26,
"executionTimeMillisEstimate": 178
}
],
"serverInfo": {
},
"serverParameters": {
"internalQueryFacetBufferSizeBytes": 104857600,
"internalQueryFacetMaxOutputDocSizeBytes": 104857600,
"internalLookupStageIntermediateDocumentMaxSizeBytes": 16793600,
"internalDocumentSourceGroupMaxMemoryBytes": 104857600,
"internalQueryMaxBlockingSortMemoryUsageBytes": 33554432,
"internalQueryProhibitBlockingMergeOnMongoS": 0,
"internalQueryMaxAddToSetBytes": 104857600,
"internalDocumentSourceSetWindowFieldsMaxMemoryBytes": 104857600
},
"command": {
"aggregate": "Pages",
"pipeline": [
{
"$group": {
"_id": {
"year": {
"$year": "$issue_date"
}
},
"total": {
"$count": {}
}
}
},
{
"$project": {
"year": "$_id.year",
"total": "$total"
}
},
{
"$sort": {
"year": 1
}
}
],
"allowDiskUse": true,
"cursor": {},
"maxTimeMS": 60000,
},
"ok": 1,
"$clusterTime": {
"clusterTime": {
"$timestamp": {
"t": 1674088070,
"i": 22
}
},
"signature": {
"hash": {
"$binary": {
"base64": "A/J23GkvPsdMBnzWui0R7/rMKGk=",
"subType": "00"
}
},
"keyId": {
"$numberLong": "7150657730754117634"
}
}
},
"operationTime": {
"$timestamp": {
"t": 1674088070,
"i": 22
}
}
}