Open 7Kronos opened 1 month ago
Each call to consumer.info()
does an API request to fetch the latest info. This has quite a large overhead when done for every message and can be simplified by getting the pending count directly from the message metadata:
if (msg.info.pending === 0) {
break
}
Could you check with that change?
@MauriceVanVeen
That's a good point, figured it out reading examples earlier and tried already.
consumer.info()
was adding ~2 ms
I made a POC with rudimentary code replacing KV and JS with mongodb collections but with the same code base and some indexes.
I know the driver is optimized and enqueue changes but I added write concern to 1, so I have an ack from the MongoDB instance, effectively throttling to prevent the server from overwhelming.
I got these results :
Tell me if I can help in any way.
Observed behavior
We have built a pipeline that, from various information sources, allows us to produce an entity whose data is composed on the fly.
The messages are stored in a stream with
Per Subject Messages Limit 1
and incoming messages have this subject templateproduct.{sku}.{source}
This allows us to maintain in NATS the latest information from a source for a given product.The pipeline subscribes to
product.>
to trigger the composition of a product sheet, which it stores in a KV bucket, a concept similar to an event store. During this phase, the pipeline must collect all the messages concerning a SKUproduct.{sku}.>
To do this, an ephemeral consumer is created to collect these messages and then deleted :This is called each time for each message in the stream.
With a base of 50,000 messages, this phase takes an average of 7ms, which is acceptable at this stage.
However, during testing 3,500,000 messages this phase takes an average of 420ms, which represents a significant performance hit.
It is important to note that no publication occurs in parallel. The messages were loaded in advance before the test was triggered.
Disk I/O is pretty low
Expected behavior
We except a smaller performance hit.
Server and client version
The server is standalone 2.10.18
Javascript client 2.28.2
Host environment
Docker version 26.0.2 Volume driver : local
Steps to reproduce
No response