Reduce cache size
Hopefully, this will help determine if the cache is the cause of the memory growth we see.
This commit is contained in:
parent
5f475f107b
commit
cb23cf2d76
|
@ -11,6 +11,7 @@ function Cache(size, type) {
|
||||||
type = type || 'unit';
|
type = type || 'unit';
|
||||||
this.size = size;
|
this.size = size;
|
||||||
this.type = typeEnum[type];
|
this.type = typeEnum[type];
|
||||||
|
if (this.type === typeEnum.unit) { this.size -= 1; }
|
||||||
// `cache` contains {content, index}.
|
// `cache` contains {content, index}.
|
||||||
// - content: the actual data that is cached.
|
// - content: the actual data that is cached.
|
||||||
// - index: the position in `order` of the data.
|
// - index: the position in `order` of the data.
|
||||||
|
@ -30,6 +31,7 @@ Cache.prototype = {
|
||||||
// If the cache is full, remove the oldest data
|
// If the cache is full, remove the oldest data
|
||||||
// (ie, the data requested longest ago.)
|
// (ie, the data requested longest ago.)
|
||||||
var numberToRemove = this.limitReached();
|
var numberToRemove = this.limitReached();
|
||||||
|
if (numberToRemove > this.order.length) { numberToRemove = this.order.length; }
|
||||||
for (var i = 0; i < numberToRemove; i++) {
|
for (var i = 0; i < numberToRemove; i++) {
|
||||||
// Remove `order`'s oldest element, the first.
|
// Remove `order`'s oldest element, the first.
|
||||||
delete this.cache[this.order[0]];
|
delete this.cache[this.order[0]];
|
||||||
|
@ -39,7 +41,7 @@ Cache.prototype = {
|
||||||
this.cache[cacheIndex] = {
|
this.cache[cacheIndex] = {
|
||||||
index: this.order.length,
|
index: this.order.length,
|
||||||
content: cached,
|
content: cached,
|
||||||
}
|
};
|
||||||
this.order.push(cacheIndex);
|
this.order.push(cacheIndex);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -58,9 +60,10 @@ Cache.prototype = {
|
||||||
return this.cache[cacheIndex] !== undefined;
|
return this.cache[cacheIndex] !== undefined;
|
||||||
},
|
},
|
||||||
|
|
||||||
// Returns true if we're past the limit.
|
// Returns the number of elements to remove if we're past the limit.
|
||||||
limitReached: function heuristic() {
|
limitReached: function heuristic() {
|
||||||
if (this.type === typeEnum.unit) {
|
if (this.type === typeEnum.unit) {
|
||||||
|
// Remove the excess.
|
||||||
return Math.max(0, (this.order.length - this.size));
|
return Math.max(0, (this.order.length - this.size));
|
||||||
} else if (this.type === typeEnum.heap) {
|
} else if (this.type === typeEnum.heap) {
|
||||||
if (getHeapSize() >= this.size) {
|
if (getHeapSize() >= this.size) {
|
||||||
|
|
|
@ -157,8 +157,8 @@ var minAccuracy = 0.75;
|
||||||
// = 1 - max(1, df) / rf
|
// = 1 - max(1, df) / rf
|
||||||
var freqRatioMax = 1 - minAccuracy;
|
var freqRatioMax = 1 - minAccuracy;
|
||||||
|
|
||||||
// Request cache size of 500MB (~1000 bytes/image).
|
// Request cache size of 50MB (~5000 bytes/image).
|
||||||
var requestCache = new LruCache(500000);
|
var requestCache = new LruCache(10000);
|
||||||
|
|
||||||
// Deep error handling for vendor hooks.
|
// Deep error handling for vendor hooks.
|
||||||
var vendorDomain = domain.create();
|
var vendorDomain = domain.create();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user