Comments (8)
Transferring to nats.go repo
from nats.go.
Hey @b04112106, depending on what you need there are few options to achieve automatic cleanup:
-
InactiveThreshold
setting onConsumerConfig
- setting this will instruct the server to cleanup the consumer if it has been inactive for the specified duration. A consumer is considered inactive if there are no pending pull requests (for pull consumers) or to interest detected on deliver subject (for push consumers) - not if there are no messages to be delivered. For durable consumers, by default this is not set so the consumers will never get cleaned up. -
If you also want to prevent recovering consumer after server restart and you don't care about the messages you could also use a in-memory consumer by setting
MemoryStorage
on config. It is important to note that with in memory consumer it will be lost as soon as your nats-server process is terminated.
Let me know if this answers your question.
from nats.go.
Hi @piotrpio , thank you for the recommandation!! It helps a lot and is precisely what I want. I choose to use memory storage but am afraid of running out of memory. The size of my jetstream is about 14GB and # of consumers is about 6. When I try to AddConsumer
, the memory usage climbs up to 6GB. Is it normal? I'm still trying to avoid such situation.
update: after AddConsumer
I use
js.PullSubscribe("", "", nats.Bind(streamName, consumerName))
And I found that AddConsumer
itself allocate lots of memory.
from nats.go.
Consumers does not take much space themselves. They do not store messages. Stream does.
However, in Interests based streams, consumers can affext number of messages in the stream.
Can you share your stream config?
We would also need info about stream content to answer the question if it's normal to have few gigabyes of memory allocated.
from nats.go.
Hi @Jarema , thank you for the reply and here is my stream config!
SystemStream = nats.StreamConfig{
Name: name,
Subjects: []string{name + ".>"},
}
The stream content is a struct generated by protobuf. The size of message varies from 10^1 KB to 160 KB and it depends on the length of slice. I've already had 1,400,000 messages and the total size is 14 gigabytes.
I use pyroscope to monitor the usage of memory and found that if I only call go natsServer.Start()
to run the nats server, the size of memory allocated does not grow rapidly. However, after I call AddConsumer
or Fetch
, allocated memory grows. The peak is 22 GB over 32 GB.
from nats.go.
What verison of nats-server
are you running?
The memory usage depends a lot on traffic, cluster setup, and a lot of other factors.
Could you share some context on your setup?
I realized I didn't answer how to manage consumers. You should not delete your JetStream
files, but rather delete the consumer from API.
from nats.go.
The version of nats-server is 2.10.0
. The server is run in container while the client connect from the same container as well. Actually, client connects to localhost.
I didn't delete JetStream
files nor consumers. I call AddConsumer
after the connection is established. There are about 30 consumers. I just doubt that because all of these consumer needs to fetch message from the JetStream
and the amount of allocated memory would only go down after gc mechanism of golang is triggerred. Does it make sense?
from nats.go.
After some experiments, we found that the memory usage peak is due to repeatedly AddConsumer Failed
. In our implementation, we try to AddConsumer
in our Service
. Service could be considered a for-loop to run a func() error
and will restart when the function returns an error. The interval between the startup and the end of service varies from 0.1 seconds to 102.4 seconds. Each time the service function fails, we double the interval and up to 102.4 seconds.
The large size of JetStream seems to increase the time consumption of AddConsumer
. Our new confusion is
- Why does it take so much memory to
AddConsumer
? - Why does it NOT release memory after context deadline exceeded?
- If I add
Durable
in consumer config, would it possibly be the solution to this issue?
from nats.go.
Related Issues (20)
- Panic when creating jet stream consumer on wildcard stream HOT 8
- Add checks for empty response in JetStream API calls HOT 2
- Object store publishes chunks without using domain in subject HOT 4
- add new encoder interface with less allocations HOT 4
- Memory leak in readMIMEHeader HOT 4
- add `FetchContext` FetchOpt
- Add `KeysWithFilter` methods to KV interface HOT 3
- panic: interface conversion: jetstream.Consumer is nil, not *jetstream.pullConsumer HOT 1
- jetstream.PublishMsgAsync panic
- Using Fetch() with and OrderedConsumer and a delivery policy of DeliverLastPerSubjectPolicy returns incorrect results HOT 1
- Publish RetryAttempt and RetryWait not working as expected HOT 9
- Client logs unmarshal errors HOT 9
- Make JS Consumer deletion on Unsubscribe() / Drain() optional HOT 1
- JetStream ConsumerContext `Drain` function not waiting for in flight requests to be done processing HOT 6
- NEW NATS API Drain for durable consumer HOT 15
- Micro does not register service with Nats. HOT 1
- `PublishAsync` Retry Mechanism Not Working as Expected HOT 5
- Failed to create OrderedConsumer HOT 3
- packets lost: subscribe to more topics and get message packets quickly. The first message packet of some topics is lost. HOT 4
- How to get the number of active user subscriptions for the current topic, not consumers
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nats.go.