You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While testing the NATS KV store, I was surprised to find out that reading the contents of a bucket was an order of magnitude slower than reading an individual key.
Since its an aggregate operation, I did expect it to be slower, but not by this significant of a margin.
iex(1)>Gnat.Jetstream.API.KV.put_value(:cluster_nats,"example","foo","bar"):ok# Reading a value single digit millisecondsiex(2)>:timer.tc(fn->Gnat.Jetstream.API.KV.get_value(:cluster_nats,"example","foo")end,:millisecond){4,"bar"}# Reading the contents of a bucket is always at least 100msiex(3)>:timer.tc(fn->Gnat.Jetstream.API.KV.contents(:cluster_nats,"example")end,:millisecond){134,{:ok,%{"foo"=>"bar"}}}
@brandynbennett I think we talked about this back when we first introduced KV functionality when jetstream was a separate library. Do you remember any details about this behavior?
I think we could switch this to use the PullConsumer API so we will know when we've reached the end of the stream and we can eliminate the 100ms wait
@mmmries Sorry, I don't remember the details of this 100ms minimum. Looks like we're using a regular Consumer for the value of that contents function. Maybe there's a way to configure that or use the PullConsumer if that works smoother.
Problem
While testing the NATS KV store, I was surprised to find out that reading the contents of a bucket was an order of magnitude slower than reading an individual key.
Since its an aggregate operation, I did expect it to be slower, but not by this significant of a margin.
Upon further inspection, it appears that this is a limitation of the client implementation, where it will always wait a minimum of 100ms from the consumer before returning https://github.com/nats-io/nats.ex/blob/v1.9.0/lib/gnat/jetstream/api/kv.ex#L263
Possible Solutions
I am happy to submit a PR but I wanted to start a conversation first
The text was updated successfully, but these errors were encountered: