Skip to content

Commit

Permalink
[ML] change to only calculate model size on initial load to prevent s…
Browse files Browse the repository at this point in the history
…low cache promotions (#66451) (#66462)

When a value is promoted in the LRU cache, its weight is removed and added.

The LocalModel object was recalculating the model size for ever weight check, which caused a polynomial runtime.

This commit changes the model size to only be calculated in the LocalModel ctor.
  • Loading branch information
benwtrent committed Dec 16, 2020
1 parent 5000ec8 commit a370104
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public class LocalModel implements Closeable {
private final License.OperationMode licenseLevel;
private final CircuitBreaker trainedModelCircuitBreaker;
private final AtomicLong referenceCount;
private final long cachedRamBytesUsed;

LocalModel(String modelId,
String nodeId,
Expand All @@ -67,6 +68,7 @@ public class LocalModel implements Closeable {
TrainedModelStatsService trainedModelStatsService,
CircuitBreaker trainedModelCircuitBreaker) {
this.trainedModelDefinition = trainedModelDefinition;
this.cachedRamBytesUsed = trainedModelDefinition.ramBytesUsed();
this.modelId = modelId;
this.fieldNames = new HashSet<>(input.getFieldNames());
// the ctor being called means a new instance was created.
Expand All @@ -82,7 +84,10 @@ public class LocalModel implements Closeable {
}

long ramBytesUsed() {
return trainedModelDefinition.ramBytesUsed();
// This should always be cached and not calculated on call.
// This is because the caching system calls this method on every promotion call that changes the LRU head
// Consequently, recalculating can cause serious throughput issues due to LRU changes in the cache
return cachedRamBytesUsed;
}

public String getModelId() {
Expand Down

0 comments on commit a370104

Please sign in to comment.