Bringing together the Apache Cassandra experts from the community and DataStax.

Want to learn? Have a question? Want to share your expertise? You are in the right place!

Not sure where to begin? Getting Started

 

question

cvois1 avatar image
cvois1 asked Erick Ramirez edited

Fuite mémoire avec l'API C# Fetch

L'api C# Fetch autorise des requétes CQL. Il me semble qu'un appel avec CQL en paramètre ait une grosse fuite mémoire :

Code avec fuite mémoire:

var noSqlQry = string.Format("SELECT * FROM item_by_tx WHERE tx_id='{0}' AND item_type={1}", item.TxId, item.ItemType);
if (_logger.IsEnabled(LogLevel.Trace)) _logger.LogTrace("Exec NoSQL query: {0}", noSqlQry);

itemByTx = _mapper.Fetch<ItemByTx>(Cql.New(noSqlQry))
  .OrderBy(x => x.ItemStamp)
  .LastOrDefault(x => x.ItemStamp >= start && x.ItemStamp < end); 

Code sans fuite mémoire:

IEnumerable<ItemByTx> items = _mapper.Fetch<ItemByTx>("SELECT * FROM item_by_tx WHERE tx_id= ? AND item_type= ?", item.TxId, item.ItemType)
  .Where(x => x.ItemStamp >= start && x.ItemStamp < end)
  .OrderBy(x => x.ItemStamp);
csharp driver
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

1 Answer

Erick Ramirez avatar image
Erick Ramirez answered Erick Ramirez edited

Il est possible que le problème soit avec string.Format().

Si vous remplacez:

Cql.New(noSqlQry)

par:

Cql.New("SELECT * FROM item_by_tx WHERE tx_id= ? AND item_type= ?", item.TxId, item.ItemType)

avez-vous toujours le même problème?

Crédit: Merci à João Reis (développeur de driver) pour la solution.

2 comments Share
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Je confirme votre hypothèse concernant l'origine du problème :

// No Memory Leak
IEnumerable<ItemByTx> items = _mapper.Fetch<ItemByTx>("SELECT * FROM item_by_tx WHERE tx_id= ? AND item_type= ?", item.TxId, item.ItemType)
  .Where(x => x.ItemStamp >= start && x.ItemStamp < end)
  .OrderBy(x => x.ItemStamp)
// No memory Leak
IEnumerable<ItemByTx> items = _mapper.Fetch<ItemByTx>(Cql.New("SELECT * FROM item_by_tx WHERE tx_id= ? AND item_type= ?", item.TxId, item.ItemType))
  .Where(x => x.ItemStamp >= start && x.ItemStamp < end)
  .OrderBy(x => x.ItemStamp);

Merci à vous !

0 Likes 0 ·

De rien. Génial!

Merci à @joao.reis (développeur de driver) pour la solution.

0 Likes 0 ·