Skip to content

Commit a87a7c4

Browse files
committed
comments
1 parent 5228abd commit a87a7c4

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

server/src/main/java/org/elasticsearch/common/util/concurrent/EsExecutors.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,7 @@ public Builder() {}
632632

633633
public Builder trackExecutionTime(double alpha) {
634634
trackExecutionTime = true;
635+
trackUtilization = true;
635636
ewmaAlpha = alpha;
636637
return this;
637638
}

server/src/main/java/org/elasticsearch/common/util/concurrent/TaskExecutionTimeTrackingEsThreadPoolExecutor.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public TaskTrackingConfig trackingConfig() {
153153
/**
154154
* Returns thread-pool utilization from last completed time interval(frame) {@link TaskTrackingConfig#utilizationInterval()}.
155155
* Utilization is measured as {@code all-threads-total-execution-time / (total-thread-count * interval)}.
156-
* This metric is updated once on per interval, and returns last completed measurement. For example:
156+
* This metric is updated once per interval, and returns last completed measurement. For example:
157157
* if interval is 30 seconds, at clock time 00:30-01:00 it will return utilization from 00:00-00:30.
158158
* Thou there is no synchronization with clocks and system time.
159159
*
@@ -283,11 +283,15 @@ synchronized void updateFrame() {
283283
}
284284

285285
/**
286-
* Update frames to current time. When it's called first time or after a long period (>> interval) current and previous frames
287-
* are going to be stale. But we know all ongoing tasks and can assume they still running, unless explicitly ended. For any
288-
* ongoing task we always assume they will run indefinitely and apply "credit" to currentTime, if task is finished in
289-
* currentFrame we deduct remaining balance. That means currentFrame can overestimate usage, but when current decay to previous
290-
* it is always accurate, because task can end only in currentFrame.
286+
* Update frames to current time. There are no guaranties that it will be invoked frequently.
287+
* For example when there are no tasks and no requests for previousFrameTime.
288+
*
289+
* When it's invoked frequently, at least once per frame, we move currentTime into previousTime.
290+
* That concludes currentTime and it's accurate.
291+
*
292+
* When it's invoked infrequently, once in multiple frames, current and previous frames are going to be stale.
293+
* Which is ok, that means there were no changes in tasks(start/end), all ongoing tasks are still running.
294+
* That means ongoing tasks fully utilized previous frames. And we can accurately tell previous frame usage.
291295
*/
292296
private void updateFrame0(long nowTime) {
293297
var now = nowTime / interval;
@@ -319,11 +323,13 @@ synchronized void startTask() {
319323
synchronized void endTask() {
320324
var now = timeNow.get();
321325
updateFrame0(now);
322-
// we already assumed that task will run till end of interval, here we subtract whats left
323326
currentTime -= (currentFrame + 1) * interval - now;
324327
--ongoingTasks;
325328
}
326329

330+
/**
331+
* Returns previous frame total execution time.
332+
*/
327333
synchronized long previousFrameTime() {
328334
updateFrame0(timeNow.get());
329335
return previousTime;

server/src/main/java/org/elasticsearch/threadpool/DefaultBuiltInExecutorBuilders.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ public Map<String, ExecutorBuilder> getBuilders(Settings settings, int allocated
6161
.trackOngoingTasks()
6262
.trackMaxQueueLatency()
6363
.trackExecutionTime(indexAutoscalingEWMA)
64-
.trackUtilization(Duration.ofSeconds(30))
6564
.build()
6665
)
6766
);

0 commit comments

Comments
 (0)