Search in sources :

Example 1 with StatsCollectors

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

the class TestDbusEventBufferMult method createStats.

private StatsCollectors<DbusEventsStatisticsCollector> createStats(String[] pNames) {
    DbusEventsStatisticsCollector stats = new AggregatedDbusEventsStatisticsCollector(1, "test", true, true, null);
    StatsCollectors<DbusEventsStatisticsCollector> statsColl = new StatsCollectors<DbusEventsStatisticsCollector>(stats);
    int count = 1;
    for (String pname : pNames) {
        DbusEventsStatisticsCollector s = new DbusEventsStatisticsCollector(1, "test" + count, true, true, null);
        statsColl.addStatsCollector(pname, s);
        ++count;
    }
    return statsColl;
}
Also used : AggregatedDbusEventsStatisticsCollector(com.linkedin.databus.core.monitoring.mbean.AggregatedDbusEventsStatisticsCollector) DbusEventsStatisticsCollector(com.linkedin.databus.core.monitoring.mbean.DbusEventsStatisticsCollector) AggregatedDbusEventsStatisticsCollector(com.linkedin.databus.core.monitoring.mbean.AggregatedDbusEventsStatisticsCollector) StatsCollectors(com.linkedin.databus.core.monitoring.mbean.StatsCollectors)

Example 2 with StatsCollectors

use of com.linkedin.databus.core.monitoring.mbean.StatsCollectors 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)2 DbusEventsStatisticsCollector (com.linkedin.databus.core.monitoring.mbean.DbusEventsStatisticsCollector)2 StatsCollectors (com.linkedin.databus.core.monitoring.mbean.StatsCollectors)2 AggregatedDbusEventsTotalStats (com.linkedin.databus.core.monitoring.mbean.AggregatedDbusEventsTotalStats)1 DbusEventsTotalStats (com.linkedin.databus.core.monitoring.mbean.DbusEventsTotalStats)1 GlobalStatsCalc (com.linkedin.databus2.core.container.netty.ServerContainer.GlobalStatsCalc)1