-
Notifications
You must be signed in to change notification settings - Fork 443
TEZ-4466: Measure exact stream read time while fetching #530
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| /* | ||
| * 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.tez.http; | ||
|
|
||
| import java.io.DataInputStream; | ||
| import java.io.FilterInputStream; | ||
| import java.io.IOException; | ||
| import java.io.InputStream; | ||
| import java.util.concurrent.TimeUnit; | ||
|
|
||
| public class MeasuredDataInputStream extends DataInputStream { | ||
|
|
||
| private final MeasuredInputStream measuredIn; | ||
|
|
||
| private MeasuredDataInputStream(MeasuredInputStream measuredIn) { | ||
| super(measuredIn); | ||
| this.measuredIn = measuredIn; | ||
| } | ||
|
|
||
| public MeasuredDataInputStream(InputStream in) { | ||
| this(new MeasuredInputStream(in)); | ||
| } | ||
|
|
||
| public long getElapsedTimeMs() { | ||
| return measuredIn.getElapsedTimeMs(); | ||
| } | ||
|
|
||
| public long getBytesRead() { | ||
| return measuredIn.getBytesRead(); | ||
| } | ||
|
|
||
| private static class MeasuredInputStream extends FilterInputStream { | ||
| private long elapsedTimeNanos = 0; | ||
| private long bytesRead = 0; | ||
|
|
||
| MeasuredInputStream(InputStream in) { | ||
| super(in); | ||
| } | ||
|
|
||
| @Override | ||
| public int read() throws IOException { | ||
| long start = System.nanoTime(); | ||
| int val = super.read(); | ||
| elapsedTimeNanos += (System.nanoTime() - start); | ||
| if (val != -1) { | ||
| bytesRead += 1; | ||
| } | ||
| return val; | ||
| } | ||
|
|
||
| @Override | ||
| public int read(byte[] b) throws IOException { | ||
| long start = System.nanoTime(); | ||
| int bytes = super.read(b); | ||
| elapsedTimeNanos += (System.nanoTime() - start); | ||
| if (bytes > 0) { | ||
| bytesRead += bytes; | ||
| } | ||
| return bytes; | ||
| } | ||
|
|
||
| @Override | ||
| public int read(byte[] b, int off, int len) throws IOException { | ||
| long start = System.nanoTime(); | ||
| int bytes = super.read(b, off, len); | ||
| elapsedTimeNanos += (System.nanoTime() - start); | ||
| if (bytes > 0) { | ||
| bytesRead += bytes; | ||
| } | ||
| return bytes; | ||
| } | ||
|
|
||
| public long getElapsedTimeMs() { | ||
| return TimeUnit.NANOSECONDS.toMillis(elapsedTimeNanos); | ||
| } | ||
|
|
||
| public long getBytesRead() { | ||
| return bytesRead; | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,11 +40,14 @@ | |
| import org.apache.tez.common.CallableWithNdc; | ||
| import org.apache.tez.common.TezRuntimeFrameworkConfigs; | ||
| import org.apache.tez.common.TezUtilsInternal; | ||
| import org.apache.tez.common.counters.TaskCounter; | ||
| import org.apache.tez.common.counters.TezCounter; | ||
| import org.apache.tez.common.security.JobTokenSecretManager; | ||
| import org.apache.tez.http.BaseHttpConnection; | ||
| import org.apache.tez.http.HttpConnectionParams; | ||
| import org.apache.tez.http.MeasuredDataInputStream; | ||
| import org.apache.tez.runtime.api.InputContext; | ||
| import org.apache.tez.runtime.library.api.TezRuntimeConfiguration; | ||
| import org.apache.tez.runtime.library.common.Constants; | ||
| import org.apache.tez.runtime.library.common.InputAttemptIdentifier; | ||
| import org.apache.tez.runtime.library.common.shuffle.InputAttemptFetchFailure; | ||
|
|
@@ -75,6 +78,8 @@ class FetcherOrderedGrouped extends CallableWithNdc<Void> { | |
| private final TezCounter wrongLengthErrs; | ||
| private final TezCounter badIdErrs; | ||
| private final TezCounter wrongReduceErrs; | ||
| private final TezCounter ioTimeCounter; | ||
| private final TezCounter ioBytesCounter; | ||
| private final FetchedInputAllocatorOrderedGrouped allocator; | ||
| private final ShuffleScheduler scheduler; | ||
| private final ExceptionReporter exceptionReporter; | ||
|
|
@@ -151,6 +156,12 @@ public FetcherOrderedGrouped(HttpConnectionParams httpConnectionParams, | |
| this.badIdErrs = badIdErrsCounter; | ||
| this.connectionErrs = connectionErrsCounter; | ||
| this.wrongReduceErrs = wrongReduceErrsCounter; | ||
| boolean measureTime = conf.getBoolean(TezRuntimeConfiguration.TEZ_RUNTIME_SHUFFLE_MEASURE_IO_TIME, | ||
| TezRuntimeConfiguration.TEZ_RUNTIME_SHUFFLE_MEASURE_IO_TIME_DEFAULT); | ||
| this.ioTimeCounter = | ||
| measureTime ? inputContext.getCounters().findCounter(TaskCounter.SHUFFLE_IO_STREAM_TIME_MILLISECONDS) : null; | ||
| this.ioBytesCounter = | ||
| measureTime ? inputContext.getCounters().findCounter(TaskCounter.SHUFFLE_IO_STREAM_BYTES) : null; | ||
| this.applicationId = inputContext.getApplicationId().toString(); | ||
| this.dagId = inputContext.getDagIdentifier(); | ||
|
|
||
|
|
@@ -227,6 +238,10 @@ private void cleanupCurrentConnection(boolean disconnect) { | |
| synchronized (cleanupLock) { | ||
| try { | ||
| if (httpConnection != null) { | ||
| if (input instanceof MeasuredDataInputStream && ioTimeCounter != null) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: maybe evaluate "ioTimeCounter != null" first, looks more efficient than an
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure. the if statement will be like |
||
| ioTimeCounter.increment(((MeasuredDataInputStream) input).getElapsedTimeMs()); | ||
| ioBytesCounter.increment(((MeasuredDataInputStream) input).getBytesRead()); | ||
| } | ||
| httpConnection.cleanup(disconnect); | ||
| httpConnection = null; | ||
| } | ||
|
|
@@ -392,6 +407,9 @@ boolean setupConnection(MapHost host, Collection<InputAttemptIdentifier> attempt | |
| protected void setupConnectionInternal(MapHost host, Collection<InputAttemptIdentifier> attempts) | ||
| throws IOException, InterruptedException { | ||
| input = httpConnection.getInputStream(); | ||
| if (ioTimeCounter != null) { | ||
| input = new MeasuredDataInputStream(input); | ||
| } | ||
| httpConnection.validate(); | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.