-
Notifications
You must be signed in to change notification settings - Fork 424
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
[DRAFT] TEZ-4505: Create counters about time intervals spent in certain states in StateMachineTez #304
base: master
Are you sure you want to change the base?
[DRAFT] TEZ-4505: Create counters about time intervals spent in certain states in StateMachineTez #304
Changes from all 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,22 @@ | ||
/** | ||
* 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.common.counters; | ||
|
||
public class TaskAttemptCounter { | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,7 @@ | |
import org.apache.commons.lang.StringUtils; | ||
import org.apache.commons.lang.exception.ExceptionUtils; | ||
import org.apache.hadoop.classification.InterfaceAudience.Private; | ||
import org.apache.tez.common.counters.TaskAttemptCounter; | ||
import org.apache.tez.dag.app.dag.event.TaskEventTAFailed; | ||
import org.apache.tez.dag.records.TaskAttemptTerminationCause; | ||
import org.apache.tez.dag.records.TezTaskAttemptID; | ||
|
@@ -58,6 +59,7 @@ | |
import org.apache.hadoop.yarn.state.StateMachineFactory; | ||
import org.apache.hadoop.yarn.util.Clock; | ||
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.dag.api.TaskLocationHint; | ||
import org.apache.tez.dag.api.TezUncheckedException; | ||
|
@@ -315,6 +317,9 @@ private void augmentStateMachine() { | |
stateMachine | ||
.registerStateEnteredCallback(TaskStateInternal.SUCCEEDED, | ||
STATE_CHANGED_CALLBACK); | ||
if (StateMachineTez.isStateIntervalMonitorEnabled(conf)) { | ||
stateMachine.enableStateIntervalMonitor(); | ||
} | ||
} | ||
|
||
private final StateMachineTez<TaskStateInternal, TaskEventType, TaskEvent, TaskImpl> | ||
|
@@ -474,6 +479,10 @@ public TezCounters getCounters() { | |
try { | ||
TaskAttempt bestAttempt = selectBestAttempt(); | ||
TezCounters taskCounters = (bestAttempt != null) ? bestAttempt.getCounters() : TaskAttemptImpl.EMPTY_COUNTERS; | ||
|
||
stateMachine.incrementStateCounters(TaskCounter.class.getSimpleName() + "_" + getVertex().getName(), taskCounters); | ||
maybeMergeAllTaskAttemptCounters(taskCounters); | ||
|
||
if (getVertex().isSpeculationEnabled()) { | ||
tezCounters.incrAllCounters(taskCounters); | ||
return tezCounters; | ||
|
@@ -484,6 +493,18 @@ public TezCounters getCounters() { | |
} | ||
} | ||
|
||
private void maybeMergeAllTaskAttemptCounters(TezCounters taskCounters) { | ||
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 |
||
if (stateMachine.isStateIntervalMonitorEnabled()) { | ||
// if the state interval monitoring is disabled for this TaskImpl.stateMachine, | ||
// it's disabled for all TaskAttemptImpl's stateMachine too | ||
return; | ||
} | ||
String groupName = TaskAttemptCounter.class.getSimpleName() + "_" + getVertex().getName(); | ||
for (TaskAttempt at : attempts.values()) { | ||
taskCounters.getGroup(groupName).aggrAllCounters(at.getStateCounters().getGroup(groupName)); | ||
} | ||
} | ||
|
||
TaskStatistics getStatistics() { | ||
// simply return the stats from the best attempt | ||
readLock.lock(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,8 +21,12 @@ | |
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.apache.hadoop.conf.Configuration; | ||
import org.apache.hadoop.util.Time; | ||
import org.apache.hadoop.yarn.state.InvalidStateTransitonException; | ||
import org.apache.hadoop.yarn.state.StateMachine; | ||
import org.apache.tez.common.counters.TezCounters; | ||
import org.apache.tez.dag.api.TezConfiguration; | ||
import org.apache.tez.dag.records.TezID; | ||
|
||
public class StateMachineTez<STATE extends Enum<STATE>, EVENTTYPE extends Enum<EVENTTYPE>, EVENT, OPERAND> | ||
|
@@ -34,6 +38,10 @@ public class StateMachineTez<STATE extends Enum<STATE>, EVENTTYPE extends Enum<E | |
|
||
private final StateMachine<STATE, EVENTTYPE, EVENT> realStatemachine; | ||
|
||
private boolean isStateIntervalMonitorEnabled = false; | ||
private long lastStateChangedTime = Time.monotonicNow(); | ||
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. shouldn't this be set as part of |
||
private Map<String, Long> intervalSpentInStatesMs = new HashMap<>(); | ||
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. this can be final |
||
|
||
@SuppressWarnings("unchecked") | ||
public StateMachineTez(StateMachine sm, OPERAND operand) { | ||
this.realStatemachine = sm; | ||
|
@@ -67,7 +75,38 @@ public STATE doTransition(EVENTTYPE eventType, EVENT event) throws | |
if (callback != null) { | ||
callback.onStateChanged(operand, newState); | ||
} | ||
if (isStateIntervalMonitorEnabled) { | ||
String stateName = oldState.name(); | ||
if (!intervalSpentInStatesMs.containsKey(stateName)) { | ||
intervalSpentInStatesMs.put(stateName, 0L); | ||
} | ||
long now = Time.monotonicNow(); | ||
intervalSpentInStatesMs.put(stateName, now - lastStateChangedTime); | ||
lastStateChangedTime = now; | ||
} | ||
} | ||
return newState; | ||
} | ||
|
||
public static boolean isStateIntervalMonitorEnabled(Configuration conf) { | ||
return conf.getBoolean(TezConfiguration.TEZ_DAG_STATE_INTERVAL_MONITOR_ENABLED, | ||
TezConfiguration.TEZ_DAG_STATE_INTERVAL_MONITOR_ENABLED_DEFAULT); | ||
} | ||
|
||
public boolean isStateIntervalMonitorEnabled() { | ||
return isStateIntervalMonitorEnabled; | ||
} | ||
|
||
public void enableStateIntervalMonitor() { | ||
this.isStateIntervalMonitorEnabled = true; | ||
} | ||
|
||
public void incrementStateCounters(String group, TezCounters counters) { | ||
if (!isStateIntervalMonitorEnabled) { | ||
return; | ||
} | ||
for (Map.Entry<String, Long> e : intervalSpentInStatesMs.entrySet()) { | ||
counters.getGroup(group).findCounter(e.getKey(), true).increment(e.getValue()); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't decode the usage of this 'empty' class, we are only using the name of this class, if only name is required can't we have a string constant or an enum
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is just a leftover, actually I'm in the middle of this, full of bugs, let me set this PR to [DRAFT]