Reputation: 23
I'm building app to measure NoSQL databases performance and I have a problem to batch insert a large amount of data, in the Cassandra database.
When I'm trying to batch insert more then 1000 records, using DataStax C# driver, I get an AggregateException.
This is my data model:
public Guid Id { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public int Year { get; set; }
public string Genres { get; set; }
public int Rating { get; set; }
public string OriginalLanguage { get; set; }
public string ProductionCountry { get; set; }
public int VotingsNumber { get; set; }
And this is my code:
private string InsertData(ISession session, List<Movie> moviesList)
{
var table = session.GetTable<Movie>();
table.CreateIfNotExists();
var batch = session.CreateBatch();
foreach (var record in moviesList)
{
batch.Append(table.Insert(record));
}
Stopwatch watch = new Stopwatch();
watch.Start();
batch.Execute();
watch.Stop();
return watch.ElapsedMilliseconds.ToString();
}
Can someone explain to me what I'm doing wrong?
Upvotes: 2
Views: 2804
Reputation: 2217
Batch statements are not maded for bulk loading in Cassandra, in the C# faq Datastax clearly recommend to have a batch size in the order of tens.
If you want to insert a lot of datas in your case you should regular or async statements to do so.
Upvotes: 9