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?
source share