-
Notifications
You must be signed in to change notification settings - Fork 8.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HADOOP-17461. Collect thread-level IOStatistics. (#4352)
This adds a thread-level collector of IOStatistics, IOStatisticsContext, which can be: * Retrieved for a thread and cached for access from other threads. * reset() to record new statistics. * Queried for live statistics through the IOStatisticsSource.getIOStatistics() method. * Queries for a statistics aggregator for use in instrumented classes. * Asked to create a serializable copy in snapshot() The goal is to make it possible for applications with multiple threads performing different work items simultaneously to be able to collect statistics on the individual threads, and so generate aggregate reports on the total work performed for a specific job, query or similar unit of work. Some changes in IOStatistics-gathering classes are needed for this feature * Caching the active context's aggregator in the object's constructor * Updating it in close() Slightly more work is needed in multithreaded code, such as the S3A committers, which collect statistics across all threads used in task and job commit operations. Currently the IOStatisticsContext-aware classes are: * The S3A input stream, output stream and list iterators. * RawLocalFileSystem's input and output streams. * The S3A committers. * The TaskPool class in hadoop-common, which propagates the active context into scheduled worker threads. Collection of statistics in the IOStatisticsContext is disabled process-wide by default until the feature is considered stable. To enable the collection, set the option fs.thread.level.iostatistics.enabled to "true" in core-site.xml; Contributed by Mehakmeet Singh and Steve Loughran
- Loading branch information
Showing
26 changed files
with
1,459 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
...ject/hadoop-common/src/main/java/org/apache/hadoop/fs/statistics/IOStatisticsContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.hadoop.fs.statistics; | ||
|
||
import org.apache.hadoop.fs.statistics.impl.IOStatisticsContextIntegration; | ||
|
||
/** | ||
* An interface defined to capture thread-level IOStatistics by using per | ||
* thread context. | ||
* <p> | ||
* The aggregator should be collected in their constructor by statistics-generating | ||
* classes to obtain the aggregator to update <i>across all threads</i>. | ||
* <p> | ||
* The {@link #snapshot()} call creates a snapshot of the statistics; | ||
* <p> | ||
* The {@link #reset()} call resets the statistics in the context so | ||
* that later snapshots will get the incremental data. | ||
*/ | ||
public interface IOStatisticsContext extends IOStatisticsSource { | ||
|
||
/** | ||
* Get the IOStatisticsAggregator for the context. | ||
* | ||
* @return return the aggregator for the context. | ||
*/ | ||
IOStatisticsAggregator getAggregator(); | ||
|
||
/** | ||
* Capture the snapshot of the context's IOStatistics. | ||
* | ||
* @return IOStatisticsSnapshot for the context. | ||
*/ | ||
IOStatisticsSnapshot snapshot(); | ||
|
||
/** | ||
* Get a unique ID for this context, for logging | ||
* purposes. | ||
* | ||
* @return an ID unique for all contexts in this process. | ||
*/ | ||
long getID(); | ||
|
||
/** | ||
* Reset the context's IOStatistics. | ||
*/ | ||
void reset(); | ||
|
||
/** | ||
* Get the context's IOStatisticsContext. | ||
* | ||
* @return instance of IOStatisticsContext for the context. | ||
*/ | ||
static IOStatisticsContext getCurrentIOStatisticsContext() { | ||
return IOStatisticsContextIntegration.getCurrentIOStatisticsContext(); | ||
} | ||
|
||
/** | ||
* Set the IOStatisticsContext for the current thread. | ||
* @param statisticsContext IOStatistics context instance for the | ||
* current thread. If null, the context is reset. | ||
*/ | ||
static void setThreadIOStatisticsContext( | ||
IOStatisticsContext statisticsContext) { | ||
IOStatisticsContextIntegration.setThreadIOStatisticsContext( | ||
statisticsContext); | ||
} | ||
} |
81 changes: 81 additions & 0 deletions
81
...mmon/src/main/java/org/apache/hadoop/fs/statistics/impl/EmptyIOStatisticsContextImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.hadoop.fs.statistics.impl; | ||
|
||
import org.apache.hadoop.fs.statistics.IOStatistics; | ||
import org.apache.hadoop.fs.statistics.IOStatisticsAggregator; | ||
import org.apache.hadoop.fs.statistics.IOStatisticsContext; | ||
import org.apache.hadoop.fs.statistics.IOStatisticsSnapshot; | ||
|
||
/** | ||
* Empty IOStatistics context which serves no-op for all the operations and | ||
* returns an empty Snapshot if asked. | ||
* | ||
*/ | ||
final class EmptyIOStatisticsContextImpl implements IOStatisticsContext { | ||
|
||
private static final IOStatisticsContext EMPTY_CONTEXT = new EmptyIOStatisticsContextImpl(); | ||
|
||
private EmptyIOStatisticsContextImpl() { | ||
} | ||
|
||
/** | ||
* Create a new empty snapshot. | ||
* A new one is always created for isolation. | ||
* | ||
* @return a statistics snapshot | ||
*/ | ||
@Override | ||
public IOStatisticsSnapshot snapshot() { | ||
return new IOStatisticsSnapshot(); | ||
} | ||
|
||
@Override | ||
public IOStatisticsAggregator getAggregator() { | ||
return EmptyIOStatisticsStore.getInstance(); | ||
} | ||
|
||
@Override | ||
public IOStatistics getIOStatistics() { | ||
return EmptyIOStatistics.getInstance(); | ||
} | ||
|
||
@Override | ||
public void reset() {} | ||
|
||
/** | ||
* The ID is always 0. | ||
* As the real context implementation counter starts at 1, | ||
* we are guaranteed to have unique IDs even between them and | ||
* the empty context. | ||
* @return 0 | ||
*/ | ||
@Override | ||
public long getID() { | ||
return 0; | ||
} | ||
|
||
/** | ||
* Get the single instance. | ||
* @return an instance. | ||
*/ | ||
static IOStatisticsContext getInstance() { | ||
return EMPTY_CONTEXT; | ||
} | ||
} |
Oops, something went wrong.