diff options
author | Shin Yee Tan <shinyee.tan@mongodb.com> | 2022-07-15 19:02:18 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-11-23 13:55:00 +0000 |
commit | 06729d7c8624609bf417324c3e11c4f6d4641a5d (patch) | |
tree | 4a84373c10a6a33d0f87d9d021a8f02c875ff435 /jstests/noPassthrough | |
parent | 200257e2ce28cb29e03bd0711a33498e7688ddc7 (diff) | |
download | mongo-06729d7c8624609bf417324c3e11c4f6d4641a5d.tar.gz |
SERVER-60455 serverStatus metrics for external sorter
(cherry picked from commit dc6803c67067003e6575fdd57e7c387fbcb8b23b)
Diffstat (limited to 'jstests/noPassthrough')
-rw-r--r-- | jstests/noPassthrough/serverstatus_indexbulkbuilder.js | 47 |
1 files changed, 43 insertions, 4 deletions
diff --git a/jstests/noPassthrough/serverstatus_indexbulkbuilder.js b/jstests/noPassthrough/serverstatus_indexbulkbuilder.js index ca72e721b1f..7d10f5fcc49 100644 --- a/jstests/noPassthrough/serverstatus_indexbulkbuilder.js +++ b/jstests/noPassthrough/serverstatus_indexbulkbuilder.js @@ -12,9 +12,15 @@ load('jstests/noPassthrough/libs/index_build.js'); +const maxMemUsageMegabytes = 50; +const numDocs = 10; +const fieldSize = 10 * 1024 * 1024; +const approxMemoryUsage = numDocs * fieldSize; +let expectedSpilledRanges = approxMemoryUsage / (maxMemUsageMegabytes * 1024 * 1024); + const replSet = new ReplSetTest({ nodes: 1, - nodeOptions: {setParameter: {maxIndexBuildMemoryUsageMegabytes: 50}}, + nodeOptions: {setParameter: {maxIndexBuildMemoryUsageMegabytes: maxMemUsageMegabytes}}, }); replSet.startSet(); replSet.initiate(); @@ -23,10 +29,10 @@ let primary = replSet.getPrimary(); let testDB = primary.getDB('test'); let coll = testDB.getCollection('t'); -for (let i = 0; i < 10; i++) { +for (let i = 0; i < numDocs; i++) { assert.commandWorked(coll.insert({ _id: i, - a: 'a'.repeat(10 * 1024 * 1024), + a: 'a'.repeat(fieldSize), })); } @@ -41,6 +47,13 @@ assert.eq(indexBulkBuilderSection.count, 1, tojson(indexBulkBuilderSection)); assert.eq(indexBulkBuilderSection.resumed, 0, tojson(indexBulkBuilderSection)); assert.eq(indexBulkBuilderSection.filesOpenedForExternalSort, 1, tojson(indexBulkBuilderSection)); assert.eq(indexBulkBuilderSection.filesClosedForExternalSort, 1, tojson(indexBulkBuilderSection)); +assert.eq( + indexBulkBuilderSection.spilledRanges, expectedSpilledRanges, tojson(indexBulkBuilderSection)); +assert.between(0, + indexBulkBuilderSection.bytesSpilled, + approxMemoryUsage, + tojson(indexBulkBuilderSection), + true); // Shut down server during an index to verify 'resumable' value on restart. IndexBuildTest.pauseIndexBuilds(primary); @@ -68,9 +81,16 @@ assert.eq(indexBulkBuilderSection.resumed, 1, tojson(indexBulkBuilderSection)); // and read it back on startup. assert.eq(indexBulkBuilderSection.filesOpenedForExternalSort, 1, tojson(indexBulkBuilderSection)); assert.eq(indexBulkBuilderSection.filesClosedForExternalSort, 1, tojson(indexBulkBuilderSection)); +assert.eq(indexBulkBuilderSection.spilledRanges, 1, tojson(indexBulkBuilderSection)); +assert.between(0, + indexBulkBuilderSection.bytesSpilled, + approxMemoryUsage, + tojson(indexBulkBuilderSection), + true); // Confirm that metrics are updated during initial sync. -const newNode = replSet.add({setParameter: {maxIndexBuildMemoryUsageMegabytes: 50}}); +const newNode = + replSet.add({setParameter: {maxIndexBuildMemoryUsageMegabytes: maxMemUsageMegabytes}}); replSet.reInitiate(); replSet.waitForState(newNode, ReplSetTest.State.SECONDARY); replSet.awaitReplication(); @@ -85,6 +105,17 @@ indexBulkBuilderSection = newNodeTestDB.serverStatus().indexBulkBuilder; assert.gte(indexBulkBuilderSection.count, 3, tojson(indexBulkBuilderSection)); assert.eq(indexBulkBuilderSection.filesOpenedForExternalSort, 1, tojson(indexBulkBuilderSection)); assert.eq(indexBulkBuilderSection.filesClosedForExternalSort, 1, tojson(indexBulkBuilderSection)); +// We try building two indexes for the test collection so the memory usage limit for each index +// build during initial sync is the maxIndexBuildMemoryUsageMegabytes divided by the number of index +// builds. We end up with half of the in-memory memory so we double the amount of spills expected. +expectedSpilledRanges *= 2; +assert.eq( + indexBulkBuilderSection.spilledRanges, expectedSpilledRanges, tojson(indexBulkBuilderSection)); +assert.between(0, + indexBulkBuilderSection.bytesSpilled, + approxMemoryUsage, + tojson(indexBulkBuilderSection), + true); // Building multiple indexes in a single createIndex command increases count by the number of // indexes requested. @@ -99,6 +130,14 @@ assert.eq(indexBulkBuilderSection.count, 4, tojson(indexBulkBuilderSection)); assert.eq(indexBulkBuilderSection.resumed, 1, tojson(indexBulkBuilderSection)); assert.eq(indexBulkBuilderSection.filesOpenedForExternalSort, 2, tojson(indexBulkBuilderSection)); assert.eq(indexBulkBuilderSection.filesClosedForExternalSort, 2, tojson(indexBulkBuilderSection)); +expectedSpilledRanges += 2; +assert.eq( + indexBulkBuilderSection.spilledRanges, expectedSpilledRanges, tojson(indexBulkBuilderSection)); +assert.between(0, + indexBulkBuilderSection.bytesSpilled, + approxMemoryUsage, + tojson(indexBulkBuilderSection), + true); replSet.stopSet(); })(); |