Can I use JetStream KV as cache? #1507
-
I tried to use JetStream KV as cache, but it seems to get worse than even no cache. And Redis goes well in the case. I wonder if my test case is not good (not suitable for the cache-case). The test code is nats-demo/cache |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 9 replies
-
Try setting the KV to memory storage. |
Beta Was this translation helpful? Give feedback.
-
We can be on par with Redis when there is a real network. You can also use KV watchers to have a subset of the KV space in your app, and kept up to date for even faster response times. I disagree with R.I., no reason it can not be very fast IMO. Should make sure direct get acces is on with your KV etc. |
Beta Was this translation helpful? Give feedback.
-
To add a bit more concrete details to the answer above. How you can do a simple NATS and Redis latency comparison using the KV get() operation: NATS setup is Redis setup is just start On a Mac Studio M1-Ultra the NATS benchmark reports almost exactly 24,000 synchronous operations per second meaning an average latency of 41.666 micro-seconds per get. The redis benchmark reports an average of 18 micro-seconds. These test are between processes on the same host over the loopback interface, in real-life deployments however client applications and NATS or Redis servers are going to talk to each other over the network, and that latency due to the network is going to be a number of times larger than the latency of NATS/Redis as measured above (e.g. in the hundreds of micro-seconds over a fast LAN) such that the 20 or so micro-seconds of difference in latency between NATS and Redis becomes relatively insignificant. |
Beta Was this translation helpful? Give feedback.
We can be on par with Redis when there is a real network.
You can also use KV watchers to have a subset of the KV space in your app, and kept up to date for even faster response times.
I disagree with R.I., no reason it can not be very fast IMO.
Should make sure direct get acces is on with your KV etc.