Search in sources :

Example 1 with NonPersistentSubscriptionStats

use of org.apache.pulsar.common.policies.data.NonPersistentSubscriptionStats in project incubator-pulsar by apache.

the class NonPersistentTopicTest method testMsgDropStat.

/**
 * Verifies msg-drop stats
 *
 * @throws Exception
 */
@Test
public void testMsgDropStat() throws Exception {
    int defaultNonPersistentMessageRate = conf.getMaxConcurrentNonPersistentMessagePerConnection();
    try {
        final String topicName = "non-persistent://my-property/use/my-ns/stats-topic";
        // restart broker with lower publish rate limit
        conf.setMaxConcurrentNonPersistentMessagePerConnection(1);
        stopBroker();
        startBroker();
        Consumer<byte[]> consumer = pulsarClient.newConsumer().topic(topicName).subscriptionName("subscriber-1").receiverQueueSize(1).subscribe();
        Consumer<byte[]> consumer2 = pulsarClient.newConsumer().topic(topicName).subscriptionName("subscriber-2").receiverQueueSize(1).subscriptionType(SubscriptionType.Shared).subscribe();
        ProducerImpl<byte[]> producer = (ProducerImpl<byte[]>) pulsarClient.newProducer().topic(topicName).create();
        String firstTimeConnected = producer.getConnectedSince();
        ExecutorService executor = Executors.newFixedThreadPool(5);
        byte[] msgData = "testData".getBytes();
        final int totalProduceMessages = 200;
        CountDownLatch latch = new CountDownLatch(totalProduceMessages);
        for (int i = 0; i < totalProduceMessages; i++) {
            executor.submit(() -> {
                producer.sendAsync(msgData).handle((msg, e) -> {
                    latch.countDown();
                    return null;
                });
            });
        }
        latch.await();
        NonPersistentTopic topic = (NonPersistentTopic) pulsar.getBrokerService().getTopic(topicName).get();
        pulsar.getBrokerService().updateRates();
        NonPersistentTopicStats stats = topic.getStats();
        NonPersistentPublisherStats npStats = stats.getPublishers().get(0);
        NonPersistentSubscriptionStats sub1Stats = stats.getSubscriptions().get("subscriber-1");
        NonPersistentSubscriptionStats sub2Stats = stats.getSubscriptions().get("subscriber-2");
        assertTrue(npStats.msgDropRate > 0);
        assertTrue(sub1Stats.msgDropRate > 0);
        assertTrue(sub2Stats.msgDropRate > 0);
        // make sure producer connection not disconnected due to unordered ack
        assertEquals(firstTimeConnected, producer.getConnectedSince());
        producer.close();
        consumer.close();
        consumer2.close();
        executor.shutdown();
    } finally {
        conf.setMaxConcurrentNonPersistentMessagePerConnection(defaultNonPersistentMessageRate);
    }
}
Also used : ProducerImpl(org.apache.pulsar.client.impl.ProducerImpl) NonPersistentSubscriptionStats(org.apache.pulsar.common.policies.data.NonPersistentSubscriptionStats) ExecutorService(java.util.concurrent.ExecutorService) NonPersistentTopicStats(org.apache.pulsar.common.policies.data.NonPersistentTopicStats) NonPersistentPublisherStats(org.apache.pulsar.common.policies.data.NonPersistentPublisherStats) CountDownLatch(java.util.concurrent.CountDownLatch) NonPersistentTopic(org.apache.pulsar.broker.service.nonpersistent.NonPersistentTopic) Test(org.testng.annotations.Test) ZookeeperServerTest(org.apache.pulsar.zookeeper.ZookeeperServerTest)

Example 2 with NonPersistentSubscriptionStats

use of org.apache.pulsar.common.policies.data.NonPersistentSubscriptionStats in project incubator-pulsar by apache.

the class NonPersistentTopic method getStats.

public NonPersistentTopicStats getStats() {
    NonPersistentTopicStats stats = new NonPersistentTopicStats();
    ObjectObjectHashMap<String, PublisherStats> remotePublishersStats = new ObjectObjectHashMap<String, PublisherStats>();
    producers.forEach(producer -> {
        NonPersistentPublisherStats publisherStats = (NonPersistentPublisherStats) producer.getStats();
        stats.msgRateIn += publisherStats.msgRateIn;
        stats.msgThroughputIn += publisherStats.msgThroughputIn;
        if (producer.isRemote()) {
            remotePublishersStats.put(producer.getRemoteCluster(), publisherStats);
        } else {
            stats.getPublishers().add(publisherStats);
        }
    });
    stats.averageMsgSize = stats.msgRateIn == 0.0 ? 0.0 : (stats.msgThroughputIn / stats.msgRateIn);
    subscriptions.forEach((name, subscription) -> {
        NonPersistentSubscriptionStats subStats = subscription.getStats();
        stats.msgRateOut += subStats.msgRateOut;
        stats.msgThroughputOut += subStats.msgThroughputOut;
        stats.getSubscriptions().put(name, subStats);
    });
    replicators.forEach((cluster, replicator) -> {
        NonPersistentReplicatorStats ReplicatorStats = replicator.getStats();
        // Add incoming msg rates
        PublisherStats pubStats = remotePublishersStats.get(replicator.getRemoteCluster());
        if (pubStats != null) {
            ReplicatorStats.msgRateIn = pubStats.msgRateIn;
            ReplicatorStats.msgThroughputIn = pubStats.msgThroughputIn;
            ReplicatorStats.inboundConnection = pubStats.address;
            ReplicatorStats.inboundConnectedSince = pubStats.connectedSince;
        }
        stats.msgRateOut += ReplicatorStats.msgRateOut;
        stats.msgThroughputOut += ReplicatorStats.msgThroughputOut;
        stats.getReplication().put(replicator.getRemoteCluster(), ReplicatorStats);
    });
    return stats;
}
Also used : NonPersistentSubscriptionStats(org.apache.pulsar.common.policies.data.NonPersistentSubscriptionStats) NonPersistentReplicatorStats(org.apache.pulsar.common.policies.data.NonPersistentReplicatorStats) NonPersistentTopicStats(org.apache.pulsar.common.policies.data.NonPersistentTopicStats) NonPersistentPublisherStats(org.apache.pulsar.common.policies.data.NonPersistentPublisherStats) PublisherStats(org.apache.pulsar.common.policies.data.PublisherStats) NonPersistentPublisherStats(org.apache.pulsar.common.policies.data.NonPersistentPublisherStats) ObjectObjectHashMap(com.carrotsearch.hppc.ObjectObjectHashMap)

Example 3 with NonPersistentSubscriptionStats

use of org.apache.pulsar.common.policies.data.NonPersistentSubscriptionStats in project incubator-pulsar by apache.

the class NonPersistentSubscription method getStats.

public NonPersistentSubscriptionStats getStats() {
    NonPersistentSubscriptionStats subStats = new NonPersistentSubscriptionStats();
    NonPersistentDispatcher dispatcher = this.dispatcher;
    if (dispatcher != null) {
        dispatcher.getConsumers().forEach(consumer -> {
            ConsumerStats consumerStats = consumer.getStats();
            subStats.consumers.add(consumerStats);
            subStats.msgRateOut += consumerStats.msgRateOut;
            subStats.msgThroughputOut += consumerStats.msgThroughputOut;
            subStats.msgRateRedeliver += consumerStats.msgRateRedeliver;
        });
    }
    subStats.type = getType();
    subStats.msgDropRate = dispatcher.getMesssageDropRate().getRate();
    return subStats;
}
Also used : NonPersistentSubscriptionStats(org.apache.pulsar.common.policies.data.NonPersistentSubscriptionStats) ConsumerStats(org.apache.pulsar.common.policies.data.ConsumerStats)

Aggregations

NonPersistentSubscriptionStats (org.apache.pulsar.common.policies.data.NonPersistentSubscriptionStats)3 NonPersistentPublisherStats (org.apache.pulsar.common.policies.data.NonPersistentPublisherStats)2 NonPersistentTopicStats (org.apache.pulsar.common.policies.data.NonPersistentTopicStats)2 ObjectObjectHashMap (com.carrotsearch.hppc.ObjectObjectHashMap)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutorService (java.util.concurrent.ExecutorService)1 NonPersistentTopic (org.apache.pulsar.broker.service.nonpersistent.NonPersistentTopic)1 ProducerImpl (org.apache.pulsar.client.impl.ProducerImpl)1 ConsumerStats (org.apache.pulsar.common.policies.data.ConsumerStats)1 NonPersistentReplicatorStats (org.apache.pulsar.common.policies.data.NonPersistentReplicatorStats)1 PublisherStats (org.apache.pulsar.common.policies.data.PublisherStats)1 ZookeeperServerTest (org.apache.pulsar.zookeeper.ZookeeperServerTest)1 Test (org.testng.annotations.Test)1