kfaraz commented on code in PR #16691:
URL: https://github.com/apache/druid/pull/16691#discussion_r1668847707


##########
server/src/main/java/org/apache/druid/server/coordinator/loading/LoadingRateTracker.java:
##########
@@ -0,0 +1,118 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.druid.server.coordinator.loading;
+
+import com.google.common.collect.EvictingQueue;
+
+import javax.annotation.concurrent.ThreadSafe;
+import java.util.concurrent.atomic.AtomicReference;
+
+/**
+ * Tracks the current segment loading rate for a single server.
+ * <p>
+ * The loading rate is computed as a moving average of the last
+ * {@link #MOVING_AVERAGE_WINDOW_SIZE} progress updates (or more if any of the
+ * updates was smaller than {@link #MIN_ENTRY_SIZE_BYTES}).
+ */
+@ThreadSafe
+public class LoadingRateTracker
+{
+  public static final int MOVING_AVERAGE_WINDOW_SIZE = 10;
+  public static final long MIN_ENTRY_SIZE_BYTES = 1_000_000_000;
+
+  private final EvictingQueue<Entry> window = 
EvictingQueue.create(MOVING_AVERAGE_WINDOW_SIZE);
+  private final AtomicReference<Entry> windowTotal = new AtomicReference<>(new 
Entry());
+  private Entry currentTail;
+
+  public synchronized void updateProgress(long bytes, long millisElapsed)
+  {
+    if (bytes >= 0 && millisElapsed > 0) {

Review Comment:
   ```suggestion
       if (bytes > 0 && millisElapsed > 0) {
   ```



##########
server/src/main/java/org/apache/druid/server/coordinator/loading/LoadingRateTracker.java:
##########
@@ -0,0 +1,118 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.druid.server.coordinator.loading;
+
+import com.google.common.collect.EvictingQueue;
+
+import javax.annotation.concurrent.ThreadSafe;
+import java.util.concurrent.atomic.AtomicReference;
+
+/**
+ * Tracks the current segment loading rate for a single server.
+ * <p>
+ * The loading rate is computed as a moving average of the last
+ * {@link #MOVING_AVERAGE_WINDOW_SIZE} progress updates (or more if any of the
+ * updates was smaller than {@link #MIN_ENTRY_SIZE_BYTES}).
+ */
+@ThreadSafe
+public class LoadingRateTracker
+{
+  public static final int MOVING_AVERAGE_WINDOW_SIZE = 10;
+  public static final long MIN_ENTRY_SIZE_BYTES = 1_000_000_000;
+
+  private final EvictingQueue<Entry> window = 
EvictingQueue.create(MOVING_AVERAGE_WINDOW_SIZE);
+  private final AtomicReference<Entry> windowTotal = new AtomicReference<>(new 
Entry());
+  private Entry currentTail;
+
+  public synchronized void updateProgress(long bytes, long millisElapsed)
+  {
+    if (bytes >= 0 && millisElapsed > 0) {

Review Comment:
   Yeah, I think that would be fair.
   
   Although, I am not sure about tombstone segments. They would have size zero 
but it would still take non-zero time to load time. I guess in that case it 
would make sense to account for the time in the overall window average.
   
   Let me know what you think.



##########
server/src/main/java/org/apache/druid/server/http/CoordinatorResource.java:
##########
@@ -111,14 +111,23 @@ public Response getLoadQueue(
       return Response.ok(
           Maps.transformValues(
               coordinator.getLoadManagementPeons(),
-              input -> {
-                long loadSize = input.getSizeOfSegmentsToLoad();
-                long dropSize = 
input.getSegmentsToDrop().stream().mapToLong(DataSegment::getSize).sum();
+              peon -> {
+                long loadSize = peon.getSizeOfSegmentsToLoad();
+                long dropSize = 
peon.getSegmentsToDrop().stream().mapToLong(DataSegment::getSize).sum();
+
+                // 1 kbps = 1/8 kB/s = 1/8 B/ms
+                long loadRateKbps = peon.getLoadRateKbps();
+                long expectedLoadTimeMillis
+                    = loadRateKbps > 0 && loadSize > 0
+                      ? (8 * loadSize) / loadRateKbps
+                      : 0;
+
                 return new ImmutableMap.Builder<>()
-                    .put("segmentsToLoad", input.getSegmentsToLoad().size())
-                    .put("segmentsToDrop", input.getSegmentsToDrop().size())
+                    .put("segmentsToLoad", peon.getSegmentsToLoad().size())
+                    .put("segmentsToDrop", peon.getSegmentsToDrop().size())
                     .put("segmentsToLoadSize", loadSize)
                     .put("segmentsToDropSize", dropSize)
+                    .put("expectedLoadTimeMillis", expectedLoadTimeMillis)
                     .build();
               }

Review Comment:
   Actually, the `full` mode is currently broken. It just returns the entire 
`LoadQueuePeon` object in the response.
   `CuratorLoadQueuePeon` had some `@JsonProperty` fields that were serialized 
out into the response.
   But `HttpLoadQueuePeon` has never had any `@JsonProperty` fields since it 
was first written, so we just get an empty object in the response of the API 
`/druid/v1/coordinator/loadQueue?full`.
   
   Since no one has ever reported this issue, I assume no one is using it (the 
web-console certainly doesn't use it).
   I will create a separate PR to either fix it or just get rid of it 
completely.



##########
server/src/main/java/org/apache/druid/server/coordinator/loading/HttpLoadQueuePeon.java:
##########
@@ -542,6 +557,24 @@ private void onRequestCompleted(SegmentHolder holder, 
RequestStatus status)
     executeCallbacks(holder, status == RequestStatus.SUCCESS);
   }
 
+  @GuardedBy("lock")
+  private void updateLoadProgress(
+      List<DataSegmentChangeResponse> responses,
+      long requestCompleteTimeMillis
+  )
+  {
+    final long loadSize =
+        responses.stream()
+                 .filter(response -> response.getStatus().getState() == 
SegmentChangeStatus.State.SUCCESS)
+                 .map(DataSegmentChangeResponse::getRequest)
+                 .filter(req -> req instanceof SegmentChangeRequestLoad)

Review Comment:
   I did consider this, but it is not really going to be useful because:
   - DROP actions rarely spend time in the queue. This is because DROPs are 
always prioritized over LOADs and are executed immediately.
   - For a DROP action, rate in kbps is not very meaningful since the size of 
the segment doesn't exactly play a role in the time taken to delete the file 
from disk. I guess we would have to track drops per second, but that doesn't 
have any physical significance.



##########
server/src/main/java/org/apache/druid/server/coordinator/loading/LoadingRateTracker.java:
##########
@@ -0,0 +1,118 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.druid.server.coordinator.loading;
+
+import com.google.common.collect.EvictingQueue;
+
+import javax.annotation.concurrent.ThreadSafe;
+import java.util.concurrent.atomic.AtomicReference;
+
+/**
+ * Tracks the current segment loading rate for a single server.
+ * <p>
+ * The loading rate is computed as a moving average of the last
+ * {@link #MOVING_AVERAGE_WINDOW_SIZE} progress updates (or more if any of the
+ * updates was smaller than {@link #MIN_ENTRY_SIZE_BYTES}).
+ */
+@ThreadSafe
+public class LoadingRateTracker
+{
+  public static final int MOVING_AVERAGE_WINDOW_SIZE = 10;
+  public static final long MIN_ENTRY_SIZE_BYTES = 1_000_000_000;
+
+  private final EvictingQueue<Entry> window = 
EvictingQueue.create(MOVING_AVERAGE_WINDOW_SIZE);
+  private final AtomicReference<Entry> windowTotal = new AtomicReference<>(new 
Entry());
+  private Entry currentTail;
+
+  public synchronized void updateProgress(long bytes, long millisElapsed)
+  {
+    if (bytes >= 0 && millisElapsed > 0) {
+      final Entry updatedTotal = new Entry();
+      final Entry currentTotal = windowTotal.get();
+      if (currentTotal != null) {
+        updatedTotal.increment(currentTotal.bytes, currentTotal.millisElapsed);
+      }
+
+      updatedTotal.increment(bytes, millisElapsed);
+
+      final Entry evictedHead = addToTail(bytes, millisElapsed);
+      if (evictedHead != null) {
+        updatedTotal.increment(-evictedHead.bytes, -evictedHead.millisElapsed);
+      }
+
+      if (updatedTotal.bytes > 0 && updatedTotal.millisElapsed > 0) {
+        windowTotal.set(updatedTotal);
+      }

Review Comment:
   ```suggestion
         windowTotal.set(updatedTotal);
   ```



##########
server/src/main/java/org/apache/druid/server/coordinator/loading/HttpLoadQueuePeon.java:
##########
@@ -542,6 +557,24 @@ private void onRequestCompleted(SegmentHolder holder, 
RequestStatus status)
     executeCallbacks(holder, status == RequestStatus.SUCCESS);
   }
 
+  @GuardedBy("lock")
+  private void updateLoadProgress(
+      List<DataSegmentChangeResponse> responses,
+      long requestCompleteTimeMillis
+  )
+  {
+    final long loadSize =
+        responses.stream()
+                 .filter(response -> response.getStatus().getState() == 
SegmentChangeStatus.State.SUCCESS)
+                 .map(DataSegmentChangeResponse::getRequest)

Review Comment:
   Sure, we can make that change.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to