Giter Club home page Giter Club logo

Comments (8)

gcolliso avatar gcolliso commented on August 24, 2024 1

Transferring to nats.go repo

from nats.go.

piotrpio avatar piotrpio commented on August 24, 2024

Hey @b04112106, depending on what you need there are few options to achieve automatic cleanup:

  • InactiveThreshold setting on ConsumerConfig - 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.

b04112106 avatar b04112106 commented on August 24, 2024

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.

Jarema avatar Jarema commented on August 24, 2024

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.

b04112106 avatar b04112106 commented on August 24, 2024

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.

Jarema avatar Jarema commented on August 24, 2024

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.

b04112106 avatar b04112106 commented on August 24, 2024

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.

b04112106 avatar b04112106 commented on August 24, 2024

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

  1. Why does it take so much memory to AddConsumer?
  2. Why does it NOT release memory after context deadline exceeded?
  3. If I add Durable in consumer config, would it possibly be the solution to this issue?

from nats.go.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.