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);
}
}
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;
}
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;
}
Aggregations