weismat
weismat

Reputation: 7411

Cassandra Insert performance c#

I am doing a proof of concept on Cassandra using the apache-cassandra-3.10 and CassandraCSharpDriver version 3.2.1.
I want to put in a large amount of Tick data into Cassandra with C#.
My current schema looks like this.

CREATE TABLE my_keyspace.ticks (
    instrumentcode int,
    timestamp timestamp,
    type smallint,
    exchange smallint,
    price decimal,
    volume int,
    PRIMARY KEY (instrumentcode, timestamp, type, exchange)
) WITH CLUSTERING ORDER BY (timestamp ASC, type ASC, exchange ASC);

I am using a prepared statement in the following way:

//setup
Cluster = Cluster.Builder().AddContactPoints("localhost").Build();
Session = Cluster.Connect("my_keyspace");
ps = Session.Prepare("Insert into ticks (instrumentcode, timestamp, type, exchange, price, volume) values(?,?,?,?,?,?)");
//repeated re-using the same prepared statement
var statement = ps.Bind(tickCassandra.Instrumentcode, tickCassandra.Timestamp, tickCassandra.Type, tickCassandra.Exchange, tickCassandra.Price, tick.Volume);
var x = Session.Execute(statement);

With this code I am stuck at an insert performance of around 600 inserts/second - both on my dev machine (i7) and my prod like machine (16 core beast).
Do you see any performance improvements in my schema or my C# code? Or do I just need to tweak more the Cassandra configuration?

Upvotes: 2

Views: 2065

Answers (1)

Marko Švaljek
Marko Švaljek

Reputation: 2101

Try using:

//Execute a statement asynchronously
session.ExecuteAsync(statement);

This should be a huge boost (around 3-4 times) of what you have now.

Edit after comments:

You also need to be careful with retry and exception handling, once you move your app out from poc stage. There are couple of very good and helpful examples (suggestion of xmas79 - thanks!)

  1. https://stackoverflow.com/a/39643888/6570821
  2. https://stackoverflow.com/a/40524828/6570821
  3. https://stackoverflow.com/a/40794021/6570821

Upvotes: 4

Related Questions