Skip to content

Commit

Permalink
improve comments
Browse files Browse the repository at this point in the history
Signed-off-by: Kaituo Li <[email protected]>
  • Loading branch information
kaituo committed Aug 16, 2023
1 parent 13c90a8 commit 7f5a077
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions src/main/java/org/opensearch/timeseries/MemoryTracker.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@
import com.amazon.randomcutforest.RandomCutForest;
import com.amazon.randomcutforest.parkservices.ThresholdedRandomCutForest;

/**
* Responsible for tracking and managing the memory consumption related to OpenSearch time series analysis.
* It offers functionalities to:
* - Track the total memory consumption and consumption per specific origin.
* - Monitor reserved memory bytes.
* - Decide if memory can be allocated based on the current usage and the heap limit.
* - Estimate the memory size for a ThresholdedRandomCutForest model based on various parameters.
*
*/
public class MemoryTracker {
private static final Logger LOG = LogManager.getLogger(MemoryTracker.class);

Expand Down Expand Up @@ -304,11 +313,21 @@ public int getThresholdModelBytes() {
}

/**
* This function derives from the old code: https://tinyurl.com/2eaabja6
* Determines if hosting is allowed based on the estimated size of a given ThresholdedRandomCutForest and
* the available memory resources.
*
* <p>This method synchronizes access to ensure that checks and operations related to resource availability
* are thread-safe.
*
* @param configId The identifier for the configuration being checked. Used in error messages.
* @param trcf The ThresholdedRandomCutForest to estimate the size for.
* @return True if the system can allocate the required bytes to host the trcf.
* @throws LimitExceededException If the required memory for the trcf exceeds the available memory.
*
* @param configId Config Id
* @param trcf Thresholded random cut forest model
* @return true if there is enough memory; otherwise throw LimitExceededException.
* <p>Usage example:
* <pre>{@code
* boolean canHost = isHostingAllowed("config123", myTRCF);
* }</pre>
*/
public synchronized boolean isHostingAllowed(String configId, ThresholdedRandomCutForest trcf) {
long requiredBytes = estimateTRCFModelSize(trcf);
Expand Down

0 comments on commit 7f5a077

Please sign in to comment.