Perf
This commit is contained in:
parent
e059c26083
commit
d48831aa9e
15
others/scaler.mjs
Normal file
15
others/scaler.mjs
Normal file
|
@ -0,0 +1,15 @@
|
|||
import NodeCache from 'node-cache';
|
||||
|
||||
const cache = new NodeCache({ stdTTL: 345600, checkperiod: 3600, useClones: false });
|
||||
|
||||
function scaleCache() {
|
||||
const mem = process.memoryUsage();
|
||||
const freeHeap = mem.heapTotal - mem.heapUsed;
|
||||
const ratio = freeHeap / mem.heapTotal;
|
||||
|
||||
const max = ratio > 0.5 ? 20000 : ratio < 0.2 ? 5000 : 10000;
|
||||
cache.options.maxKeys = max;
|
||||
console.log(`[SCALER] freeHeap ${(freeHeap/1e6).toFixed(1)}MB maxKeys → ${max}`);
|
||||
}
|
||||
|
||||
setInterval(scaleCache, 60_000);
|
Loading…
Reference in New Issue
Block a user