forked from opensearch-project/OpenSearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Bharathwaj G <[email protected]>
- Loading branch information
1 parent
47032e5
commit df6c065
Showing
3 changed files
with
207 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 95 additions & 1 deletion
96
server/src/main/java/org/opensearch/ratelimiting/tracker/NodePerformanceTracker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,96 @@ | ||
package org.opensearch.ratelimiting.tracker;public class NodePerformanceTracker { | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.ratelimiting.tracker; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.opensearch.common.lifecycle.AbstractLifecycleComponent; | ||
import org.opensearch.common.settings.ClusterSettings; | ||
import org.opensearch.common.settings.Settings; | ||
import org.opensearch.common.unit.TimeValue; | ||
import org.opensearch.monitor.fs.FsService; | ||
import org.opensearch.threadpool.Scheduler; | ||
import org.opensearch.threadpool.ThreadPool; | ||
|
||
import java.io.IOException; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
/** | ||
* This tracks the performance of node resources such as CPU, IO and memory | ||
*/ | ||
public class NodePerformanceTracker extends AbstractLifecycleComponent { | ||
private ThreadPool threadPool; | ||
private final ClusterSettings clusterSettings; | ||
private AverageIOUsageTracker ioUsageTracker; | ||
|
||
private AverageDiskStats averageDiskStats; | ||
private PerformanceTrackerSettings performanceTrackerSettings; | ||
private FsService fsService; | ||
private volatile Scheduler.Cancellable scheduledFuture; | ||
private static final Logger logger = LogManager.getLogger(NodePerformanceTracker.class); | ||
|
||
public NodePerformanceTracker(ThreadPool threadPool, Settings settings, ClusterSettings clusterSettings, FsService fsService) { | ||
this.threadPool = threadPool; | ||
this.clusterSettings = clusterSettings; | ||
this.performanceTrackerSettings = new PerformanceTrackerSettings(settings, clusterSettings); | ||
this.fsService = fsService; | ||
initialize(); | ||
} | ||
|
||
void initialize() { | ||
ioUsageTracker = new AverageIOUsageTracker( | ||
threadPool, | ||
new TimeValue(1, TimeUnit.SECONDS), | ||
new TimeValue(60, TimeUnit.SECONDS), | ||
clusterSettings, | ||
fsService | ||
); | ||
} | ||
|
||
private AverageDiskStats getAverageIOUsed() { | ||
return ioUsageTracker.getAverageDiskStats(); | ||
} | ||
|
||
private void setAverageDiskStats(AverageDiskStats averageDiskStats) { | ||
this.averageDiskStats = averageDiskStats; | ||
} | ||
|
||
private AverageDiskStats getAverageDiskStats() { | ||
return averageDiskStats; | ||
} | ||
|
||
private void doRun() { | ||
setAverageDiskStats(getAverageIOUsed()); | ||
logger.info(getAverageDiskStats().toString()); | ||
} | ||
@Override | ||
protected void doStart() { | ||
scheduledFuture = threadPool.scheduleWithFixedDelay(() -> { | ||
try { | ||
doRun(); | ||
} catch (Exception e) { | ||
|
||
} | ||
}, new TimeValue(1, TimeUnit.SECONDS), ThreadPool.Names.GENERIC); | ||
ioUsageTracker.doStart(); | ||
} | ||
|
||
@Override | ||
protected void doStop() { | ||
if (scheduledFuture != null) { | ||
scheduledFuture.cancel(); | ||
} | ||
ioUsageTracker.doStop(); | ||
} | ||
|
||
@Override | ||
protected void doClose() throws IOException { | ||
ioUsageTracker.doClose(); | ||
} | ||
} |
101 changes: 100 additions & 1 deletion
101
server/src/main/java/org/opensearch/ratelimiting/tracker/PerformanceTrackerSettings.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,101 @@ | ||
package org.opensearch.ratelimiting.tracker;public class PerformanceTrackerSettings { | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.ratelimiting.tracker; | ||
|
||
import org.opensearch.common.settings.ClusterSettings; | ||
import org.opensearch.common.settings.Setting; | ||
import org.opensearch.common.settings.Settings; | ||
import org.opensearch.common.unit.TimeValue; | ||
|
||
/** | ||
* Settings related to node performance trackers such as polling interval, window duration etc | ||
*/ | ||
public class PerformanceTrackerSettings { | ||
|
||
private static class Defaults { | ||
/** | ||
* This is the default polling interval of usage trackers to get the resource utilization data | ||
*/ | ||
private static final long POLLING_INTERVAL_IN_MILLIS = 500; | ||
/** | ||
* This is the default window duration on which the average resource utilization values will be calculated | ||
*/ | ||
private static final long WINDOW_DURATION_IN_SECONDS = 30; | ||
} | ||
|
||
public static final Setting<TimeValue> GLOBAL_CPU_USAGE_AC_POLLING_INTERVAL_SETTING = Setting.positiveTimeSetting( | ||
"node.perf_tracker.global_cpu_usage.polling_interval", | ||
TimeValue.timeValueMillis(Defaults.POLLING_INTERVAL_IN_MILLIS), | ||
Setting.Property.NodeScope | ||
); | ||
public static final Setting<TimeValue> GLOBAL_CPU_USAGE_AC_WINDOW_DURATION_SETTING = Setting.positiveTimeSetting( | ||
"node.perf_tracker.global_cpu_usage.window_duration", | ||
TimeValue.timeValueSeconds(Defaults.WINDOW_DURATION_IN_SECONDS), | ||
//Setting.Property.Dynamic, | ||
Setting.Property.NodeScope | ||
); | ||
|
||
public static final Setting<TimeValue> GLOBAL_JVM_USAGE_AC_POLLING_INTERVAL_SETTING = Setting.positiveTimeSetting( | ||
"node.perf_tracker.global_jvmmp.polling_interval", | ||
TimeValue.timeValueMillis(Defaults.POLLING_INTERVAL_IN_MILLIS), | ||
Setting.Property.NodeScope | ||
); | ||
|
||
public static final Setting<TimeValue> GLOBAL_JVM_USAGE_AC_WINDOW_DURATION_SETTING = Setting.positiveTimeSetting( | ||
"node.perf_tracker.global_jvmmp.window_duration", | ||
TimeValue.timeValueSeconds(Defaults.WINDOW_DURATION_IN_SECONDS), | ||
//Setting.Property.Dynamic, | ||
Setting.Property.NodeScope | ||
); | ||
private volatile TimeValue cpuWindowDuration; | ||
private volatile TimeValue cpuPollingInterval; | ||
private volatile TimeValue memoryWindowDuration; | ||
private volatile TimeValue memoryPollingInterval; | ||
|
||
public PerformanceTrackerSettings(Settings settings, ClusterSettings clusterSettings) { | ||
this.cpuPollingInterval = GLOBAL_CPU_USAGE_AC_POLLING_INTERVAL_SETTING.get(settings); | ||
this.cpuWindowDuration = GLOBAL_CPU_USAGE_AC_WINDOW_DURATION_SETTING.get(settings); | ||
this.memoryPollingInterval = GLOBAL_JVM_USAGE_AC_POLLING_INTERVAL_SETTING.get(settings); | ||
this.memoryWindowDuration = GLOBAL_JVM_USAGE_AC_WINDOW_DURATION_SETTING.get(settings); | ||
|
||
clusterSettings.addSettingsUpdateConsumer(GLOBAL_CPU_USAGE_AC_WINDOW_DURATION_SETTING, this::setCpuWindowDuration); | ||
clusterSettings.addSettingsUpdateConsumer(GLOBAL_JVM_USAGE_AC_WINDOW_DURATION_SETTING, this::setMemoryWindowDuration); | ||
} | ||
|
||
public TimeValue getCpuWindowDuration() { | ||
return this.cpuWindowDuration; | ||
} | ||
|
||
public TimeValue getCpuPollingInterval() { | ||
return cpuPollingInterval; | ||
} | ||
|
||
public TimeValue getMemoryPollingInterval() { | ||
return memoryPollingInterval; | ||
} | ||
|
||
public TimeValue getMemoryWindowDuration() { | ||
return memoryWindowDuration; | ||
} | ||
|
||
public void setCpuWindowDuration(TimeValue cpuWindowDuration) { | ||
this.cpuWindowDuration = cpuWindowDuration; | ||
} | ||
|
||
public void setMemoryWindowDuration(TimeValue memoryWindowDuration) { | ||
this.memoryWindowDuration = memoryWindowDuration; | ||
} | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|