You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2022/07/06 13:34:53 UTC
[GitHub] [pulsar] eolivelli opened a new issue, #16421: Shared subscription + Batch messages: consumerFlow trigger reading the same messages from storage
eolivelli opened a new issue, #16421:
URL: https://github.com/apache/pulsar/issues/16421
I am doing some testing on Shared subscription and Batch messages with the current Pulsar master.
The behaviour that I am observing is that when you have Batch messages the Consumer is sending flow control messages for more messages that it can handle.
This is how to reproduce the problem:
- write 100.000 messages using batching
- start a Consumer with a Shared subscription (from the beginning of the topic)
- you will see that the PersistentDispatcherMultipleConsumers `consumerFlow` trigger the read of many messages
This is happening because `consumerFlow` calls `readMoreEntries() ` and `readMoreEntries() ` sees that there are messages to be re-delivered, because the consumer still haven't acknowledged them.
This is turn requests the ManagedCursor to read the data from storage.
I have observed this behaviour while working on offloader performances, but it also happens with regular BK based ledgers.
This simple test case reproduces the problem, I append it to this test https://github.com/apache/pulsar/blob/1ba180cbc7490eff6ac6d3a78d61ce7919236c95/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/CreateSubscriptionTest.java#L66
```
@Test
public void testConsumerFlowOnSharedSubscription() throws Exception {
String topic = "persistent://my-property/my-ns/topic" + UUID.randomUUID();
admin.topics().createNonPartitionedTopic(topic);
String subName = "my-sub";
int numMessages = 20_000;
final CountDownLatch count = new CountDownLatch(numMessages);
try (Consumer<byte[]> consumer = pulsarClient.newConsumer()
.subscriptionMode(SubscriptionMode.Durable)
.subscriptionType(SubscriptionType.Shared)
.topic(topic)
.subscriptionName(subName)
.messageListener(new MessageListener<byte[]>() {
@Override
public void received(Consumer<byte[]> consumer, Message<byte[]> msg) {
//log.info("received {} - {}", msg, count.getCount());
consumer.acknowledgeAsync(msg);
count.countDown();
}
})
.subscribe();
Producer<byte[]> producer = pulsarClient
.newProducer()
.blockIfQueueFull(true)
.enableBatching(true)
.topic(topic)
.create()) {
consumer.pause();
byte[] message = "foo".getBytes(StandardCharsets.UTF_8);
List<CompletableFuture<?>> futures = new ArrayList<>();
for (int i = 0; i < numMessages; i++) {
futures.add(producer.sendAsync(message).whenComplete( (id,e) -> {
if (e != null) {
log.error("error", e);
}
}));
if (futures.size() == 1000) {
FutureUtil.waitForAll(futures).get();
futures.clear();
}
}
producer.flush();
consumer.resume();
assertTrue(count.await(20, TimeUnit.SECONDS));
}
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Shared subscription + Batch messages: consumerFlow trigger reading the same messages from storage [pulsar]
Posted by "lhotari (via GitHub)" <gi...@apache.org>.
lhotari commented on issue #16421:
URL: https://github.com/apache/pulsar/issues/16421#issuecomment-2619570906
There's currently an open issue #23900 where the broker cache is always by-passed for replay queue reads, also when `cacheEvictionByMarkDeletedPosition=true` is used. That's addressed by #23903 . The limitation and issue described in this issue (#16421), remains. I have work in progress to address this issue.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] github-actions[bot] commented on issue #16421: Shared subscription + Batch messages: consumerFlow trigger reading the same messages from storage
Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on issue #16421:
URL: https://github.com/apache/pulsar/issues/16421#issuecomment-1207316128
The issue had no activity for 30 days, mark with Stale label.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] eolivelli commented on issue #16421: Shared subscription + Batch messages: consumerFlow trigger reading the same messages from storage
Posted by GitBox <gi...@apache.org>.
eolivelli commented on issue #16421:
URL: https://github.com/apache/pulsar/issues/16421#issuecomment-1177365957
with batch messages we fall into this case:
https://github.com/apache/pulsar/blob/8b1d7a0c894c3124db99302e60e0e523a55dc3b2/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentDispatcherMultipleConsumers.java#L625
basically the dispatcher reads N entries from Storage (BK or Offloader) and the Consumer does not have enough permits, so we are throwing away part of the entries that we read.
Those entries are added to the list of "messages to replay" and so they will be read again from storage next time.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Shared subscription + Batch messages: consumerFlow trigger reading the same messages from storage [pulsar]
Posted by "lhotari (via GitHub)" <gi...@apache.org>.
lhotari closed issue #16421: Shared subscription + Batch messages: consumerFlow trigger reading the same messages from storage
URL: https://github.com/apache/pulsar/issues/16421
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] eolivelli commented on issue #16421: Shared subscription + Batch messages: consumerFlow trigger reading the same messages from storage
Posted by GitBox <gi...@apache.org>.
eolivelli commented on issue #16421:
URL: https://github.com/apache/pulsar/issues/16421#issuecomment-1177708177
I believe that this implementation about `cacheEvictionByMarkDeletedPosition` will also help with this problem, because it won't let the "messages to replay" to be evicted from the cache.
https://github.com/apache/pulsar/pull/14985
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Shared subscription + Batch messages: consumerFlow trigger reading the same messages from storage [pulsar]
Posted by "lhotari (via GitHub)" <gi...@apache.org>.
lhotari commented on issue #16421:
URL: https://github.com/apache/pulsar/issues/16421#issuecomment-3229166740
PIP-430 will address this. One potential workaround is to use `preciseDispatcherFlowControl=true` which will reduce the amount of unnecessary reads when batch messages are used.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] eolivelli commented on issue #16421: Shared subscription + Batch messages: consumerFlow trigger reading the same messages from storage
Posted by GitBox <gi...@apache.org>.
eolivelli commented on issue #16421:
URL: https://github.com/apache/pulsar/issues/16421#issuecomment-1177516197
In order to solve the problem we should not evict from the cache the entries that are still in "messagesToReply", otherwise we will keep reading from BK (or from TieredStorage).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Shared subscription + Batch messages: consumerFlow trigger reading the same messages from storage [pulsar]
Posted by "lhotari (via GitHub)" <gi...@apache.org>.
lhotari commented on issue #16421:
URL: https://github.com/apache/pulsar/issues/16421#issuecomment-2997629173
"PIP-430: Pulsar Broker cache improvements: refactoring eviction and adding a new cache strategy based on expected read count", #24444 will finally address this issue.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] eolivelli commented on issue #16421: Shared subscription + Batch messages: consumerFlow trigger reading the same messages from storage
Posted by GitBox <gi...@apache.org>.
eolivelli commented on issue #16421:
URL: https://github.com/apache/pulsar/issues/16421#issuecomment-1177367198
After doing some testing I have found that the problem is that the ManagedLedger EntryCache is evicted only by taking into account the "readPosition" of the cursor.
But the "messages to replay" are behind the "readPosition", so those entries are evicted from the cache
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] eolivelli commented on issue #16421: Shared subscription + Batch messages: consumerFlow trigger reading the same messages from storage
Posted by GitBox <gi...@apache.org>.
eolivelli commented on issue #16421:
URL: https://github.com/apache/pulsar/issues/16421#issuecomment-1176252645
The problem is here, when you use MessageListener we increase permits of 1, even for Messages that are part of a batch.
https://github.com/apache/pulsar/blob/926834ef8b2b57d3964aa7e9773e6245bcee861c/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ConsumerBase.java#L1087
So the problem is mostly with the MessageListener API, used by pulsar-perf (and also OpenMessaging benchmark)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org