-
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 2 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,79 @@ | ||
| /* | ||
| * 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(); | ||
| } | ||
|
|
||
| private static class MeasuredInputStream extends FilterInputStream { | ||
| private long elapsedTimeNanos = 0; | ||
|
|
||
| MeasuredInputStream(InputStream in) { | ||
| super(in); | ||
| } | ||
|
|
||
| @Override | ||
| public int read() throws IOException { | ||
| long start = System.nanoTime(); | ||
| int ret = super.read(); | ||
| elapsedTimeNanos += (System.nanoTime() - start); | ||
| return ret; | ||
| } | ||
|
|
||
| @Override | ||
| public int read(byte[] b) throws IOException { | ||
| long start = System.nanoTime(); | ||
| int ret = super.read(b); | ||
| elapsedTimeNanos += (System.nanoTime() - start); | ||
| return ret; | ||
| } | ||
|
|
||
| @Override | ||
| public int read(byte[] b, int off, int len) throws IOException { | ||
| long start = System.nanoTime(); | ||
| int ret = super.read(b, off, len); | ||
| elapsedTimeNanos += (System.nanoTime() - start); | ||
| return ret; | ||
| } | ||
|
|
||
| public long getElapsedTimeMs() { | ||
| return TimeUnit.NANOSECONDS.toMillis(elapsedTimeNanos); | ||
| } | ||
| } | ||
| } |
| 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,7 @@ class FetcherOrderedGrouped extends CallableWithNdc<Void> { | |
| private final TezCounter wrongLengthErrs; | ||
| private final TezCounter badIdErrs; | ||
| private final TezCounter wrongReduceErrs; | ||
| private final TezCounter ioTimeCounter; | ||
| private final FetchedInputAllocatorOrderedGrouped allocator; | ||
| private final ShuffleScheduler scheduler; | ||
| private final ExceptionReporter exceptionReporter; | ||
|
|
@@ -151,6 +155,9 @@ public FetcherOrderedGrouped(HttpConnectionParams httpConnectionParams, | |
| this.badIdErrs = badIdErrsCounter; | ||
| this.connectionErrs = connectionErrsCounter; | ||
| this.wrongReduceErrs = wrongReduceErrsCounter; | ||
| this.ioTimeCounter = conf.getBoolean(TezRuntimeConfiguration.TEZ_RUNTIME_SHUFFLE_MEASURE_IO_TIME, | ||
| TezRuntimeConfiguration.TEZ_RUNTIME_SHUFFLE_MEASURE_IO_TIME_DEFAULT) ? | ||
| inputContext.getCounters().findCounter(TaskCounter.SHUFFLE_IO_TIME_MILLISECONDS) : null; | ||
| this.applicationId = inputContext.getApplicationId().toString(); | ||
| this.dagId = inputContext.getDagIdentifier(); | ||
|
|
||
|
|
@@ -227,6 +234,9 @@ 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()); | ||
| } | ||
| httpConnection.cleanup(disconnect); | ||
| httpConnection = null; | ||
| } | ||
|
|
@@ -392,6 +402,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(); | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -60,6 +60,7 @@ | |
| import org.apache.hadoop.fs.Path; | ||
| import org.apache.hadoop.fs.RawLocalFileSystem; | ||
| import org.apache.hadoop.yarn.api.records.ApplicationId; | ||
| import org.apache.tez.common.counters.TaskCounter; | ||
| import org.apache.tez.common.counters.TezCounter; | ||
| import org.apache.tez.common.counters.TezCounters; | ||
| import org.apache.tez.common.security.JobTokenSecretManager; | ||
|
|
@@ -798,4 +799,62 @@ private InputContext createMockInputContext() { | |
|
|
||
| return inputContext; | ||
| } | ||
|
|
||
| @Test | ||
| public void testShuffleMeasureIOTime() throws Exception { | ||
| Configuration conf = new TezConfiguration(); | ||
| conf.setBoolean(TezRuntimeConfiguration.TEZ_RUNTIME_SHUFFLE_MEASURE_IO_TIME, true); | ||
|
|
||
| ShuffleScheduler scheduler = mock(ShuffleScheduler.class); | ||
| MergeManager merger = mock(MergeManager.class); | ||
| Shuffle shuffle = mock(Shuffle.class); | ||
|
|
||
| final MapHost host = new MapHost(HOST, PORT, 1, 1); | ||
| InputContext inputContext = createMockInputContext(); | ||
| FetcherOrderedGrouped mockFetcher = | ||
| new FetcherOrderedGrouped(null, scheduler, merger, shuffle, null, false, 0, null, conf, getRawFs(conf), false, | ||
| HOST, PORT, host, ioErrsCounter, wrongLengthErrsCounter, badIdErrsCounter, wrongMapErrsCounter, | ||
| connectionErrsCounter, wrongReduceErrsCounter, false, false, true, false, inputContext); | ||
| final FetcherOrderedGrouped fetcher = spy(mockFetcher); | ||
|
|
||
| final List<InputAttemptIdentifier> srcAttempts = | ||
| List.of(new InputAttemptIdentifier(0, 1, InputAttemptIdentifier.PATH_PREFIX + "pathComponent_0")); | ||
| doReturn(srcAttempts).when(scheduler).getMapsForHost(host); | ||
|
|
||
| URL url = | ||
| ShuffleUtils.constructInputURL("http" + "://" + HOST + ":" + PORT + "/mapOutput?job=job_123&&reduce=1&map=", | ||
| srcAttempts, false); | ||
| fetcher.httpConnection = new FakeHttpConnection(url, null, "", null) { | ||
| @Override | ||
| public DataInputStream getInputStream() { | ||
| ByteArrayInputStream bin = new ByteArrayInputStream(new byte[1024]) { | ||
| @Override | ||
| public int read(byte[] b, int off, int len) { | ||
| try { | ||
| Thread.sleep(10); | ||
| } catch (InterruptedException e) { | ||
| Thread.currentThread().interrupt(); | ||
| } | ||
| return super.read(b, off, len); | ||
| } | ||
| }; | ||
| return new DataInputStream(bin); | ||
| } | ||
| }; | ||
|
|
||
| fetcher.setupConnectionInternal(host, srcAttempts); | ||
|
|
||
| // Read some bytes to trigger the elapsed time measurement | ||
| byte[] buffer = new byte[10]; | ||
| int bytesRead = fetcher.input.read(buffer, 0, buffer.length); | ||
| assertEquals(10, bytesRead); | ||
|
|
||
| // shutDown will update the counter | ||
| fetcher.shutDown(); | ||
|
|
||
| // Check if io time counter is updated | ||
| TezCounter ioTimeCounter = inputContext.getCounters().findCounter(TaskCounter.SHUFFLE_IO_TIME_MILLISECONDS); | ||
| long ioTime = ioTimeCounter.getValue(); | ||
| assertTrue(ioTime >= 10, "IO Time should be at least 10ms, but was " + ioTime); | ||
|
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. 10ms is a wild guess, even if it's working for 99% of the cases: I would use |
||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.