Search in sources :

Example 1 with NameValuePair

use of org.apache.hadoop.metrics2.util.Metrics2Util.NameValuePair in project hadoop by apache.

the class TestEntityGroupFSTimelineStore method testPluginRead.

@Test
public void testPluginRead() throws Exception {
    // Verify precondition
    assertEquals(EntityGroupPlugInForTest.class.getName(), store.getConfig().get(YarnConfiguration.TIMELINE_SERVICE_ENTITY_GROUP_PLUGIN_CLASSES));
    List<TimelineEntityGroupPlugin> currPlugins = store.getPlugins();
    for (TimelineEntityGroupPlugin plugin : currPlugins) {
        ClassLoader pluginClassLoader = plugin.getClass().getClassLoader();
        assertTrue("Should set up ApplicationClassLoader", pluginClassLoader instanceof ApplicationClassLoader);
        URL[] paths = ((URLClassLoader) pluginClassLoader).getURLs();
        boolean foundJAR = false;
        for (URL path : paths) {
            if (path.toString().contains(testJar.getAbsolutePath())) {
                foundJAR = true;
            }
        }
        assertTrue("Not found path " + testJar.getAbsolutePath() + " for plugin " + plugin.getClass().getName(), foundJAR);
    }
    // Load data and cache item, prepare timeline store by making a cache item
    EntityGroupFSTimelineStore.AppLogs appLogs = store.new AppLogs(mainTestAppId, mainTestAppDirPath, AppState.COMPLETED);
    EntityCacheItem cacheItem = new EntityCacheItem(EntityGroupPlugInForTest.getStandardTimelineGroupId(mainTestAppId), config);
    cacheItem.setAppLogs(appLogs);
    store.setCachedLogs(EntityGroupPlugInForTest.getStandardTimelineGroupId(mainTestAppId), cacheItem);
    MutableCounterLong detailLogEntityRead = store.metrics.getGetEntityToDetailOps();
    MutableStat cacheRefresh = store.metrics.getCacheRefresh();
    long numEntityReadBefore = detailLogEntityRead.value();
    long cacheRefreshBefore = cacheRefresh.lastStat().numSamples();
    // Generate TDM
    TimelineDataManager tdm = PluginStoreTestUtils.getTdmWithStore(config, store);
    // Verify single entity read
    TimelineEntity entity3 = tdm.getEntity("type_3", mainTestAppId.toString(), EnumSet.allOf(TimelineReader.Field.class), UserGroupInformation.getLoginUser());
    assertNotNull(entity3);
    assertEquals(entityNew.getStartTime(), entity3.getStartTime());
    // Verify multiple entities read
    NameValuePair primaryFilter = new NameValuePair(EntityGroupPlugInForTest.APP_ID_FILTER_NAME, mainTestAppId.toString());
    TimelineEntities entities = tdm.getEntities("type_3", primaryFilter, null, null, null, null, null, null, EnumSet.allOf(TimelineReader.Field.class), UserGroupInformation.getLoginUser());
    assertEquals(1, entities.getEntities().size());
    for (TimelineEntity entity : entities.getEntities()) {
        assertEquals(entityNew.getStartTime(), entity.getStartTime());
    }
    // Verify metrics
    assertEquals(numEntityReadBefore + 2L, detailLogEntityRead.value());
    assertEquals(cacheRefreshBefore + 1L, cacheRefresh.lastStat().numSamples());
}
Also used : MutableCounterLong(org.apache.hadoop.metrics2.lib.MutableCounterLong) MutableStat(org.apache.hadoop.metrics2.lib.MutableStat) TimelineEntity(org.apache.hadoop.yarn.api.records.timeline.TimelineEntity) ApplicationClassLoader(org.apache.hadoop.util.ApplicationClassLoader) URL(java.net.URL) TimelineEntities(org.apache.hadoop.yarn.api.records.timeline.TimelineEntities) URLClassLoader(java.net.URLClassLoader) ApplicationClassLoader(org.apache.hadoop.util.ApplicationClassLoader) URLClassLoader(java.net.URLClassLoader) Test(org.junit.Test)

Example 2 with NameValuePair

use of org.apache.hadoop.metrics2.util.Metrics2Util.NameValuePair in project hadoop by apache.

the class RollingWindowManager method snapshot.

/**
   * Take a snapshot of current top users in the past period.
   *
   * @param time the current time
   * @return a TopWindow describing the top users for each metric in the 
   * window.
   */
public TopWindow snapshot(long time) {
    TopWindow window = new TopWindow(windowLenMs);
    Set<String> metricNames = metricMap.keySet();
    LOG.debug("iterating in reported metrics, size={} values={}", metricNames.size(), metricNames);
    for (Map.Entry<String, RollingWindowMap> entry : metricMap.entrySet()) {
        String metricName = entry.getKey();
        RollingWindowMap rollingWindows = entry.getValue();
        TopN topN = getTopUsersForMetric(time, metricName, rollingWindows);
        final int size = topN.size();
        if (size == 0) {
            continue;
        }
        Op op = new Op(metricName, topN.getTotal());
        window.addOp(op);
        // Reverse the users from the TopUsers using a stack, 
        // since we'd like them sorted in descending rather than ascending order
        Stack<NameValuePair> reverse = new Stack<NameValuePair>();
        for (int i = 0; i < size; i++) {
            reverse.push(topN.poll());
        }
        for (int i = 0; i < size; i++) {
            NameValuePair userEntry = reverse.pop();
            User user = new User(userEntry.getName(), userEntry.getValue());
            op.addUser(user);
        }
    }
    return window;
}
Also used : NameValuePair(org.apache.hadoop.metrics2.util.Metrics2Util.NameValuePair) Stack(java.util.Stack) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Map(java.util.Map) TopN(org.apache.hadoop.metrics2.util.Metrics2Util.TopN)

Example 3 with NameValuePair

use of org.apache.hadoop.metrics2.util.Metrics2Util.NameValuePair in project hadoop by apache.

the class DecayRpcScheduler method addTopNCallerSummary.

// Key: Caller(xyz).Volume and Caller(xyz).Priority
private void addTopNCallerSummary(MetricsRecordBuilder rb) {
    TopN topNCallers = getTopCallers(topUsersCount);
    Map<Object, Integer> decisions = scheduleCacheRef.get();
    final int actualCallerCount = topNCallers.size();
    for (int i = 0; i < actualCallerCount; i++) {
        NameValuePair entry = topNCallers.poll();
        String topCaller = "Caller(" + entry.getName() + ")";
        String topCallerVolume = topCaller + ".Volume";
        String topCallerPriority = topCaller + ".Priority";
        rb.addCounter(Interns.info(topCallerVolume, topCallerVolume), entry.getValue());
        Integer priority = decisions.get(entry.getName());
        if (priority != null) {
            rb.addCounter(Interns.info(topCallerPriority, topCallerPriority), priority);
        }
    }
}
Also used : NameValuePair(org.apache.hadoop.metrics2.util.Metrics2Util.NameValuePair) TopN(org.apache.hadoop.metrics2.util.Metrics2Util.TopN)

Example 4 with NameValuePair

use of org.apache.hadoop.metrics2.util.Metrics2Util.NameValuePair in project hadoop by apache.

the class DecayRpcScheduler method getTopCallers.

// Get the top N callers' raw call count and scheduler decision
private TopN getTopCallers(int n) {
    TopN topNCallers = new TopN(n);
    Iterator<Map.Entry<Object, List<AtomicLong>>> it = callCounts.entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry<Object, List<AtomicLong>> entry = it.next();
        String caller = entry.getKey().toString();
        Long count = entry.getValue().get(1).get();
        if (count > 0) {
            topNCallers.offer(new NameValuePair(caller, count));
        }
    }
    return topNCallers;
}
Also used : NameValuePair(org.apache.hadoop.metrics2.util.Metrics2Util.NameValuePair) AtomicLong(java.util.concurrent.atomic.AtomicLong) AtomicLong(java.util.concurrent.atomic.AtomicLong) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) TopN(org.apache.hadoop.metrics2.util.Metrics2Util.TopN)

Example 5 with NameValuePair

use of org.apache.hadoop.metrics2.util.Metrics2Util.NameValuePair in project hadoop by apache.

the class RollingWindowManager method getTopUsersForMetric.

/**
   * Calculates the top N users over a time interval.
   * 
   * @param time the current time
   * @param metricName Name of metric
   * @return
   */
private TopN getTopUsersForMetric(long time, String metricName, RollingWindowMap rollingWindows) {
    TopN topN = new TopN(topUsersCnt);
    Iterator<Map.Entry<String, RollingWindow>> iterator = rollingWindows.entrySet().iterator();
    while (iterator.hasNext()) {
        Map.Entry<String, RollingWindow> entry = iterator.next();
        String userName = entry.getKey();
        RollingWindow aWindow = entry.getValue();
        long windowSum = aWindow.getSum(time);
        // do the gc here
        if (windowSum == 0) {
            LOG.debug("gc window of metric: {} userName: {}", metricName, userName);
            iterator.remove();
            continue;
        }
        LOG.debug("offer window of metric: {} userName: {} sum: {}", metricName, userName, windowSum);
        topN.offer(new NameValuePair(userName, windowSum));
    }
    LOG.debug("topN users size for command {} is: {}", metricName, topN.size());
    return topN;
}
Also used : NameValuePair(org.apache.hadoop.metrics2.util.Metrics2Util.NameValuePair) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Map(java.util.Map) TopN(org.apache.hadoop.metrics2.util.Metrics2Util.TopN)

Aggregations

NameValuePair (org.apache.hadoop.metrics2.util.Metrics2Util.NameValuePair)4 TopN (org.apache.hadoop.metrics2.util.Metrics2Util.TopN)4 Map (java.util.Map)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 URL (java.net.URL)1 URLClassLoader (java.net.URLClassLoader)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Stack (java.util.Stack)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 MutableCounterLong (org.apache.hadoop.metrics2.lib.MutableCounterLong)1 MutableStat (org.apache.hadoop.metrics2.lib.MutableStat)1 ApplicationClassLoader (org.apache.hadoop.util.ApplicationClassLoader)1 TimelineEntities (org.apache.hadoop.yarn.api.records.timeline.TimelineEntities)1 TimelineEntity (org.apache.hadoop.yarn.api.records.timeline.TimelineEntity)1 Test (org.junit.Test)1