Skip to content

Commit

Permalink
Add hdfs stats for local and remote rack bytes read (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
bbeaudreault authored Apr 19, 2024
1 parent 6c01d85 commit 9a3d0b3
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,12 @@ public interface MetricsRegionServerSource extends BaseSource, JvmPauseMonitorSo
String ZEROCOPY_BYTES_READ = "zeroCopyBytesRead";
String ZEROCOPY_BYTES_READ_DESC = "The number of bytes read through HDFS zero copy";

String LOCAL_RACK_BYTES_READ = "localRackBytesRead";
String LOCAL_RACK_BYTES_READ_DESC = "The number of bytes read from the same rack of the RegionServer, but not the local HDFS DataNode";

String REMOTE_RACK_BYTES_READ = "remoteRackBytesRead";
String REMOTE_RACK_BYTES_READ_DESC = "The number of bytes read from a different rack from that of the RegionServer";

String BLOCKED_REQUESTS_COUNT = "blockedRequestCount";
String BLOCKED_REQUESTS_COUNT_DESC = "The number of blocked requests because of memstore size is "
+ "larger than blockingMemStoreSize";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,10 @@ public interface MetricsRegionServerWrapper {
/** Returns Number of bytes read from the local HDFS DataNode. */
long getLocalBytesRead();

long getLocalRackBytesRead();

long getRemoteRackBytesRead();

/** Returns Number of bytes read locally through HDFS short circuit. */
long getShortCircuitBytesRead();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,8 @@ private MetricsRecordBuilder addGaugesToMetricsRecordBuilder(MetricsRecordBuilde
PERCENT_FILES_LOCAL_SECONDARY_REGIONS_DESC), rsWrap.getPercentFileLocalSecondaryRegions())
.addGauge(Interns.info(TOTAL_BYTES_READ, TOTAL_BYTES_READ_DESC), rsWrap.getTotalBytesRead())
.addGauge(Interns.info(LOCAL_BYTES_READ, LOCAL_BYTES_READ_DESC), rsWrap.getLocalBytesRead())
.addGauge(Interns.info(LOCAL_RACK_BYTES_READ, LOCAL_RACK_BYTES_READ_DESC), rsWrap.getLocalRackBytesRead())
.addGauge(Interns.info(REMOTE_RACK_BYTES_READ, REMOTE_RACK_BYTES_READ_DESC), rsWrap.getRemoteRackBytesRead())
.addGauge(Interns.info(SHORTCIRCUIT_BYTES_READ, SHORTCIRCUIT_BYTES_READ_DESC),
rsWrap.getShortCircuitBytesRead())
.addGauge(Interns.info(ZEROCOPY_BYTES_READ, ZEROCOPY_BYTES_READ_DESC),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import org.apache.commons.lang3.StringUtils;
import org.apache.hadoop.fs.GlobalStorageStatistics;
import org.apache.hadoop.fs.StorageStatistics;
import org.apache.hadoop.hbase.CompatibilitySingletonFactory;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.HDFSBlocksDistribution;
Expand Down Expand Up @@ -1037,6 +1039,29 @@ public long getLocalBytesRead() {
return FSDataInputStreamWrapper.getLocalBytesRead();
}

@Override
public long getLocalRackBytesRead() {
return getGlobalStorageStatistic("bytesReadDistanceOfOneOrTwo");
}

@Override
public long getRemoteRackBytesRead() {
return getGlobalStorageStatistic("bytesReadDistanceOfThreeOrFour")
+ getGlobalStorageStatistic("bytesReadDistanceOfFiveOrLarger");
}

private static long getGlobalStorageStatistic(String name) {
StorageStatistics stats = GlobalStorageStatistics.INSTANCE.get("hdfs");
if (stats == null) {
return 0;
}
Long val = stats.getLong(name);
if (val == null) {
return 0;
}
return val;
}

@Override
public long getShortCircuitBytesRead() {
return FSDataInputStreamWrapper.getShortCircuitBytesRead();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,16 @@ public long getLocalBytesRead() {
return 0;
}

@Override
public long getLocalRackBytesRead() {
return 0;
}

@Override
public long getRemoteRackBytesRead() {
return 0;
}

@Override
public long getShortCircuitBytesRead() {
return 0;
Expand Down

0 comments on commit 9a3d0b3

Please sign in to comment.