Hi everyone, thanks in advance for your responses, this is my first post and I am a beginner using this amazing database engine:
I have published an application to production enviroment in my company, We use an App Service from Windows Azure and I realized that the service started to have a high memory usage, we scale out our service to more instances but it was not enough,
our main approach is save lots of information daily for that reason we need to have a high availability.
In summary, our save function is something like this:
public void Save(T entity)
{
try
{
string insertQuery = SwCqlQueryBuilder.GenerateInsertQuery(entity, _conn._session.Keyspace, _table.ToString());
_conn._session.Execute(insertQuery);
}
catch (Exception)
{
}
}
I debugged the Cassandra dll and I found a class called MapperFactory.cs which save some kind of cache Dictionaries;
private readonly ConcurrentDictionary<Tuple<Type, string>, Delegate> _mapperFuncCache;
private readonly ConcurrentDictionary<Tuple<Type, string>, Delegate> _valueCollectorFuncCache;
Also, there is a function called GetMappers() which is executed every time we call the execute method from the session object:
public Func<Row, T> GetMapper<T>(string cql, RowSet rows)
{
Tuple<Type, string> key = Tuple.Create(typeof(T), cql);
Delegate mapperFunc = _mapperFuncCache.GetOrAdd(key, _ => CreateMapper<T>(rows));
return (Func<Row, T>)mapperFunc;
}
The problem origin was the _mapperFunctCache because it store every "insert query" even if it's not a prepared statement then that dictionary started to increase consuming all the memory,
The temporary solution was clean periodically the dictionary then our memory consumption decreased, I would like to ask for some help in this context:
• Is it necessary use prepared statements as a rule?
• What would you recommend? What are we doing wrong?
• Is it could be considered as a bug in the cassandra dll?
Thanks in advance and regards.