Skip to content

Commit fad1d5a

Browse files
fix yetus
1 parent 1fe8cba commit fad1d5a

File tree

5 files changed

+16
-15
lines changed

5 files changed

+16
-15
lines changed

hadoop-tools/hadoop-azure/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,8 @@
632632
<exclude>**/azurebfs/ITestSmallWriteOptimization.java</exclude>
633633
<exclude>**/azurebfs/ITestAbfsStreamStatistics*.java</exclude>
634634
<exclude>**/azurebfs/services/ITestReadBufferManager.java</exclude>
635+
<exclude>**/azurebfs/WriteThreadPoolSizeManager.java</exclude>
636+
<exclude>**/azurebfs/services/ReadBufferManagerV2.java</exclude>
635637
<exclude>**/azurebfs/commit/*.java</exclude>
636638
</excludes>
637639

@@ -672,6 +674,8 @@
672674
<include>**/azurebfs/extensions/ITestAbfsDelegationTokens.java</include>
673675
<include>**/azurebfs/ITestSmallWriteOptimization.java</include>
674676
<include>**/azurebfs/services/ITestReadBufferManager.java</include>
677+
<include>**/azurebfs/WriteThreadPoolSizeManager.java</include>
678+
<include>**/azurebfs/services/ReadBufferManagerV2.java</include>
675679
<include>**/azurebfs/ITestAbfsStreamStatistics*.java</include>
676680
<include>**/azurebfs/commit/*.java</include>
677681
</includes>

hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/AbfsCountersImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,15 +303,15 @@ public AbfsReadFooterMetrics getAbfsReadFooterMetrics() {
303303
*/
304304
@Override
305305
public AbfsWriteThreadPoolMetrics getAbfsWriteThreadPoolMetrics() {
306-
return abfsWriteThreadPoolMetrics;
306+
return abfsWriteThreadPoolMetrics != null ? abfsWriteThreadPoolMetrics : null;
307307
}
308308

309309
/**
310310
* Returns the read thread pool metrics instance, or {@code null} if uninitialized.
311311
*/
312312
@Override
313313
public AbfsReadThreadPoolMetrics getAbfsReadThreadPoolMetrics() {
314-
return abfsReadThreadPoolMetrics;
314+
return abfsReadThreadPoolMetrics != null ? abfsReadThreadPoolMetrics : null;
315315
}
316316

317317
/**

hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/WriteThreadPoolSizeManager.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
import static org.apache.hadoop.fs.azurebfs.constants.FileSystemConfigurations.BYTES_PER_GIGABYTE;
5050
import static org.apache.hadoop.fs.azurebfs.constants.FileSystemConfigurations.HIGH_CPU_LOW_MEMORY_REDUCTION_FACTOR;
5151
import static org.apache.hadoop.fs.azurebfs.constants.FileSystemConfigurations.HIGH_CPU_REDUCTION_FACTOR;
52-
import static org.apache.hadoop.fs.azurebfs.constants.FileSystemConfigurations.HUNDRED;
5352
import static org.apache.hadoop.fs.azurebfs.constants.FileSystemConfigurations.HUNDRED_D;
5453
import static org.apache.hadoop.fs.azurebfs.constants.FileSystemConfigurations.LOW_CPU_HIGH_MEMORY_DECREASE_FACTOR;
5554
import static org.apache.hadoop.fs.azurebfs.constants.FileSystemConfigurations.LOW_CPU_POOL_SIZE_INCREASE_FACTOR;
@@ -88,17 +87,15 @@ public final class WriteThreadPoolSizeManager implements Closeable {
8887
private final AbfsConfiguration abfsConfiguration;
8988
/* Metrics collector for monitoring the performance of the ABFS write thread pool. */
9089
private final AbfsWriteThreadPoolMetrics writeThreadPoolMetrics;
91-
/* Last recorded CPU time used for computing CPU utilization deltas. */
92-
private static long lastCpuTime = 0;
93-
/* Last recorded system time used for utilization calculations. */
94-
private static long lastTime = 0;
9590
/* Flag indicating if CPU monitoring has started. */
9691
private volatile boolean isMonitoringStarted = false;
9792
/* Tracks the last scale direction applied, or empty if none. */
9893
private volatile String lastScaleDirection = EMPTY_STRING;
9994
/* Maximum CPU utilization observed during the monitoring interval. */
10095
private volatile double maxCpuUtilization = 0.0;
96+
/** High memory usage threshold used to trigger thread pool downscaling. */
10197
private final double highMemoryThreshold;
98+
/** Low memory usage threshold used to allow thread pool upscaling. */
10299
private final double lowMemoryThreshold;
103100

104101
/**
@@ -351,14 +348,15 @@ public double getJvmCpuLoad() {
351348
double getMemoryLoad() {
352349
MemoryMXBean osBean = ManagementFactory.getMemoryMXBean();
353350
MemoryUsage memoryUsage = osBean.getHeapMemoryUsage();
354-
return (double) memoryUsage.getUsed() / memoryUsage.getCommitted();
351+
return (double) memoryUsage.getUsed() / memoryUsage.getMax();
355352
}
356353

357354
/**
358355
* Dynamically adjusts the thread pool size based on current CPU utilization
359356
* and available heap memory relative to the initially available heap.
360357
*
361358
* @param cpuUtilization Current system CPU utilization (0.0 to 1.0)
359+
* @throws InterruptedException if the resizing operation is interrupted while acquiring the lock
362360
*/
363361
public void adjustThreadPoolSizeBasedOnCPU(double cpuUtilization) throws InterruptedException {
364362
lock.lock();
@@ -367,7 +365,6 @@ public void adjustThreadPoolSizeBasedOnCPU(double cpuUtilization) throws Interru
367365
int currentPoolSize = executor.getMaximumPoolSize();
368366
double memoryLoad = getMemoryLoad();
369367
LOG.debug("Current CPU Utilization: {}", cpuUtilization);
370-
371368
if (cpuUtilization > (abfsConfiguration.getWriteHighCpuThreshold()/HUNDRED_D)) {
372369
newMaxPoolSize = calculateReducedPoolSizeHighCPU(currentPoolSize, memoryLoad);
373370
} else if (cpuUtilization > (abfsConfiguration.getWriteMediumCpuThreshold()/HUNDRED_D)) {
@@ -737,7 +734,7 @@ synchronized WriteThreadPoolStats getCurrentStats(
737734
getSystemCpuUtilization(), // System CPU usage (ratio)
738735
getAvailableHeapMemory(), // Free heap (GB)
739736
getCommittedHeapMemory(), // Committed heap (GB)
740-
memoryLoad, // used/committed
737+
memoryLoad, // used/max
741738
currentScaleDirection, // "I", "D", or ""
742739
maxCpuUtilization // Peak JVM CPU usage so far
743740
);

hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/AbfsReadThreadPoolMetrics.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929

3030
import org.apache.hadoop.fs.azurebfs.constants.FSOperationType;
3131
import org.apache.hadoop.fs.azurebfs.enums.AbfsReadThreadPoolMetricsEnum;
32-
import org.apache.hadoop.fs.azurebfs.enums.AbfsWriteThreadPoolMetricsEnum;
3332
import org.apache.hadoop.fs.azurebfs.enums.StatisticTypeEnum;
3433
import org.apache.hadoop.fs.statistics.impl.IOStatisticsStore;
3534

@@ -131,8 +130,9 @@ public synchronized void update(ReadBufferManagerV2.ReadThreadPoolStats stats) {
131130
}
132131

133132
/**
134-
* Returns a flag indicating whether the metrics have been updated at least once.
135-
* Used to verify if metric updates have occurred since initialization.
133+
* Indicates whether the metrics have been updated at least once since initialization.
134+
*
135+
* @return {@code true} if an update has occurred, {@code false} otherwise
136136
*/
137137
public boolean getUpdatedAtLeastOnce() {
138138
return updatedAtLeastOnce.get();

hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/ReadBufferManagerV2.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,7 +1050,7 @@ private void printDebugLog(String message, Object... args) {
10501050
double getMemoryLoad() {
10511051
MemoryMXBean osBean = ManagementFactory.getMemoryMXBean();
10521052
MemoryUsage memoryUsage = osBean.getHeapMemoryUsage();
1053-
return (double) memoryUsage.getUsed() / memoryUsage.getCommitted();
1053+
return (double) memoryUsage.getUsed() / memoryUsage.getMax();
10541054
}
10551055

10561056
/**
@@ -1376,7 +1376,7 @@ synchronized ReadThreadPoolStats getCurrentStats(double jvmCpuLoad, double maxCp
13761376
getSystemCpuLoad(), // System CPU usage (ratio)
13771377
getAvailableHeapMemory(), // Free heap (GB)
13781378
getCommittedHeapMemory(), // Committed heap (GB)
1379-
getMemoryLoad(), // used/committed
1379+
getMemoryLoad(), // used/max
13801380
currentScaleDirection, // "I", "D", or ""
13811381
maxCpuUtilization // Peak JVM CPU usage so far
13821382
);

0 commit comments

Comments
 (0)