【问题标题】:Cassandra Insert performance c#Cassandra 插入性能 c#
【发布时间】: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


【解决方案1】:

尝试使用:

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

这应该是您现在拥有的巨大提升(大约 3-4 倍)。

在 cmets 之后编辑:

一旦您将应用程序从 poc 阶段移出,您还需要小心重试和异常处理。有 几个非常好的和有用的例子(xmas79 的建议 - 谢谢!)

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

【讨论】:

猜你喜欢
  • 2018-01-12
  • 2011-08-22
  • 2015-03-10
  • 1970-01-01
  • 2023-03-27
  • 2017-06-03
  • 2017-08-13
  • 2016-07-12
  • 1970-01-01
相关资源
最近更新 更多