mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-16 18:56:15 +01:00
cache improvements, stats
This commit is contained in:
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
var cacheController = module.exports;
|
var cacheController = module.exports;
|
||||||
|
|
||||||
|
var utils = require('../../utils');
|
||||||
|
|
||||||
cacheController.get = function (req, res) {
|
cacheController.get = function (req, res) {
|
||||||
var postCache = require('../../posts/cache');
|
var postCache = require('../../posts/cache');
|
||||||
var groupCache = require('../../groups').cache;
|
var groupCache = require('../../groups').cache;
|
||||||
@@ -38,6 +40,9 @@ cacheController.get = function (req, res) {
|
|||||||
itemCount: objectCache.itemCount,
|
itemCount: objectCache.itemCount,
|
||||||
percentFull: ((objectCache.length / objectCache.max) * 100).toFixed(2),
|
percentFull: ((objectCache.length / objectCache.max) * 100).toFixed(2),
|
||||||
dump: req.query.debug ? JSON.stringify(objectCache.dump(), null, 4) : false,
|
dump: req.query.debug ? JSON.stringify(objectCache.dump(), null, 4) : false,
|
||||||
|
hits: utils.addCommas(String(objectCache.hits)),
|
||||||
|
misses: utils.addCommas(String(objectCache.misses)),
|
||||||
|
missRatio: (1 - (objectCache.hits / (objectCache.hits + objectCache.misses))).toFixed(4),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ module.exports = function (db, module) {
|
|||||||
maxAge: 0,
|
maxAge: 0,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
cache.misses = 0;
|
||||||
|
cache.hits = 0;
|
||||||
module.objectCache = cache;
|
module.objectCache = cache;
|
||||||
|
|
||||||
pubsub.on('mongo:hash:cache:del', function (key) {
|
pubsub.on('mongo:hash:cache:del', function (key) {
|
||||||
@@ -86,9 +88,14 @@ module.exports = function (db, module) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var nonCachedKeys = keys.filter(function (key) {
|
var nonCachedKeys = keys.filter(function (key) {
|
||||||
return !cache.get(key);
|
return cache.get(key) === undefined;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var hits = keys.length - nonCachedKeys.length;
|
||||||
|
var misses = keys.length - hits;
|
||||||
|
cache.hits += hits;
|
||||||
|
cache.misses += misses;
|
||||||
|
|
||||||
if (!nonCachedKeys.length) {
|
if (!nonCachedKeys.length) {
|
||||||
return getFromCache(callback);
|
return getFromCache(callback);
|
||||||
}
|
}
|
||||||
@@ -98,12 +105,9 @@ module.exports = function (db, module) {
|
|||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
data.forEach(function (objectData) {
|
var map = helpers.toMap(data);
|
||||||
if (objectData) {
|
nonCachedKeys.forEach(function (key) {
|
||||||
var key = objectData._key;
|
cache.set(key, map[key] || null);
|
||||||
delete objectData._key;
|
|
||||||
cache.set(key, objectData);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
getFromCache(callback);
|
getFromCache(callback);
|
||||||
|
|||||||
@@ -30,15 +30,20 @@
|
|||||||
<div class="panel-heading"><i class="fa fa-calendar-o"></i> Object Cache</div>
|
<div class="panel-heading"><i class="fa fa-calendar-o"></i> Object Cache</div>
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<label>[[admin/advanced/cache:length-to-max]]</label><br/>
|
<label>[[admin/advanced/cache:length-to-max]]</label><br/>
|
||||||
<span>{objectCache.length} / {objectCache.max}</span><br/>
|
<span>{objectCache.length} / {objectCache.max}</span><br/>
|
||||||
|
|
||||||
<div class="progress">
|
<div class="progress">
|
||||||
<div class="progress-bar" role="progressbar" aria-valuenow="{objectCache.percentFull}" aria-valuemin="0" aria-valuemax="100" style="width: {objectCache.percentFull}%;">
|
<div class="progress-bar" role="progressbar" aria-valuenow="{objectCache.percentFull}" aria-valuemin="0" aria-valuemax="100" style="width: {objectCache.percentFull}%;">
|
||||||
[[admin/advanced/cache:percent-full, {objectCache.percentFull}]]
|
[[admin/advanced/cache:percent-full, {objectCache.percentFull}]]
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<label>Hits:</label> <span>{objectCache.hits}</span><br/>
|
||||||
|
<label>Misses:</label> <span>{objectCache.misses}</span><br/>
|
||||||
|
<label>Miss Ratio:</label> <span>{objectCache.missRatio}</span><br/>
|
||||||
|
|
||||||
<!-- IF objectCache.dump -->
|
<!-- IF objectCache.dump -->
|
||||||
<pre>{objectCache.dump}</pre>
|
<pre>{objectCache.dump}</pre>
|
||||||
<!-- ENDIF objectCache.dump -->
|
<!-- ENDIF objectCache.dump -->
|
||||||
|
|||||||
Reference in New Issue
Block a user