Search in sources :

Example 1 with AggregatedDbusEventsTotalStats

use of com.linkedin.databus.core.monitoring.mbean.AggregatedDbusEventsTotalStats in project databus by linkedin.

the class TestAggregatedDbusEventStatsCollector method runAggregateTestStats.

void runAggregateTestStats(int n) {
    try {
        DbusEventsStatisticsCollector aggregateEventStatsCollectors = new AggregatedDbusEventsStatisticsCollector(0, "eventsInbound", true, true, null);
        // collection of n+1 stats collectors;
        StatsCollectors<DbusEventsStatisticsCollector> eventStatsCollectors = new StatsCollectors<DbusEventsStatisticsCollector>(aggregateEventStatsCollectors);
        // add new individual stats collectors
        int maxEventsInWindow = 10;
        StatsWriter[] nStatsWriters = createStatsWriters(n, maxEventsInWindow);
        for (StatsWriter sw : nStatsWriters) {
            eventStatsCollectors.addStatsCollector(sw.getStatsName(), sw.getEventsStatsCollector());
        }
        // aggregator thread; 250 ms poll time
        GlobalStatsCalc agg = new GlobalStatsCalc(10);
        agg.registerStatsCollector(eventStatsCollectors);
        Thread aggThread = new Thread(agg);
        aggThread.start();
        // start writers
        for (StatsWriter sw : nStatsWriters) {
            sw.start();
        }
        // Let the writers start
        Thread.sleep(1000);
        long startTimeMs = System.currentTimeMillis();
        // 5s
        long durationInMs = 5 * 1000;
        DbusEventsTotalStats globalStats = aggregateEventStatsCollectors.getTotalStats();
        long prevValue = 0, prevSize = 0;
        while (System.currentTimeMillis() < (startTimeMs + durationInMs)) {
            // constraint checks;
            // check that readers don't have partial updates or get initialized
            long value = globalStats.getNumDataEvents();
            long size = globalStats.getSizeDataEvents();
            Assert.assertTrue(value > 0);
            if (prevValue > 0 && (value != prevValue)) {
                Assert.assertTrue(size != prevSize);
                prevValue = value;
                prevSize = size;
            }
            Assert.assertTrue(globalStats.getMaxSeenWinScn() > 0);
            Thread.sleep(RngUtils.randomPositiveInt() % 10 + 1);
        }
        // shut down
        for (StatsWriter sw : nStatsWriters) {
            sw.shutdown();
            sw.interrupt();
        }
        // Give a chance to catch up
        Thread.sleep(1000);
        agg.halt();
        aggThread.interrupt();
        // final tally aggregatedEventTotalStats = sum of all individual statsWriter objects in a thread free way
        AggregatedDbusEventsTotalStats myTotalStats = new AggregatedDbusEventsTotalStats(StatsWriter.OWNERID, "mytotal", true, false, null);
        for (DbusEventsStatisticsCollector s : eventStatsCollectors.getStatsCollectors()) {
            DbusEventsTotalStats writerStat = s.getTotalStats();
            // obviously - we assume this is correct here. we want to check that the updates happen correctly in a concurrent setting
            myTotalStats.mergeStats(writerStat);
        }
        LOG.info("global = " + globalStats.getNumDataEvents() + " Sigma writers=" + myTotalStats.getNumDataEvents());
        Assert.assertEquals("NumDataEvents mismatch for n = " + n, globalStats.getNumDataEvents(), myTotalStats.getNumDataEvents());
        Assert.assertEquals("MaxSeenWinScn mismatch for n = " + n, globalStats.getMaxSeenWinScn(), myTotalStats.getMaxSeenWinScn());
    } catch (InterruptedException e) {
        Assert.assertTrue(false);
    }
}
Also used : AggregatedDbusEventsStatisticsCollector(com.linkedin.databus.core.monitoring.mbean.AggregatedDbusEventsStatisticsCollector) AggregatedDbusEventsStatisticsCollector(com.linkedin.databus.core.monitoring.mbean.AggregatedDbusEventsStatisticsCollector) DbusEventsStatisticsCollector(com.linkedin.databus.core.monitoring.mbean.DbusEventsStatisticsCollector) GlobalStatsCalc(com.linkedin.databus2.core.container.netty.ServerContainer.GlobalStatsCalc) StatsCollectors(com.linkedin.databus.core.monitoring.mbean.StatsCollectors) AggregatedDbusEventsTotalStats(com.linkedin.databus.core.monitoring.mbean.AggregatedDbusEventsTotalStats) DbusEventsTotalStats(com.linkedin.databus.core.monitoring.mbean.DbusEventsTotalStats) AggregatedDbusEventsTotalStats(com.linkedin.databus.core.monitoring.mbean.AggregatedDbusEventsTotalStats)

Aggregations

AggregatedDbusEventsStatisticsCollector (com.linkedin.databus.core.monitoring.mbean.AggregatedDbusEventsStatisticsCollector)1 AggregatedDbusEventsTotalStats (com.linkedin.databus.core.monitoring.mbean.AggregatedDbusEventsTotalStats)1 DbusEventsStatisticsCollector (com.linkedin.databus.core.monitoring.mbean.DbusEventsStatisticsCollector)1 DbusEventsTotalStats (com.linkedin.databus.core.monitoring.mbean.DbusEventsTotalStats)1 StatsCollectors (com.linkedin.databus.core.monitoring.mbean.StatsCollectors)1 GlobalStatsCalc (com.linkedin.databus2.core.container.netty.ServerContainer.GlobalStatsCalc)1