anmolanmol1234 commented on code in PR #8056:
URL: https://github.com/apache/hadoop/pull/8056#discussion_r2556342075


##########
hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/ReadBufferManagerV2.java:
##########
@@ -831,41 +861,79 @@ private boolean manualEviction(final ReadBuffer buf) {
    */
   private void adjustThreadPool() {
     int currentPoolSize = workerRefs.size();
-    double cpuLoad = getCpuLoad();
+    double cpuLoad = getJvmCpuLoad();
+    if (cpuLoad > maxCpuUtilization) {
+      maxCpuUtilization = cpuLoad;
+    }
     int requiredPoolSize = getRequiredThreadPoolSize();
     int newThreadPoolSize;
     printTraceLog(
         "Current CPU load: {}, Current worker pool size: {}, Current queue 
size: {}",
         cpuLoad, currentPoolSize, requiredPoolSize);
     if (currentPoolSize < requiredPoolSize && cpuLoad < cpuThreshold) {
+      lastScaleDirection = "I";
       // Submit more background tasks.
       newThreadPoolSize = Math.min(maxThreadPoolSize,
           (int) Math.ceil(
               (currentPoolSize * (HUNDRED_D + threadPoolUpscalePercentage))
                   / HUNDRED_D));
+      if (newThreadPoolSize == maxThreadPoolSize) {

Review Comment:
   taken



##########
hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/ReadBufferManagerV2.java:
##########
@@ -831,41 +861,79 @@ private boolean manualEviction(final ReadBuffer buf) {
    */
   private void adjustThreadPool() {
     int currentPoolSize = workerRefs.size();
-    double cpuLoad = getCpuLoad();
+    double cpuLoad = getJvmCpuLoad();
+    if (cpuLoad > maxCpuUtilization) {
+      maxCpuUtilization = cpuLoad;
+    }
     int requiredPoolSize = getRequiredThreadPoolSize();
     int newThreadPoolSize;
     printTraceLog(
         "Current CPU load: {}, Current worker pool size: {}, Current queue 
size: {}",
         cpuLoad, currentPoolSize, requiredPoolSize);
     if (currentPoolSize < requiredPoolSize && cpuLoad < cpuThreshold) {
+      lastScaleDirection = "I";
       // Submit more background tasks.
       newThreadPoolSize = Math.min(maxThreadPoolSize,
           (int) Math.ceil(
               (currentPoolSize * (HUNDRED_D + threadPoolUpscalePercentage))
                   / HUNDRED_D));
+      if (newThreadPoolSize == maxThreadPoolSize) {
+        lastScaleDirection = "+F";   // Already full, cannot scale up
+      } else {
+        lastScaleDirection = "I";    // Normal scale-up
+      }
       // Create new Worker Threads
-      for (int i = currentPoolSize; i < newThreadPoolSize; i++) {
-        ReadBufferWorker worker = new ReadBufferWorker(i, getBufferManager());
-        workerRefs.add(worker);
-        workerPool.submit(worker);
+      if ("I".equals(lastScaleDirection)) {
+        for (int i = currentPoolSize; i < newThreadPoolSize; i++) {
+          ReadBufferWorker worker = new ReadBufferWorker(i,
+              getBufferManager(abfsClient));
+          workerRefs.add(worker);
+          workerPool.submit(worker);
+        }
       }
+      // Capture the latest thread pool statistics (pool size, CPU, memory, 
etc.)
+      ReadThreadPoolStats stats = getCurrentStats(cpuLoad, maxCpuUtilization);
+      // Update the read thread pool metrics with the latest statistics 
snapshot.
+      readThreadPoolMetrics.update(stats);
       printTraceLog("Increased worker pool size from {} to {}", 
currentPoolSize,
           newThreadPoolSize);
+    } else if (cpuLoad < cpuThreshold && currentPoolSize > requiredPoolSize) {
+      lastScaleDirection = "NA";
+      // Capture the latest thread pool statistics (pool size, CPU, memory, 
etc.)
+      ReadThreadPoolStats stats = getCurrentStats(cpuLoad, maxCpuUtilization);
+      // Update the read thread pool metrics with the latest statistics 
snapshot.
+      readThreadPoolMetrics.update(stats);
     } else if (cpuLoad > cpuThreshold || currentPoolSize > requiredPoolSize) {
       newThreadPoolSize = Math.max(minThreadPoolSize,
           (int) Math.ceil(
               (currentPoolSize * (HUNDRED_D - threadPoolDownscalePercentage))
                   / HUNDRED_D));
-      // Signal the extra workers to stop
-      while (workerRefs.size() > newThreadPoolSize) {
-        ReadBufferWorker worker = workerRefs.remove(workerRefs.size() - 1);
-        worker.stop();
+      if (newThreadPoolSize == minThreadPoolSize) {

Review Comment:
   taken



-- 
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