HADOOP-10688. Expose thread-level FileSystem StatisticsData (Sandy Ryza)

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1602519 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Sanford Ryza 2014-06-13 20:57:41 +00:00
parent 7ce31cc100
commit 9313bbd06e
2 changed files with 29 additions and 7 deletions

View File

@ -80,6 +80,8 @@ Release 2.5.0 - UNRELEASED
HADOOP-10691. Improve the readability of 'hadoop fs -help'. HADOOP-10691. Improve the readability of 'hadoop fs -help'.
(Lei Xu via wang) (Lei Xu via wang)
HADOOP-10688. Expose thread-level FileSystem StatisticsData (Sandy Ryza)
OPTIMIZATIONS OPTIMIZATIONS
BUG FIXES BUG FIXES

View File

@ -2805,7 +2805,7 @@ public abstract class FileSystem extends Configured implements Closeable {
* be perceived as atomic with respect to other threads, which is all we * be perceived as atomic with respect to other threads, which is all we
* need. * need.
*/ */
private static class StatisticsData { public static class StatisticsData {
volatile long bytesRead; volatile long bytesRead;
volatile long bytesWritten; volatile long bytesWritten;
volatile int readOps; volatile int readOps;
@ -2850,6 +2850,26 @@ public abstract class FileSystem extends Configured implements Closeable {
+ readOps + " read ops, " + largeReadOps + " large read ops, " + readOps + " read ops, " + largeReadOps + " large read ops, "
+ writeOps + " write ops"; + writeOps + " write ops";
} }
public long getBytesRead() {
return bytesRead;
}
public long getBytesWritten() {
return bytesWritten;
}
public int getReadOps() {
return readOps;
}
public int getLargeReadOps() {
return largeReadOps;
}
public int getWriteOps() {
return writeOps;
}
} }
private interface StatisticsAggregator<T> { private interface StatisticsAggregator<T> {
@ -2908,7 +2928,7 @@ public abstract class FileSystem extends Configured implements Closeable {
/** /**
* Get or create the thread-local data associated with the current thread. * Get or create the thread-local data associated with the current thread.
*/ */
private StatisticsData getThreadData() { public StatisticsData getThreadStatistics() {
StatisticsData data = threadData.get(); StatisticsData data = threadData.get();
if (data == null) { if (data == null) {
data = new StatisticsData( data = new StatisticsData(
@ -2929,7 +2949,7 @@ public abstract class FileSystem extends Configured implements Closeable {
* @param newBytes the additional bytes read * @param newBytes the additional bytes read
*/ */
public void incrementBytesRead(long newBytes) { public void incrementBytesRead(long newBytes) {
getThreadData().bytesRead += newBytes; getThreadStatistics().bytesRead += newBytes;
} }
/** /**
@ -2937,7 +2957,7 @@ public abstract class FileSystem extends Configured implements Closeable {
* @param newBytes the additional bytes written * @param newBytes the additional bytes written
*/ */
public void incrementBytesWritten(long newBytes) { public void incrementBytesWritten(long newBytes) {
getThreadData().bytesWritten += newBytes; getThreadStatistics().bytesWritten += newBytes;
} }
/** /**
@ -2945,7 +2965,7 @@ public abstract class FileSystem extends Configured implements Closeable {
* @param count number of read operations * @param count number of read operations
*/ */
public void incrementReadOps(int count) { public void incrementReadOps(int count) {
getThreadData().readOps += count; getThreadStatistics().readOps += count;
} }
/** /**
@ -2953,7 +2973,7 @@ public abstract class FileSystem extends Configured implements Closeable {
* @param count number of large read operations * @param count number of large read operations
*/ */
public void incrementLargeReadOps(int count) { public void incrementLargeReadOps(int count) {
getThreadData().largeReadOps += count; getThreadStatistics().largeReadOps += count;
} }
/** /**
@ -2961,7 +2981,7 @@ public abstract class FileSystem extends Configured implements Closeable {
* @param count number of write operations * @param count number of write operations
*/ */
public void incrementWriteOps(int count) { public void incrementWriteOps(int count) {
getThreadData().writeOps += count; getThreadStatistics().writeOps += count;
} }
/** /**