Search in sources :

Example 11 with CounterGroup

use of org.apache.tez.common.counters.CounterGroup in project tez by apache.

the class AMWebController method constructCounterMapInfo.

Map<String, Map<String, Long>> constructCounterMapInfo(TezCounters counters, Map<String, Set<String>> counterNames) {
    if (counterNames == null || counterNames.isEmpty()) {
        return null;
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("Requested counter names=" + counterNames.entrySet());
        LOG.debug("actual counters=" + counters);
    }
    Map<String, Map<String, Long>> counterInfo = new TreeMap<String, Map<String, Long>>();
    if (counterNames.containsKey("*")) {
        for (CounterGroup grpCounters : counters) {
            Map<String, Long> matchedCounters = new HashMap<String, Long>();
            for (TezCounter counter : grpCounters) {
                matchedCounters.put(counter.getName(), counter.getValue());
            }
            counterInfo.put(grpCounters.getName(), matchedCounters);
        }
    } else {
        for (Entry<String, Set<String>> entry : counterNames.entrySet()) {
            Map<String, Long> matchedCounters = new HashMap<String, Long>();
            CounterGroup grpCounters = counters.getGroup(entry.getKey());
            for (TezCounter counter : grpCounters) {
                if (entry.getValue().isEmpty() || entry.getValue().contains(counter.getName())) {
                    matchedCounters.put(counter.getName(), counter.getValue());
                }
            }
            counterInfo.put(entry.getKey(), matchedCounters);
        }
    }
    return counterInfo;
}
Also used : Set(java.util.Set) HashMap(java.util.HashMap) CounterGroup(org.apache.tez.common.counters.CounterGroup) TezCounter(org.apache.tez.common.counters.TezCounter) TreeMap(java.util.TreeMap) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) TreeMap(java.util.TreeMap)

Example 12 with CounterGroup

use of org.apache.tez.common.counters.CounterGroup in project tez by apache.

the class DagTypeConverters method convertTezCountersFromProto.

public static TezCounters convertTezCountersFromProto(TezCountersProto proto) {
    TezCounters counters = new TezCounters();
    for (TezCounterGroupProto counterGroupProto : proto.getCounterGroupsList()) {
        CounterGroup group = counters.addGroup(counterGroupProto.getName(), counterGroupProto.getDisplayName());
        for (TezCounterProto counterProto : counterGroupProto.getCountersList()) {
            TezCounter counter = group.findCounter(counterProto.getName(), counterProto.getDisplayName());
            counter.setValue(counterProto.getValue());
        }
    }
    return counters;
}
Also used : TezCounterGroupProto(org.apache.tez.dag.api.records.DAGProtos.TezCounterGroupProto) TezCounterProto(org.apache.tez.dag.api.records.DAGProtos.TezCounterProto) CounterGroup(org.apache.tez.common.counters.CounterGroup) TezCounter(org.apache.tez.common.counters.TezCounter) TezCounters(org.apache.tez.common.counters.TezCounters)

Example 13 with CounterGroup

use of org.apache.tez.common.counters.CounterGroup in project tez by apache.

the class TestTezJobs method testPerIOCounterAggregation.

@Test(timeout = 60000)
public void testPerIOCounterAggregation() throws Exception {
    String baseDir = "/tmp/perIOCounterAgg/";
    Path inPath1 = new Path(baseDir + "inPath1");
    Path inPath2 = new Path(baseDir + "inPath2");
    Path outPath = new Path(baseDir + "outPath");
    final Set<String> expectedResults = generateSortMergeJoinInput(inPath1, inPath2);
    Path stagingDirPath = new Path("/tmp/tez-staging-dir");
    remoteFs.mkdirs(stagingDirPath);
    TezConfiguration conf = new TezConfiguration(mrrTezCluster.getConfig());
    conf.setBoolean(TezConfiguration.TEZ_TASK_GENERATE_COUNTERS_PER_IO, true);
    TezClient tezClient = TezClient.create(SortMergeJoinHelper.class.getSimpleName(), conf);
    tezClient.start();
    SortMergeJoinHelper sortMergeJoinHelper = new SortMergeJoinHelper(tezClient);
    sortMergeJoinHelper.setConf(conf);
    String[] args = new String[] { "-D" + TezConfiguration.TEZ_AM_STAGING_DIR + "=" + stagingDirPath.toString(), "-counter", inPath1.toString(), inPath2.toString(), "1", outPath.toString() };
    assertEquals(0, sortMergeJoinHelper.run(conf, args, tezClient));
    verifySortMergeJoinInput(outPath, expectedResults);
    String joinerVertexName = "joiner";
    String input1Name = "input1";
    String input2Name = "input2";
    String joinOutputName = "joinOutput";
    Set<StatusGetOpts> statusOpts = new HashSet<StatusGetOpts>();
    statusOpts.add(StatusGetOpts.GET_COUNTERS);
    VertexStatus joinerVertexStatus = sortMergeJoinHelper.dagClient.getVertexStatus(joinerVertexName, statusOpts);
    final TezCounters joinerCounters = joinerVertexStatus.getVertexCounters();
    final CounterGroup aggregatedGroup = joinerCounters.getGroup(TaskCounter.class.getCanonicalName());
    final CounterGroup input1Group = joinerCounters.getGroup(TaskCounter.class.getSimpleName() + "_" + joinerVertexName + "_INPUT_" + input1Name);
    final CounterGroup input2Group = joinerCounters.getGroup(TaskCounter.class.getSimpleName() + "_" + joinerVertexName + "_INPUT_" + input2Name);
    assertTrue("aggregated counter group cannot be empty", aggregatedGroup.size() > 0);
    assertTrue("per io group for input1 cannot be empty", input1Group.size() > 0);
    assertTrue("per io group for input1 cannot be empty", input2Group.size() > 0);
    List<TaskCounter> countersToVerifyAgg = Arrays.asList(TaskCounter.ADDITIONAL_SPILLS_BYTES_READ, TaskCounter.ADDITIONAL_SPILLS_BYTES_WRITTEN, TaskCounter.COMBINE_INPUT_RECORDS, TaskCounter.MERGED_MAP_OUTPUTS, TaskCounter.NUM_DISK_TO_DISK_MERGES, TaskCounter.NUM_FAILED_SHUFFLE_INPUTS, TaskCounter.NUM_MEM_TO_DISK_MERGES, TaskCounter.NUM_SHUFFLED_INPUTS, TaskCounter.NUM_SKIPPED_INPUTS, TaskCounter.REDUCE_INPUT_GROUPS, TaskCounter.REDUCE_INPUT_RECORDS, TaskCounter.SHUFFLE_BYTES, TaskCounter.SHUFFLE_BYTES_DECOMPRESSED, TaskCounter.SHUFFLE_BYTES_DISK_DIRECT, TaskCounter.SHUFFLE_BYTES_TO_DISK, TaskCounter.SHUFFLE_BYTES_TO_MEM, TaskCounter.SPILLED_RECORDS);
    int nonZeroCounters = 0;
    // verify that the sum of the counter values for edges add up to the aggregated counter value.
    for (TaskCounter c : countersToVerifyAgg) {
        TezCounter aggregatedCounter = aggregatedGroup.findCounter(c.name(), false);
        TezCounter input1Counter = input1Group.findCounter(c.name(), false);
        TezCounter input2Counter = input2Group.findCounter(c.name(), false);
        assertNotNull("aggregated counter cannot be null " + c.name(), aggregatedCounter);
        assertNotNull("input1 counter cannot be null " + c.name(), input1Counter);
        assertNotNull("input2 counter cannot be null " + c.name(), input2Counter);
        assertEquals("aggregated counter does not match sum of input counters " + c.name(), aggregatedCounter.getValue(), input1Counter.getValue() + input2Counter.getValue());
        if (aggregatedCounter.getValue() > 0) {
            nonZeroCounters++;
        }
    }
    // ensure that at least one of the counters tested above were non-zero.
    assertTrue("At least one of the counter should be non-zero. invalid test ", nonZeroCounters > 0);
    CounterGroup joinerOutputGroup = joinerCounters.getGroup(TaskCounter.class.getSimpleName() + "_" + joinerVertexName + "_OUTPUT_" + joinOutputName);
    String outputCounterName = TaskCounter.OUTPUT_RECORDS.name();
    TezCounter aggregateCounter = aggregatedGroup.findCounter(outputCounterName, false);
    TezCounter joinerOutputCounter = joinerOutputGroup.findCounter(outputCounterName, false);
    assertNotNull("aggregated counter cannot be null " + outputCounterName, aggregateCounter);
    assertNotNull("output counter cannot be null " + outputCounterName, joinerOutputCounter);
    assertTrue("counter value is zero. test is invalid", aggregateCounter.getValue() > 0);
    assertEquals("aggregated counter does not match sum of output counters " + outputCounterName, aggregateCounter.getValue(), joinerOutputCounter.getValue());
}
Also used : Path(org.apache.hadoop.fs.Path) VertexStatus(org.apache.tez.dag.api.client.VertexStatus) CounterGroup(org.apache.tez.common.counters.CounterGroup) TezCounter(org.apache.tez.common.counters.TezCounter) TezCounters(org.apache.tez.common.counters.TezCounters) TezClient(org.apache.tez.client.TezClient) StatusGetOpts(org.apache.tez.dag.api.client.StatusGetOpts) TaskCounter(org.apache.tez.common.counters.TaskCounter) TezConfiguration(org.apache.tez.dag.api.TezConfiguration) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 14 with CounterGroup

use of org.apache.tez.common.counters.CounterGroup in project hive by apache.

the class WmFragmentCounters method dumpToTezCounters.

public void dumpToTezCounters(TezCounters tezCounters, boolean isLast) {
    if (isLast) {
        // Record the final counters.
        changeStateDone();
    }
    for (int i = 0; i < fixedCounters.length(); ++i) {
        tezCounters.findCounter(LlapWmCounters.values()[i]).setValue(fixedCounters.get(i));
    }
    // to the Tez counters.
    if (addTaskTimeCounters) {
        String hostName = MetricsUtils.getHostName();
        long queued = fixedCounters.get(LlapWmCounters.GUARANTEED_QUEUED_NS.ordinal()) + fixedCounters.get(LlapWmCounters.SPECULATIVE_QUEUED_NS.ordinal());
        long running = fixedCounters.get(LlapWmCounters.GUARANTEED_RUNNING_NS.ordinal()) + fixedCounters.get(LlapWmCounters.SPECULATIVE_RUNNING_NS.ordinal());
        CounterGroup cg = tezCounters.getGroup("LlapTaskRuntimeAgg by daemon");
        cg.findCounter("QueueTime-" + hostName).setValue(queued);
        cg.findCounter("RunTime-" + hostName).setValue(running);
        cg.findCounter("Count-" + hostName).setValue(1);
    }
}
Also used : CounterGroup(org.apache.tez.common.counters.CounterGroup)

Example 15 with CounterGroup

use of org.apache.tez.common.counters.CounterGroup in project hive by apache.

the class PostExecOrcRowGroupCountPrinter method run.

@Override
public void run(HookContext hookContext) throws Exception {
    assert (hookContext.getHookType() == HookContext.HookType.POST_EXEC_HOOK);
    HiveConf conf = hookContext.getConf();
    if (!"tez".equals(HiveConf.getVar(conf, HiveConf.ConfVars.HIVE_EXECUTION_ENGINE))) {
        return;
    }
    LOG.info("Executing post execution hook to print ORC row groups read counter..");
    SessionState ss = SessionState.get();
    SessionState.LogHelper console = ss.getConsole();
    QueryPlan plan = hookContext.getQueryPlan();
    if (plan == null) {
        return;
    }
    List<TezTask> rootTasks = Utilities.getTezTasks(plan.getRootTasks());
    for (TezTask tezTask : rootTasks) {
        LOG.info("Printing ORC row group counter for tez task: " + tezTask.getName());
        TezCounters counters = tezTask.getTezCounters();
        if (counters != null) {
            for (CounterGroup group : counters) {
                if (group.getName().equals(LlapIOCounters.class.getName())) {
                    console.printInfo(tezTask.getId() + " LLAP IO COUNTERS:", false);
                    for (TezCounter counter : group) {
                        if (counter.getDisplayName().equals(LlapIOCounters.SELECTED_ROWGROUPS.name())) {
                            console.printInfo("   " + counter.getDisplayName() + ": " + counter.getValue(), false);
                        }
                    }
                }
            }
        }
    }
}
Also used : SessionState(org.apache.hadoop.hive.ql.session.SessionState) LlapIOCounters(org.apache.hadoop.hive.llap.counters.LlapIOCounters) CounterGroup(org.apache.tez.common.counters.CounterGroup) HiveConf(org.apache.hadoop.hive.conf.HiveConf) TezCounter(org.apache.tez.common.counters.TezCounter) QueryPlan(org.apache.hadoop.hive.ql.QueryPlan) TezTask(org.apache.hadoop.hive.ql.exec.tez.TezTask) TezCounters(org.apache.tez.common.counters.TezCounters)

Aggregations

CounterGroup (org.apache.tez.common.counters.CounterGroup)16 TezCounter (org.apache.tez.common.counters.TezCounter)13 TezCounters (org.apache.tez.common.counters.TezCounters)8 SessionState (org.apache.hadoop.hive.ql.session.SessionState)4 IOException (java.io.IOException)3 Path (org.apache.hadoop.fs.Path)3 DAG (org.apache.tez.dag.api.DAG)3 DAGClient (org.apache.tez.dag.api.client.DAGClient)3 StatusGetOpts (org.apache.tez.dag.api.client.StatusGetOpts)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 HiveConf (org.apache.hadoop.hive.conf.HiveConf)2 Context (org.apache.hadoop.hive.ql.Context)2 QueryPlan (org.apache.hadoop.hive.ql.QueryPlan)2 TezTask (org.apache.hadoop.hive.ql.exec.tez.TezTask)2 MappingInput (org.apache.hadoop.hive.ql.exec.tez.UserPoolMapping.MappingInput)2 TezJobMonitor (org.apache.hadoop.hive.ql.exec.tez.monitoring.TezJobMonitor)2 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)2 BaseWork (org.apache.hadoop.hive.ql.plan.BaseWork)2 WmContext (org.apache.hadoop.hive.ql.wm.WmContext)2