Hi folks, I have a question about the cost of Key_...
# general
z
Hi folks, I have a question about the cost of Key_Shared subscriptions. Suppose I have a topic, and I create two Key_Shared subscriptions. The first has only one consumer, and the second has two. Does the second one incur twice as many reads from BookKeeper as the first?
🙌 1
d
Is the topic partitioned or not?
z
I had in mind no partitioning, but if that changes the answer I'd be interested to hear about it as well.
d
Actually, it changes it quite a bit. But let’s stick with a single partition topic, 2 different subscriptions, and 3 consumers. If the subscriptions are “in sync” in terms of message consumption, then the answer is no.
This is due to the caching layers that exist on both the broker (which both subscriptions are connecting to due to topic assignment) and at the BookKeeper layer, in the read cache.
If the subscriptions are all caught up, then all consumers will be served messages directly from the broker cache. This is true for both subscriptions and the consumers. If the consumers are catching up, then they will need to read messages from BookKeeper. When that happens, the ledger is read from disk once, and stored in an in-memory read cache. Since both subscriptions are reading these same messages (because they are in-sync), then all consumers will be served messages from the read-cache.
It gets more complicated when the subscriptions are not “in sync,” but essentially, the different subscriptions would force different ledgers into the read cache and read from there. But since these are different ledgers, they could be served by different bookies entirely.
z
Okay, that's a very helpful description, thank you. So to check my understanding, suppose there's just a single shared_key subscription with two consumers for a topic that's never been read (so all initial data requests cause cache misses). I'm guessing the memory consumption on the Pulsar broker will be proportional to the distance between the latest consumed message for each consumer (due to the read caching). And regardless of that distance, the number of reads from BookKeeper will be the same (enough to read the whole ledger once).
d
One point of clarification. The cache on the broker is used to store recently published messages, not cache misses. The goal is to minimize read latencies for consumers who are “caught up,” as these tend to be more time-sensitive use cases.
All the ledgers must be read from disk and stored in the bookie’s read cache.
z
Ah okay, this is very interesting. Thank you again for the help, it's much appreciated. I've read through the public docs a couple of times and was still a bit confused. So is it safe to assume that consuming in parallel using a Key_Shared subscription is not going to double the amount of work being done (when the consumers are both progressing at approximately the same rate)?
d
Correct. There should be multiple reads of the same ledger from the read cache across subscriptions
z
Awesome. Thank you again for the help!