【发布时间】:2017-09-13 21:22:09
【问题描述】:
我正在使用 apache-cassandra-3.10 和 CassandraCSharpDriver 版本 3.2.1 在 Cassandra 上进行概念验证。
我想用 C# 将大量的 Tick 数据放入 Cassandra。
我当前的架构如下所示。
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);
我正在通过以下方式使用准备好的语句:
//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);
使用此代码,我的插入性能被困在大约 600 次插入/秒 - 在我的开发机器 (i7) 和我的 prod 类似机器(16 核野兽)上。
您在我的架构或 C# 代码中看到任何性能改进吗?还是我只需要调整更多 Cassandra 配置?
【问题讨论】:
-
我对 cassandra 一无所知,但谷歌搜索“cassandra bulk insert c# site:stackoverflow.com”会产生很多有趣的结果
-
你每次插入时都在使用 Session.Prepare 吗?
-
否 - 我将相应地更新代码示例。
标签: c# performance cassandra