Jetstream Out of memory error #526
-
Hello all, I'm attempting to benchmark Jetstream for a computer vision project. Code is below The payload I am testing is an image file of ~0.4 MB I am trying to publish a large number of messages, from multiple Tasks & with the same payload, to the jetstream server at once; However, the server throws the below error "runtime: out of memory: cannot allocate 4194304-byte block (1761312768 in use) after some time I have set the jetstream config as below: I have also tested by changing MaxBytes and MaxMessages. as well as adding a delay before each publish, which seems to help I am trying to determine the root cause of this issue and how to avoid it. From my understanding setting the limits should make Jetstream discard messages once limits are reached, maintaining stream size regardless of volume of messages and speed of publishing Below is the code
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 6 replies
-
you should await the publish calls: var ack = await jetstream.PublishAsync($"{streamName}.picture", ...);
ack.EnsureSuccess(); Edit: JetStream publish works with acknowledgments. clients send a message and wait for a confirmation from the server that it's persisted. with .NET client when you don't await (or not keep track of the returned tasks and throttle in some fashion) you can send messages way faster then they can be persisted. I think that is what you're observing with server queuing up messages internally while waiting for disk IO. I'm not a server expert though, @neilalexander please feel free to add to it or correct me |
Beta Was this translation helpful? Give feedback.
-
@aricart @neilalexander is there a server setting to limit the internal buffer (or something) to avoid OOM errors? |
Beta Was this translation helpful? Give feedback.
-
Just a quick follow up @mtmk could you point me to some good sample applications that use the v2 library? I'm still experiencing issues like slow consumers, "Internal subscription took too long" etc. on the nats-server while running benchmarks I don't know if this has to do with config settings or disposing streams/consumers properly but a good sample application would be really helpful |
Beta Was this translation helpful? Give feedback.
you should await the publish calls:
Edit: JetStream publish works with acknowledgments. clients send a message and wait for a confirmation from the server that it's persisted. with .NET client when you don't await (or not keep track of the returned tasks and throttle in some fashion) you can send messages way faster then they can be persisted.
I think that is what you're observing with server queuing up messages internally while waiting for disk IO. I'm not a server expert though, @neilalexander please feel free to add to it or correct me