summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian DeLeonardis <brian.deleonardis@mongodb.com>2020-11-10 23:43:42 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-11-11 21:36:30 +0000
commitb457c077f0e7688d890885619eb33e73f4a65219 (patch)
tree78b7e6c16aea243336de27c02ce33e06e4921fb9
parentcb0deac8d70bd1927546f751526441daaabd55ec (diff)
downloadmongo-b457c077f0e7688d890885619eb33e73f4a65219.tar.gz
SERVER-51785 Do not count oplog writes for resource consumption metrics
-rw-r--r--jstests/core/profile_operation_metrics.js157
-rw-r--r--jstests/noPassthrough/index_build_operation_metrics.js7
-rw-r--r--src/mongo/db/stats/resource_consumption_metrics.h4
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp6
4 files changed, 48 insertions, 126 deletions
diff --git a/jstests/core/profile_operation_metrics.js b/jstests/core/profile_operation_metrics.js
index cd5b32eb687..1bd780f3a61 100644
--- a/jstests/core/profile_operation_metrics.js
+++ b/jstests/core/profile_operation_metrics.js
@@ -139,19 +139,8 @@ const operations = [
assert.eq(profileDoc.docUnitsRead, 0);
assert.eq(profileDoc.idxEntryBytesRead, 0);
assert.eq(profileDoc.idxEntryUnitsRead, 0);
- if (isReplSet) {
- // Ensure writes to the oplog are counted. Some oplog fields like UUID are
- // randomized between runs, but the types are fixed-length, so we can make strong
- // assertions about the sizes. If the oplog format changes for any reason, then so
- // will these assertions.
- assert.eq(profileDoc.docBytesWritten, 188);
- // Note that the oplog entry is greater than the default unit size of 128 bytes so
- // it counts for 2 document units.
- assert.eq(profileDoc.docUnitsWritten, 3);
- } else {
- assert.eq(profileDoc.docBytesWritten, 29);
- assert.eq(profileDoc.docUnitsWritten, 1);
- }
+ assert.eq(profileDoc.docBytesWritten, 29);
+ assert.eq(profileDoc.docUnitsWritten, 1);
assert.eq(profileDoc.idxEntryBytesWritten, 7);
assert.eq(profileDoc.idxEntryUnitsWritten, 2);
}
@@ -257,16 +246,10 @@ const operations = [
}
assert.eq(profileDoc.idxEntryBytesRead, 3);
assert.eq(profileDoc.idxEntryUnitsRead, 1);
- if (isReplSet) {
- // Ensure writes to the oplog are counted.
- assert.eq(profileDoc.docBytesWritten, 224);
- assert.eq(profileDoc.docUnitsWritten, 3);
- } else {
- // This update will not be performed in-place because it is too small and affects an
- // index.
- assert.eq(profileDoc.docBytesWritten, 29);
- assert.eq(profileDoc.docUnitsWritten, 1);
- }
+ // This update will not be performed in-place because it is too small and affects an
+ // index.
+ assert.eq(profileDoc.docBytesWritten, 29);
+ assert.eq(profileDoc.docUnitsWritten, 1);
// Deletes one index entry and writes another.
assert.eq(profileDoc.idxEntryBytesWritten, 9);
assert.eq(profileDoc.idxEntryUnitsWritten, 2);
@@ -290,16 +273,10 @@ const operations = [
}
assert.eq(profileDoc.idxEntryBytesRead, 3);
assert.eq(profileDoc.idxEntryUnitsRead, 1);
- if (isReplSet) {
- // Ensure writes to the oplog are counted.
- assert.eq(profileDoc.docBytesWritten, 224);
- assert.eq(profileDoc.docUnitsWritten, 3);
- } else {
- // This update will not be performed in-place because it is too small and affects an
- // index.
- assert.eq(profileDoc.docBytesWritten, 29);
- assert.eq(profileDoc.docUnitsWritten, 1);
- }
+ // This update will not be performed in-place because it is too small and affects an
+ // index.
+ assert.eq(profileDoc.docBytesWritten, 29);
+ assert.eq(profileDoc.docUnitsWritten, 1);
// Deletes one index entry and writes another.
assert.eq(profileDoc.idxEntryBytesWritten, 10);
assert.eq(profileDoc.idxEntryUnitsWritten, 2);
@@ -441,15 +418,9 @@ const operations = [
}
assert.eq(profileDoc.idxEntryBytesRead, 3);
assert.eq(profileDoc.idxEntryUnitsRead, 1);
- if (isReplSet) {
- // Ensure writes to the oplog are counted.
- assert.eq(profileDoc.docBytesWritten, 177);
- assert.eq(profileDoc.docUnitsWritten, 3);
- } else {
- // Deleted bytes are counted as 'written'.
- assert.eq(profileDoc.docBytesWritten, 29);
- assert.eq(profileDoc.docUnitsWritten, 1);
- }
+ // Deleted bytes are counted as 'written'.
+ assert.eq(profileDoc.docBytesWritten, 29);
+ assert.eq(profileDoc.docUnitsWritten, 1);
assert.eq(profileDoc.idxEntryBytesWritten, 3);
assert.eq(profileDoc.idxEntryUnitsWritten, 1);
}
@@ -470,15 +441,9 @@ const operations = [
}
assert.eq(profileDoc.idxEntryBytesRead, 0);
assert.eq(profileDoc.idxEntryUnitsRead, 0);
- if (isReplSet) {
- // Ensure writes to the oplog are counted.
- assert.eq(profileDoc.docBytesWritten, 177);
- assert.eq(profileDoc.docUnitsWritten, 3);
- } else {
- // Deleted bytes are counted as 'written'.
- assert.eq(profileDoc.docBytesWritten, 29);
- assert.eq(profileDoc.docUnitsWritten, 1);
- }
+ // Deleted bytes are counted as 'written'.
+ assert.eq(profileDoc.docBytesWritten, 29);
+ assert.eq(profileDoc.docUnitsWritten, 1);
assert.eq(profileDoc.idxEntryBytesWritten, 3);
assert.eq(profileDoc.idxEntryUnitsWritten, 1);
}
@@ -560,17 +525,8 @@ const operations = [
// Reads the index entry for 'a' to determine uniqueness.
assert.eq(profileDoc.idxEntryBytesRead, 6);
assert.eq(profileDoc.idxEntryUnitsRead, 1);
- if (isReplSet) {
- // Ensure writes to the oplog are counted. Some oplog fields like UUID are
- // randomized between runs, but the types are fixed-length, so we can make strong
- // assertions about the sizes. If the oplog format changes for any reason, then so
- // will these assertions.
- assert.eq(profileDoc.docBytesWritten, 188);
- assert.eq(profileDoc.docUnitsWritten, 3);
- } else {
- assert.eq(profileDoc.docBytesWritten, 29);
- assert.eq(profileDoc.docUnitsWritten, 1);
- }
+ assert.eq(profileDoc.docBytesWritten, 29);
+ assert.eq(profileDoc.docUnitsWritten, 1);
// Deletes one entry and writes another.
assert.eq(profileDoc.idxEntryBytesWritten, 10);
assert.eq(profileDoc.idxEntryUnitsWritten, 2);
@@ -620,16 +576,10 @@ const operations = [
// Reads index entries on '_id' for the lookup and 'a' to ensure uniqueness.
assert.eq(profileDoc.idxEntryBytesRead, 9);
assert.eq(profileDoc.idxEntryUnitsRead, 2);
- if (isReplSet) {
- // Ensure writes to the oplog are counted.
- assert.eq(profileDoc.docBytesWritten, 224);
- assert.eq(profileDoc.docUnitsWritten, 3);
- } else {
- // This out-of-place update should perform a direct insert because it is not large
- // enough to qualify for the in-place update path.
- assert.eq(profileDoc.docBytesWritten, 29);
- assert.eq(profileDoc.docUnitsWritten, 1);
- }
+ // This out-of-place update should perform a direct insert because it is not large
+ // enough to qualify for the in-place update path.
+ assert.eq(profileDoc.docBytesWritten, 29);
+ assert.eq(profileDoc.docUnitsWritten, 1);
// Removes one entry and inserts another.
assert.eq(profileDoc.idxEntryBytesWritten, 11);
assert.eq(profileDoc.idxEntryUnitsWritten, 2);
@@ -661,11 +611,10 @@ const operations = [
assert.eq(profileDoc.idxEntryBytesRead, 10);
assert.eq(profileDoc.idxEntryUnitsRead, 2);
if (isReplSet) {
- // When WT_MODIFY is used on a replicated collection, in addition to writing fewer
- // bytes per the comment about WT_MODIFY above, ensure it also inserts into the
- // oplog.
- assert.eq(profileDoc.docBytesWritten, 208);
- assert.eq(profileDoc.docUnitsWritten, 3);
+ // When WT_MODIFY is used on a replicated collection fewer bytes are written per the
+ // comment about WT_MODIFY above.
+ assert.eq(profileDoc.docBytesWritten, 13);
+ assert.eq(profileDoc.docUnitsWritten, 1);
} else {
assert.eq(profileDoc.docBytesWritten, 1061);
assert.eq(profileDoc.docUnitsWritten, 9);
@@ -699,18 +648,10 @@ const operations = [
}
assert.eq(profileDoc.idxEntryBytesRead, 4);
assert.eq(profileDoc.idxEntryUnitsRead, 1);
- if (isReplSet) {
- // When WT_MODIFY is used on a replicated collection, in addition to writing fewer
- // bytes per the comment about WT_MODIFY above, ensure it also inserts into the
- // oplog.
- assert.eq(profileDoc.docBytesWritten, 211);
- assert.eq(profileDoc.docUnitsWritten, 3);
- } else {
- // This is calculated as the number of bytes overwritten + the number of bytes
- // written, and is still less than the full document size.
- assert.eq(profileDoc.docBytesWritten, 16);
- assert.eq(profileDoc.docUnitsWritten, 1);
- }
+ // This is calculated as the number of bytes overwritten + the number of bytes
+ // written, and is still less than the full document size.
+ assert.eq(profileDoc.docBytesWritten, 16);
+ assert.eq(profileDoc.docUnitsWritten, 1);
assert.eq(profileDoc.idxEntryBytesWritten, 0);
assert.eq(profileDoc.idxEntryUnitsWritten, 0);
}
@@ -731,13 +672,8 @@ const operations = [
assert.eq(profileDoc.docUnitsRead, 0);
assert.eq(profileDoc.idxEntryBytesRead, 0);
assert.eq(profileDoc.idxEntryUnitsRead, 0);
- if (isReplSet) {
- assert.eq(profileDoc.docBytesWritten, 188);
- assert.eq(profileDoc.docUnitsWritten, 3);
- } else {
- assert.eq(profileDoc.docBytesWritten, 29);
- assert.eq(profileDoc.docUnitsWritten, 1);
- }
+ assert.eq(profileDoc.docBytesWritten, 29);
+ assert.eq(profileDoc.docUnitsWritten, 1);
assert.eq(profileDoc.idxEntryBytesWritten, 3);
assert.eq(profileDoc.idxEntryUnitsWritten, 1);
}
@@ -808,13 +744,8 @@ const operations = [
}
assert.eq(profileDoc.idxEntryBytesRead, 3);
assert.eq(profileDoc.idxEntryUnitsRead, 1);
- if (isReplSet) {
- assert.eq(profileDoc.docBytesWritten, 211);
- assert.eq(profileDoc.docUnitsWritten, 3);
- } else {
- assert.eq(profileDoc.docBytesWritten, 16);
- assert.eq(profileDoc.docUnitsWritten, 1);
- }
+ assert.eq(profileDoc.docBytesWritten, 16);
+ assert.eq(profileDoc.docUnitsWritten, 1);
assert.eq(profileDoc.idxEntryBytesWritten, 0);
assert.eq(profileDoc.idxEntryUnitsWritten, 0);
}
@@ -837,13 +768,8 @@ const operations = [
}
assert.eq(profileDoc.idxEntryBytesRead, 3);
assert.eq(profileDoc.idxEntryUnitsRead, 1);
- if (isReplSet) {
- assert.eq(profileDoc.docBytesWritten, 177);
- assert.eq(profileDoc.docUnitsWritten, 3);
- } else {
- assert.eq(profileDoc.docBytesWritten, 29);
- assert.eq(profileDoc.docUnitsWritten, 1);
- }
+ assert.eq(profileDoc.docBytesWritten, 29);
+ assert.eq(profileDoc.docUnitsWritten, 1);
assert.eq(profileDoc.idxEntryBytesWritten, 3);
assert.eq(profileDoc.idxEntryUnitsWritten, 1);
}
@@ -865,15 +791,8 @@ const operations = [
assert.eq(profileDoc.docUnitsRead, 0);
assert.eq(profileDoc.idxEntryBytesRead, 0);
assert.eq(profileDoc.idxEntryUnitsRead, 0);
- if (isReplSet) {
- assert.eq(profileDoc.docBytesWritten, 18800);
- // Each inserted document counts for 1 document unit plus 2 document units for its
- // oplog entry (which is larger than the default unit size of 128 bytes).
- assert.eq(profileDoc.docUnitsWritten, 300);
- } else {
- assert.eq(profileDoc.docBytesWritten, 2900);
- assert.eq(profileDoc.docUnitsWritten, 100);
- }
+ assert.eq(profileDoc.docBytesWritten, 2900);
+ assert.eq(profileDoc.docUnitsWritten, 100);
assert.eq(profileDoc.idxEntryBytesWritten, 299);
assert.eq(profileDoc.idxEntryUnitsWritten, 100);
}
diff --git a/jstests/noPassthrough/index_build_operation_metrics.js b/jstests/noPassthrough/index_build_operation_metrics.js
index c2311e5a3ae..88b549e2467 100644
--- a/jstests/noPassthrough/index_build_operation_metrics.js
+++ b/jstests/noPassthrough/index_build_operation_metrics.js
@@ -74,10 +74,9 @@ assert.commandWorked(primaryDB.createCollection(collName));
assert.commandWorked(bulk.execute());
assertMetrics(primary, (metrics) => {
- // Each document insert counts as 1 unit plus 2 units (default unit size = 128) per oplog
- // entry.
- assert.eq(metrics[dbName].docBytesWritten, 167 * nDocs);
- assert.eq(metrics[dbName].docUnitsWritten, 3 * nDocs);
+ // Each document is 29 bytes and we do not count oplog writes.
+ assert.eq(metrics[dbName].docBytesWritten, 29 * nDocs);
+ assert.eq(metrics[dbName].docUnitsWritten, nDocs);
// The inserted keys will vary in size from 2 to 4 bytes depending on their value. Assert
// that the number of bytes fall within that range.
diff --git a/src/mongo/db/stats/resource_consumption_metrics.h b/src/mongo/db/stats/resource_consumption_metrics.h
index 2f7855dd870..5e49b6f5f9a 100644
--- a/src/mongo/db/stats/resource_consumption_metrics.h
+++ b/src/mongo/db/stats/resource_consumption_metrics.h
@@ -265,7 +265,9 @@ public:
/**
* This should be called once per document written with the number of bytes written for that
- * document. This is a no-op when metrics collection is disabled on this operation.
+ * document. This is a no-op when metrics collection is disabled on this operation. This
+ * function should not be called when the operation is a write to the oplog. The metrics are
+ * only for operations that are not oplog writes.
*/
void incrementOneDocWritten(size_t docBytesWritten);
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp
index 312b76bb9a8..02aad79e6ed 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp
@@ -1512,8 +1512,10 @@ Status WiredTigerRecordStore::_insertRecords(OperationContext* opCtx,
// Increment metrics for each insert separately, as opposed to outside of the loop. The API
// requires that each record be accounted for separately.
- auto& metricsCollector = ResourceConsumption::MetricsCollector::get(opCtx);
- metricsCollector.incrementOneDocWritten(value.size);
+ if (!_isOplog) {
+ auto& metricsCollector = ResourceConsumption::MetricsCollector::get(opCtx);
+ metricsCollector.incrementOneDocWritten(value.size);
+ }
}
_changeNumRecords(opCtx, nRecords);