Skip to content

Commit b00ea94

Browse files
author
Ravindra Dingankar
committed
change transfer unit to bytes per second
1 parent 34a14fc commit b00ea94

File tree

6 files changed

+30
-22
lines changed

6 files changed

+30
-22
lines changed

hadoop-common-project/hadoop-common/src/site/markdown/Metrics.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -370,9 +370,9 @@ Each metrics record contains tags such as SessionId and Hostname as additional i
370370
|:---- |:---- |
371371
| `BytesWritten` | Total number of bytes written to DataNode |
372372
| `BytesRead` | Total number of bytes read from DataNode |
373-
| `ReadTransferRateMBsNumOps` | Total number of data read transfers |
374-
| `ReadTransferRateMBsAvgTime` | Average transfer rate of bytes read from DataNode. |
375-
| `ReadTransferRateMBs`*num*`s(50/75/90/95/99)thPercentileRate` | The 50/75/90/95/99th percentile of the transfer rate of bytes read from DataNode, measured in megabytes per second. |
373+
| `ReadTransferRateNumOps` | Total number of data read transfers |
374+
| `ReadTransferRateAvgTime` | Average transfer rate of bytes read from DataNode, measured in bytes per second. |
375+
| `ReadTransferRate`*num*`s(50/75/90/95/99)thPercentileRate` | The 50/75/90/95/99th percentile of the transfer rate of bytes read from DataNode, measured in bytes per second. |
376376
| `BlocksWritten` | Total number of blocks written to DataNode |
377377
| `BlocksRead` | Total number of blocks read from DataNode |
378378
| `BlocksReplicated` | Total number of blocks replicated |

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSUtil.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1938,18 +1938,18 @@ public static boolean isParentEntry(final String path, final String parent) {
19381938
}
19391939

19401940
/**
1941-
* Calculate the transfer rate in megabytes/second. Return -1 for any negative input.
1941+
* Calculate the transfer rate in bytes/second. Return -1 for any negative input.
19421942
* @param bytes bytes
19431943
* @param durationMS duration in milliseconds
1944-
* @return the number of megabytes/second of the transfer rate
1944+
* @return the number of bytes/second of the transfer rate
19451945
*/
1946-
public static long transferRateMBs(long bytes, long durationMS) {
1946+
public static long transferRateBytesPerSecond(long bytes, long durationMS) {
19471947
if (bytes < 0 || durationMS < 0) {
19481948
return -1;
19491949
}
19501950
if (durationMS == 0) {
19511951
durationMS = 1;
19521952
}
1953-
return bytes / (1024 * 1024) * 1000 / durationMS;
1953+
return bytes * 1000 / durationMS;
19541954
}
19551955
}

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DataXceiver.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ public void readBlock(final ExtendedBlock block,
633633
datanode.metrics.incrBytesRead((int) read);
634634
datanode.metrics.incrBlocksRead();
635635
datanode.metrics.incrTotalReadTime(duration);
636-
datanode.metrics.addReadTransferRateMBs(DFSUtil.transferRateMBs(read, duration));
636+
datanode.metrics.addReadTransferRate(DFSUtil.transferRateBytesPerSecond(read, duration));
637637
} catch ( SocketException ignored ) {
638638
LOG.trace("{}:Ignoring exception while serving {} to {}",
639639
dnR, block, remoteAddress, ignored);
@@ -1124,7 +1124,7 @@ public void copyBlock(final ExtendedBlock block,
11241124
datanode.metrics.incrBytesRead((int) read);
11251125
datanode.metrics.incrBlocksRead();
11261126
datanode.metrics.incrTotalReadTime(duration);
1127-
datanode.metrics.addReadTransferRateMBs(DFSUtil.transferRateMBs(read, duration));
1127+
datanode.metrics.addReadTransferRate(DFSUtil.transferRateBytesPerSecond(read, duration));
11281128

11291129
LOG.info("Copied {} to {}", block, peer.getRemoteAddressString());
11301130
} catch (IOException ioe) {

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/metrics/DataNodeMetrics.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ public class DataNodeMetrics {
6161
@Metric MutableCounterLong bytesRead;
6262
@Metric("Milliseconds spent reading")
6363
MutableCounterLong totalReadTime;
64-
@Metric private MutableRate readTransferRateMBs;
65-
final private MutableQuantiles[] readTransferRateMBsQuantiles;
64+
@Metric private MutableRate readTransferRate;
65+
final private MutableQuantiles[] readTransferRateQuantiles;
6666
@Metric MutableCounterLong blocksWritten;
6767
@Metric MutableCounterLong blocksRead;
6868
@Metric MutableCounterLong blocksReplicated;
@@ -229,7 +229,7 @@ public DataNodeMetrics(String name, String sessionId, int[] intervals,
229229
sendDataPacketTransferNanosQuantiles = new MutableQuantiles[len];
230230
ramDiskBlocksEvictionWindowMsQuantiles = new MutableQuantiles[len];
231231
ramDiskBlocksLazyPersistWindowMsQuantiles = new MutableQuantiles[len];
232-
readTransferRateMBsQuantiles = new MutableQuantiles[len];
232+
readTransferRateQuantiles = new MutableQuantiles[len];
233233

234234
for (int i = 0; i < len; i++) {
235235
int interval = intervals[i];
@@ -258,9 +258,9 @@ public DataNodeMetrics(String name, String sessionId, int[] intervals,
258258
"ramDiskBlocksLazyPersistWindows" + interval + "s",
259259
"Time between the RamDisk block write and disk persist in ms",
260260
"ops", "latency", interval);
261-
readTransferRateMBsQuantiles[i] = registry.newQuantiles(
262-
"readTransferRateMBs" + interval + "s",
263-
"Rate at which bytes are read from datanode calculated in megabytes per second",
261+
readTransferRateQuantiles[i] = registry.newQuantiles(
262+
"readTransferRate" + interval + "s",
263+
"Rate at which bytes are read from datanode calculated in bytes per second",
264264
"ops", "rate", interval);
265265
}
266266
}
@@ -323,10 +323,10 @@ public void addIncrementalBlockReport(long latency,
323323
}
324324
}
325325

326-
public void addReadTransferRateMBs(long transferRateMBs) {
327-
readTransferRateMBs.add(transferRateMBs);
328-
for (MutableQuantiles q : readTransferRateMBsQuantiles) {
329-
q.add(transferRateMBs);
326+
public void addReadTransferRate(long readTransferRate) {
327+
this.readTransferRate.add(readTransferRate);
328+
for (MutableQuantiles q : readTransferRateQuantiles) {
329+
q.add(readTransferRate);
330330
}
331331
}
332332

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSUtil.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,4 +1108,12 @@ public void testErrorMessageForInvalidNameservice() throws Exception {
11081108
LambdaTestUtils.intercept(IOException.class, expectedErrorMessage,
11091109
()->DFSUtil.getNNServiceRpcAddressesForCluster(conf));
11101110
}
1111+
1112+
@Test
1113+
public void testTransferRateBytesPerSecond() {
1114+
assertEquals(9830, DFSUtil.transferRateBytesPerSecond(983, 100));
1115+
assertEquals(983000, DFSUtil.transferRateBytesPerSecond(983, 0));
1116+
assertEquals(-1, DFSUtil.transferRateBytesPerSecond(-983, 100));
1117+
assertEquals(-1, DFSUtil.transferRateBytesPerSecond(983, -100));
1118+
}
11111119
}

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDataNodeMetrics.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ public void testDataNodeTimeSpend() throws Exception {
392392

393393
final long startWriteValue = getLongCounter("TotalWriteTime", rb);
394394
final long startReadValue = getLongCounter("TotalReadTime", rb);
395-
assertCounter("ReadTransferRateMBsNumOps", 0L, rb);
395+
assertCounter("ReadTransferRateNumOps", 0L, rb);
396396
final AtomicInteger x = new AtomicInteger(0);
397397

398398
// Lets Metric system update latest metrics
@@ -412,8 +412,8 @@ public Boolean get() {
412412
MetricsRecordBuilder rbNew = getMetrics(datanode.getMetrics().name());
413413
final long endWriteValue = getLongCounter("TotalWriteTime", rbNew);
414414
final long endReadValue = getLongCounter("TotalReadTime", rbNew);
415-
assertCounter("ReadTransferRateMBsNumOps", 1L, rbNew);
416-
assertQuantileGauges("ReadTransferRateMBs" + "60s", rbNew, "Rate");
415+
assertCounter("ReadTransferRateNumOps", 1L, rbNew);
416+
assertQuantileGauges("ReadTransferRate" + "60s", rbNew, "Rate");
417417
return endWriteValue > startWriteValue
418418
&& endReadValue > startReadValue;
419419
}

0 commit comments

Comments
 (0)