MongoDBPerformanceTuningBook icon indicating copy to clipboard operation
MongoDBPerformanceTuningBook copied to clipboard

Some of the mongoTuning.js function can't be used in mongodb6

Open yuing32 opened this issue 2 years ago • 1 comments

Some of the mongoTuning.js function are not working in mongodb6. (mongoTuning.js is an excellent tool~ Hope it can still work in the future)

For example: var explainCsr=db.<collection_name>.explain().find() mongoTuning.quickExplain(explainCsr)

It is not working currently because .explain().find() is not a cursor anymore. The solution for this case: db.<collection_name>.find().explain() Because the result is still cursor.

================================= Another case is "mongoTuning.keyServerStats(5000)" TypeError: Cannot read properties of undefined (reading 'rate')

Seem the case is same (cursor)~ But I am not able to fix it currently because the code is quite difficult for me (I am not programmer)......

yuing32 avatar Oct 22 '23 10:10 yuing32

Another case is "mongoTuning.keyServerStats(5000)"

I just fix this case.

mongoTuning.derivedStatistics = function (serverData) { const { deltas, finals } = serverData; const data = {}; const descriptions = {}; // ********************************************* // Network counters // *********************************************

data.netKBInPS = deltas['network.bytesIn.low'].rate / 1024; data.netKBOutPS = deltas['network.bytesOut.low'].rate / 1024;

// ******************************************** // Activity counters // ******************************************** data.intervalSeconds = deltas.timeDelta; data.queryPS = deltas['opcounters.query.low'].rate; data.getmorePS = deltas['opcounters.getmore.low'].rate; data.commandPS = deltas['opcounters.command.low'].rate; data.insertPS = deltas['opcounters.insert.low'].rate; data.updatePS = deltas['opcounters.update.low'].rate; data.deletePS = deltas['opcounters.delete.low'].rate;

// ******************************************** // Document counters // ******************************************** data.docsReturnedPS = deltas['metrics.document.returned.low'].rate; data.docsUpdatedPS = deltas['metrics.document.updated.low'].rate; data.docsInsertedPS = deltas['metrics.document.inserted.low'].rate; data.ixscanDocsPS = deltas['metrics.queryExecutor.scanned.low'].rate; data.collscanDocsPS = deltas['metrics.queryExecutor.scannedObjects.low'].rate;

descriptions.scansToDocumentRatio = 'Ratio of documents scanned to documents returned'; if (data.docsReturnedPS > 0) { data.scansToDocumentRatio = (data.ixscanDocsPS + data.collscanDocsPS) / data.docsReturnedPS; } else { data.scansToDocumentRatio = 0; }

// ******************************************** // Transaction statistics // ******************************************** data.transactionsStartedPS = deltas['transactions.totalStarted.low'].rate; data.transactionsAbortedPS = deltas['transactions.totalAborted.low'].rate; data.transactionsCommittedPS = deltas['transactions.totalCommitted.low'].rate; if (data.transactionsStartedPS > 0) { data.transactionAbortPct = (data.transactionsAbortedPS * 100) / data.transactionsStartedPS; } else { data.transactionAbortPct = 0; }

if (deltas['opLatencies.reads.ops.low'].delta > 0) { data.readLatencyMs = deltas['opLatencies.reads.latency.low'].delta / deltas['opLatencies.reads.ops.low'].delta / 1000; } else data.readLatency = 0;

if (deltas['opLatencies.writes.ops.low'].delta > 0) { data.writeLatencyMs = deltas['opLatencies.writes.latency.low'].delta / deltas['opLatencies.writes.ops.low'].delta / 1000; } else data.writeLatency = 0;

if (deltas['opLatencies.commands.ops.low'].delta > 0) { data.cmdLatencyMs = deltas['opLatencies.commands.latency.low'].delta / deltas['opLatencies.commands.ops.low'].delta / 1000; } else data.cmdLatency = 0;

data.connections = deltas['connections.current'].lastValue; data.availableConnections = deltas['connections.available'].firstValue; data.assertsPS = deltas['asserts.regular'].rate + deltas['asserts.warning'].rate + deltas['asserts.msg'].rate + deltas['asserts.user'].rate + deltas['asserts.rollovers'].rate;

data.activeReaders = finals['globalLock.activeClients.readers']; data.activeWriters = finals['globalLock.activeClients.writers']; data.queuedReaders = finals['globalLock.currentQueue.readers']; data.queuedWriters = finals['globalLock.currentQueue.writers']; data.globalLockQueue = { readActive: data.activeReaders, readQueued: data.queuedReaders, writeActive: data.activeWriters, writeQueued: data.queuedWriters, };

// ********************************************************* // Memory counters // *********************************************************

data.cacheReadQAvailable = deltas['wiredTiger.concurrentTransactions.read.available'].lastValue; data.cacheReadQUsed = deltas['wiredTiger.concurrentTransactions.read.out'].lastValue;

data.cacheWriteQAvailable = deltas['wiredTiger.concurrentTransactions.write.available'].lastValue; data.cacheWriteQUsed = deltas['wiredTiger.concurrentTransactions.write.out'].lastValue;

data.cacheGetsPS = deltas['wiredTiger.cache.pages requested from the cache'].rate;

data.cacheReadInsPS = deltas['wiredTiger.cache.pages read into cache'].rate;

descriptions.cacheHitRate = 'Hit Rate in the wiredTigerCache '; if (data.cacheGetsPS > 0) { data.cacheHitRate = ((data.cacheGetsPS - data.cacheReadInsPS) * 100) / data.cacheGetsPS; } else { data.cacheHitRate = 0; }

data.evictionsPs = deltas['wiredTiger.cache.internal pages evicted'].rate; data.evictionBlockedPs = deltas['wiredTiger.thread-yield.page acquire eviction blocked'].rate; if (data.evictionsPs > 0) { data.evictionBlockRate = (data.evictionBlockedPs * 100) / data.evictionsPs; } else data.evictionBlockRate = 0;

if (data.cacheReadInsPS > 0) { data.evictionRate = (data.evictionsPs * 100) / data.cacheReadInsPS; } else data.evictionRate = 0;

data.cacheHighWaterMB = deltas['wiredTiger.cache.maximum bytes configured.low'].lastValue / 1048576;

data.cacheSizeMB = deltas['wiredTiger.cache.bytes currently in the cache'].lastValue / 1048576;

data.diskBlockReadsPS = deltas['wiredTiger.block-manager.blocks read'].rate; data.diskBlockWritesPS = deltas['wiredTiger.block-manager.blocks written'].rate;

data.logKBRatePS = deltas['wiredTiger.log.log bytes written'].rate / 1024;

data.logSyncTimeRateMsPS = deltas['wiredTiger.log.log sync time duration (usecs)'].rate / 1000;

data.logSyncOpsPS = deltas['wiredTiger.log.log sync operations'].rate;

if (data.logSyncOpsPS > 0) { data.logAvgSyncTime = data.logSyncTimeRateMsPS / data.logSyncOpsPS; } else data.logAvgSyncTime = 0;

// ********************************************************* // Disk IO // *********************************************************

Object.keys(data).forEach((key) => { if (data[key] % 1 > 0.01) { data[key] = data[key].toFixed(4); } }); return data; };

yuing32 avatar Oct 22 '23 11:10 yuing32