Cassandra c # driver memory leak

Using the cassandra.net driver, we encounter the following problem: When inserting a large number of rows with parameterized INSERT, the memory usage of the application is constantly growing:

class Program { static Cluster cluster = Cluster.Builder() .AddContactPoints(ConfigurationManager.AppSettings["address"]) .Build(); static Session session = cluster .Connect(ConfigurationManager.AppSettings["keyspace"]); static int counter = 0; static void Main(string[] args) { for (int i = 0; i < 50; i++) { new Thread(() => { while (true) { new Person() { Name = Interlocked.Increment(ref counter).ToString(), ID = Guid.NewGuid(), Data = new byte[4096], }.Save(session); } }).Start(); } Console.ReadLine(); } } class Person { public Guid ID { get; set; } public string Name { get; set; } public byte[] Data { get; set; } public void Save(Session session) { Stopwatch w = Stopwatch.StartNew(); session.Execute(session.Prepare( "INSERT INTO Person(id, name, data) VALUES(?, ?, ?);") .Bind(this.ID, this.Name, this.Data)); Console.WriteLine("{1} saved in {0} ms", w.Elapsed.TotalMilliseconds, this.Name); } } 

In accordance with the created memory dump, the managed heap contains a huge number of small byte arrays (most of them are generation 2), which can be traced to methods for converting bytes in cassandro (InvConvert *) to the internal TypeInterpreter class.

Do you have any tips or ideas on how we could get rid of this problem?

+4
source share
3 answers

For everyone who comes across this. I have memory problems when creating a lot of Cassandra.ISession , although I managed it correctly using the using statement. Changing my code to reuse a single ISession like fixing it. I do not know if this is the best solution.

+4
source

You create a prepared state for each record that you are trying to insert. Try to create a prepared state once when creating a session.

+1
source

try using the utility if possible. Perhaps your Garbace collection cannot clear them. You should also write to the Cassandra developers. Looks like a mistake to me.

Does this help you?

0
source

Source: https://habr.com/ru/post/1500337/


All Articles