Skip to content

Instantly share code, notes, and snippets.

@gharriso
Created June 12, 2018 07:37
Show Gist options
  • Save gharriso/bc1609683b8f07dfbd3d45d93897d20a to your computer and use it in GitHub Desktop.
Save gharriso/bc1609683b8f07dfbd3d45d93897d20a to your computer and use it in GitHub Desktop.
Calculate MongoDB wiredTiger Cache miss rate
function missrate(intervalMs) {
var statsStart = db.serverStatus().wiredTiger.cache;
var startTime = new Date();
sleep(intervalMs);
var endTime = new Date();
var statsEnd = db.serverStatus().wiredTiger.cache;
var logicalReads =
statsEnd['pages requested from the cache'] -
statsStart['pages requested from the cache'];
var physicalReads =
statsEnd['pages read into cache'] - statsStart['pages read into cache'];
var elapsedTime = endTime - startTime;
var missRate = physicalReads * 100 / logicalReads;
var logicalReadRate =
Math.round(logicalReads * 1000 * 100 / elapsedTime) / 100;
var physicalReadRate =
Math.round(physicalReads * 1000 * 100 / elapsedTime) / 100;
print('Elapsed time (ms)', elapsedTime);
print('logical Read Rate IO/s', logicalReadRate);
print('physical Read Rate IO/s', physicalReadRate);
print('wiredTiger miss rate', Math.round(missRate * 100) / 100);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment