Jetstream Consumers - Creation of Consumers on Stream with replication takes more time #1635
Replies: 4 comments 5 replies
-
Hey. The differences comes from the fact, that replicated stream needs to create a Raft Group and assign nodes for all replicas. Keep in mind that creating 1k streams with 1 consumer on each looks like a pattern that could be improved. |
Beta Was this translation helpful? Give feedback.
-
I'll dig the details later, but it seems that "Consumer Groups", "pinning consumer" could be of some use here for the part when you want to map consumers at runtime? It is something we work on right now. |
Beta Was this translation helpful? Give feedback.
-
Such adhoc single subject stream walks are best done with the Dodext Get API. It can, without consumers, get all messages for a subject one by one (later in matches) https://github.com/nats-io/nats-architecture-and-design/blob/main/adr/ADR-31.md#request Depending on language the implementation may vary but this is the cheapest way to walk just one subject in a stream. |
Beta Was this translation helpful? Give feedback.
-
We are trying to explore the possibilities to implement a work queue solution where we are able to map incoming work items to consumers (who will process the incoming work items and then wait for futher work items). We also came accross and old discussion thread #1635 and associated blog post https://docs.kraudcloud.com/blog/2023/11/22/exclusive-worker-tokens-with-nats/ |
Beta Was this translation helpful? Give feedback.
-
Hello NATS team,
For a prototype, we have deployed a 3 instance NATS cluster ( all 3 instances running on same machine)
We are trying to implement a use case which would need consumers to be dynamically created and deleted on a NATS stream (Stream replication is set to 3).
We observe considerable delay in the Consumer create operation when the stream is replicated. Could you please review the data and suggest how this operation can be optimized?
As a test case, we tried creating 1000 streams with 1 consumer each (ie, 1000 consumers).
A percentile histogram of 1000 Consumer create operation using Golang client API "CreateOrUpdateConsumer" looks as :
If we run the same test without replicating the stream, we see the results as
As seen in the values, we see a huge latency in the create operation when we have replication enabled ( and is set to 3)
the code snippet used for this test is :
Our test bed details are :
Beta Was this translation helpful? Give feedback.
All reactions