Search in sources :

Example 21 with UnifiedClientStats

use of com.linkedin.databus.client.pub.mbean.UnifiedClientStats in project databus by linkedin.

the class TestMultiConsumerCallback method testPerf.

@Test
public void testPerf() throws Exception {
    LOG.info("\n\nstarting testPerf()");
    List<String> sources = new ArrayList<String>();
    Map<Long, IdNamePair> sourcesMap = new HashMap<Long, IdNamePair>();
    for (int i = 1; i <= 3; ++i) {
        IdNamePair sourcePair = new IdNamePair((long) i, "source" + i);
        sources.add(sourcePair.getName());
        sourcesMap.put(sourcePair.getId(), sourcePair);
    }
    Hashtable<Long, AtomicInteger> keyCounts = new Hashtable<Long, AtomicInteger>();
    DbusEventBuffer eventsBuf = new DbusEventBuffer(_generic100KBufferStaticConfig);
    eventsBuf.start(0);
    eventsBuf.startEvents();
    initBufferWithEvents(eventsBuf, 1, 1, (short) 1, keyCounts);
    initBufferWithEvents(eventsBuf, 2, 2, (short) 3, keyCounts);
    eventsBuf.endEvents(100L);
    DbusEventBuffer.DbusEventIterator iter = eventsBuf.acquireIterator("myIter1");
    assert iter.hasNext() : "unable to read event";
    iter.next();
    DbusEvent event1 = iter.next();
    DatabusStreamConsumer logConsumer = new LoggingConsumer();
    SelectingDatabusCombinedConsumer sdccLogConsumer = new SelectingDatabusCombinedConsumer(logConsumer);
    DatabusV2ConsumerRegistration consumerReg = new DatabusV2ConsumerRegistration(sdccLogConsumer, sources, null);
    ConsumerCallbackStats consumerStatsCollector = new ConsumerCallbackStats(1, "test", "test", true, false, null);
    UnifiedClientStats unifiedStatsCollector = new UnifiedClientStats(1, "test", "test.unified");
    List<DatabusV2ConsumerRegistration> allRegistrations = Arrays.asList(consumerReg);
    ThreadPoolExecutor executor = (ThreadPoolExecutor) Executors.newCachedThreadPool();
    MultiConsumerCallback callback = new MultiConsumerCallback(allRegistrations, executor, 60000, new StreamConsumerCallbackFactory(consumerStatsCollector, unifiedStatsCollector), consumerStatsCollector, unifiedStatsCollector, null, null);
    callback.setSourceMap(sourcesMap);
    callback.onStartConsumption();
    callback.onStartDataEventSequence(new SingleSourceSCN(1, 1));
    for (int i = 0; i < 10000; ++i) {
        callback.onDataEvent(event1, null);
    }
    callback.onEndDataEventSequence(new SingleSourceSCN(1, 1));
    callback.onStopConsumption();
    System.out.println("max threads=" + executor.getLargestPoolSize() + " task count=" + executor.getTaskCount());
    System.out.println("dataEventsReceived=" + consumerStatsCollector.getNumDataEventsReceived() + " sysEventsReceived=" + consumerStatsCollector.getNumSysEventsReceived() + " dataEventsProcessed=" + consumerStatsCollector.getNumDataEventsProcessed() + " latencyEventsProcessed=" + consumerStatsCollector.getLatencyEventsProcessed());
    long dataEvents = consumerStatsCollector.getNumDataEventsReceived();
    assert (consumerStatsCollector.getNumDataEventsProcessed() == dataEvents);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IdNamePair(com.linkedin.databus.core.util.IdNamePair) UnifiedClientStats(com.linkedin.databus.client.pub.mbean.UnifiedClientStats) DbusEvent(com.linkedin.databus.core.DbusEvent) DatabusStreamConsumer(com.linkedin.databus.client.pub.DatabusStreamConsumer) Hashtable(java.util.Hashtable) ConsumerCallbackStats(com.linkedin.databus.client.pub.mbean.ConsumerCallbackStats) DbusEventBuffer(com.linkedin.databus.core.DbusEventBuffer) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SingleSourceSCN(com.linkedin.databus.client.SingleSourceSCN) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest) AfterTest(org.testng.annotations.AfterTest)

Aggregations

UnifiedClientStats (com.linkedin.databus.client.pub.mbean.UnifiedClientStats)21 Test (org.testng.annotations.Test)10 ConsumerCallbackStats (com.linkedin.databus.client.pub.mbean.ConsumerCallbackStats)9 Checkpoint (com.linkedin.databus.core.Checkpoint)9 DbusEvent (com.linkedin.databus.core.DbusEvent)9 ArrayList (java.util.ArrayList)7 DbusEventBuffer (com.linkedin.databus.core.DbusEventBuffer)6 DbusEventsStatisticsCollector (com.linkedin.databus.core.monitoring.mbean.DbusEventsStatisticsCollector)6 IdNamePair (com.linkedin.databus.core.util.IdNamePair)6 HashMap (java.util.HashMap)6 DatabusV2ConsumerRegistration (com.linkedin.databus.client.consumer.DatabusV2ConsumerRegistration)5 DatabusSubscription (com.linkedin.databus.core.data_model.DatabusSubscription)5 MultiConsumerCallback (com.linkedin.databus.client.consumer.MultiConsumerCallback)3 SelectingDatabusCombinedConsumer (com.linkedin.databus.client.consumer.SelectingDatabusCombinedConsumer)3 StreamConsumerCallbackFactory (com.linkedin.databus.client.consumer.StreamConsumerCallbackFactory)3 DatabusStreamConsumer (com.linkedin.databus.client.pub.DatabusStreamConsumer)3 ConsumerCallbackResult (com.linkedin.databus.client.pub.ConsumerCallbackResult)2 ServerInfo (com.linkedin.databus.client.pub.ServerInfo)2 ConsumerCallbackStatsEvent (com.linkedin.databus.client.pub.monitoring.events.ConsumerCallbackStatsEvent)2 UnifiedClientStatsEvent (com.linkedin.databus.client.pub.monitoring.events.UnifiedClientStatsEvent)2