use of org.apache.pulsar.common.policies.data.SubscriptionStats in project incubator-pulsar by apache.
the class PartitionedTopicStatsTest method testPartitionedTopicStats.
@Test
public void testPartitionedTopicStats() {
PartitionedTopicStats partitionedTopicStats = new PartitionedTopicStats();
partitionedTopicStats.msgRateIn = 1;
partitionedTopicStats.msgThroughputIn = 1;
partitionedTopicStats.msgRateOut = 1;
partitionedTopicStats.msgThroughputOut = 1;
partitionedTopicStats.averageMsgSize = 1;
partitionedTopicStats.storageSize = 1;
partitionedTopicStats.publishers.add(new PublisherStats());
partitionedTopicStats.subscriptions.put("test_ns", new SubscriptionStats());
partitionedTopicStats.replication.put("test_ns", new ReplicatorStats());
partitionedTopicStats.metadata.partitions = 1;
partitionedTopicStats.partitions.put("test", partitionedTopicStats);
partitionedTopicStats.reset();
assertEquals(partitionedTopicStats.msgRateIn, 0.0);
assertEquals(partitionedTopicStats.msgThroughputIn, 0.0);
assertEquals(partitionedTopicStats.msgRateOut, 0.0);
assertEquals(partitionedTopicStats.msgThroughputOut, 0.0);
assertEquals(partitionedTopicStats.averageMsgSize, 0.0);
assertEquals(partitionedTopicStats.storageSize, 0);
assertEquals(partitionedTopicStats.publishers.size(), 0);
assertEquals(partitionedTopicStats.subscriptions.size(), 0);
assertEquals(partitionedTopicStats.replication.size(), 0);
assertEquals(partitionedTopicStats.metadata.partitions, 0);
assertEquals(partitionedTopicStats.partitions.size(), 0);
}
use of org.apache.pulsar.common.policies.data.SubscriptionStats in project incubator-pulsar by apache.
the class PersistentQueueE2ETest method testUnackedCountWithRedeliveries.
@Test
public void testUnackedCountWithRedeliveries() throws Exception {
final String topicName = "persistent://prop/use/ns-abc/testUnackedCountWithRedeliveries";
final String subName = "sub3";
final int numMsgs = 10;
Producer<byte[]> producer = pulsarClient.newProducer().topic(topicName).create();
ConsumerBuilder<byte[]> consumerBuilder = pulsarClient.newConsumer().topic(topicName).subscriptionName(subName).receiverQueueSize(10).subscriptionType(SubscriptionType.Shared);
ConsumerImpl<byte[]> consumer1 = (ConsumerImpl<byte[]>) consumerBuilder.subscribe();
for (int i = 0; i < numMsgs; i++) {
producer.send(("hello-" + i).getBytes());
}
Set<MessageId> c1_receivedMessages = new HashSet<>();
// C-1 gets all messages but doesn't ack
for (int i = 0; i < numMsgs; i++) {
c1_receivedMessages.add(consumer1.receive().getMessageId());
}
// C-2 will not get any message initially, since everything went to C-1 already
Consumer<byte[]> consumer2 = consumerBuilder.subscribe();
// Trigger C-1 to redeliver everything, half will go C-1 again and the other half to C-2
consumer1.redeliverUnacknowledgedMessages(c1_receivedMessages);
// Consumer 2 will also receive all message but not ack
for (int i = 0; i < numMsgs; i++) {
consumer2.receive();
}
for (MessageId msgId : c1_receivedMessages) {
consumer1.acknowledge(msgId);
}
PersistentTopicStats stats = admin.persistentTopics().getStats(topicName);
// Unacked messages count should be 0 for both consumers at this point
SubscriptionStats subStats = stats.subscriptions.get(subName);
assertEquals(subStats.msgBacklog, 0);
for (ConsumerStats cs : subStats.consumers) {
assertEquals(cs.unackedMessages, 0);
}
producer.close();
consumer1.close();
consumer2.close();
admin.persistentTopics().delete(topicName);
}
use of org.apache.pulsar.common.policies.data.SubscriptionStats in project incubator-pulsar by apache.
the class NonPersistentTopicTest method testTopicStats.
/**
* verifies that broker is capturing topic stats correctly
*/
@Test
public void testTopicStats() throws Exception {
final String topicName = "non-persistent://my-property/use/my-ns/unacked-topic";
final String subName = "non-persistent";
final int timeWaitToSync = 100;
NonPersistentTopicStats stats;
SubscriptionStats subStats;
Consumer<byte[]> consumer = pulsarClient.newConsumer().topic(topicName).subscriptionType(SubscriptionType.Shared).subscriptionName(subName).subscribe();
Thread.sleep(timeWaitToSync);
NonPersistentTopic topicRef = (NonPersistentTopic) pulsar.getBrokerService().getTopicReference(topicName);
assertNotNull(topicRef);
rolloverPerIntervalStats(pulsar);
stats = topicRef.getStats();
subStats = stats.getSubscriptions().values().iterator().next();
// subscription stats
assertEquals(stats.getSubscriptions().keySet().size(), 1);
assertEquals(subStats.consumers.size(), 1);
Producer<byte[]> producer = pulsarClient.newProducer().topic(topicName).create();
Thread.sleep(timeWaitToSync);
int totalProducedMessages = 100;
for (int i = 0; i < totalProducedMessages; i++) {
String message = "my-message-" + i;
producer.send(message.getBytes());
}
Thread.sleep(timeWaitToSync);
rolloverPerIntervalStats(pulsar);
stats = topicRef.getStats();
subStats = stats.getSubscriptions().values().iterator().next();
assertTrue(subStats.msgRateOut > 0);
assertEquals(subStats.consumers.size(), 1);
assertTrue(subStats.msgThroughputOut > 0);
// consumer stats
assertTrue(subStats.consumers.get(0).msgRateOut > 0.0);
assertTrue(subStats.consumers.get(0).msgThroughputOut > 0.0);
assertEquals(subStats.msgRateRedeliver, 0.0);
producer.close();
consumer.close();
}
use of org.apache.pulsar.common.policies.data.SubscriptionStats in project incubator-pulsar by apache.
the class BrokerServiceTest method testBrokerServicePersistentTopicStats.
@Test
public void testBrokerServicePersistentTopicStats() throws Exception {
final String topicName = "persistent://prop/use/ns-abc/successTopic";
final String subName = "successSub";
PersistentTopicStats stats;
SubscriptionStats subStats;
Consumer<byte[]> consumer = pulsarClient.newConsumer().topic(topicName).subscriptionName(subName).subscribe();
Thread.sleep(ASYNC_EVENT_COMPLETION_WAIT);
PersistentTopic topicRef = (PersistentTopic) pulsar.getBrokerService().getTopicReference(topicName);
assertNotNull(topicRef);
rolloverPerIntervalStats();
stats = topicRef.getStats();
subStats = stats.subscriptions.values().iterator().next();
// subscription stats
assertEquals(stats.subscriptions.keySet().size(), 1);
assertEquals(subStats.msgBacklog, 0);
assertEquals(subStats.consumers.size(), 1);
Producer<byte[]> producer = pulsarClient.newProducer().topic(topicName).create();
Thread.sleep(ASYNC_EVENT_COMPLETION_WAIT);
for (int i = 0; i < 10; i++) {
String message = "my-message-" + i;
producer.send(message.getBytes());
}
Thread.sleep(ASYNC_EVENT_COMPLETION_WAIT);
rolloverPerIntervalStats();
stats = topicRef.getStats();
subStats = stats.subscriptions.values().iterator().next();
// publisher stats
assertEquals(subStats.msgBacklog, 10);
assertEquals(stats.publishers.size(), 1);
assertTrue(stats.publishers.get(0).msgRateIn > 0.0);
assertTrue(stats.publishers.get(0).msgThroughputIn > 0.0);
assertTrue(stats.publishers.get(0).averageMsgSize > 0.0);
assertNotNull(stats.publishers.get(0).clientVersion);
// aggregated publish stats
assertEquals(stats.msgRateIn, stats.publishers.get(0).msgRateIn);
assertEquals(stats.msgThroughputIn, stats.publishers.get(0).msgThroughputIn);
double diff = stats.averageMsgSize - stats.publishers.get(0).averageMsgSize;
assertTrue(Math.abs(diff) < 0.000001);
// consumer stats
assertTrue(subStats.consumers.get(0).msgRateOut > 0.0);
assertTrue(subStats.consumers.get(0).msgThroughputOut > 0.0);
// aggregated consumer stats
assertEquals(subStats.msgRateOut, subStats.consumers.get(0).msgRateOut);
assertEquals(subStats.msgThroughputOut, subStats.consumers.get(0).msgThroughputOut);
assertEquals(stats.msgRateOut, subStats.consumers.get(0).msgRateOut);
assertEquals(stats.msgThroughputOut, subStats.consumers.get(0).msgThroughputOut);
assertNotNull(subStats.consumers.get(0).clientVersion);
Message<byte[]> msg;
for (int i = 0; i < 10; i++) {
msg = consumer.receive();
consumer.acknowledge(msg);
}
consumer.close();
Thread.sleep(ASYNC_EVENT_COMPLETION_WAIT);
rolloverPerIntervalStats();
stats = topicRef.getStats();
subStats = stats.subscriptions.values().iterator().next();
assertEquals(subStats.msgBacklog, 0);
}
use of org.apache.pulsar.common.policies.data.SubscriptionStats in project incubator-pulsar by apache.
the class PersistentSubscription method getStats.
public SubscriptionStats getStats() {
SubscriptionStats subStats = new SubscriptionStats();
Dispatcher 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.unackedMessages += consumerStats.unackedMessages;
});
}
subStats.type = getType();
if (SubType.Shared.equals(subStats.type)) {
if (dispatcher instanceof PersistentDispatcherMultipleConsumers) {
subStats.unackedMessages = ((PersistentDispatcherMultipleConsumers) dispatcher).getTotalUnackedMessages();
subStats.blockedSubscriptionOnUnackedMsgs = ((PersistentDispatcherMultipleConsumers) dispatcher).isBlockedDispatcherOnUnackedMsgs();
}
}
subStats.msgBacklog = getNumberOfEntriesInBacklog();
subStats.msgRateExpired = expiryMonitor.getMessageExpiryRate();
return subStats;
}
Aggregations