在單個節點上測試Cassandra C#插入性能時,i7 8個內核只有100個插入/秒。使用Datastax Cassandra驅動程序是否可以改進代碼?嘗試異步並同步Session.Execute,但性能非常差。Cassandra並行插入性能c#
[TestMethod]
public void TestMethod2()
{
// CREATE TABLE table1(
// col1 text,
// col2 timestamp,
// col3 int,
// col4 text,
// PRIMARY KEY(col1, col2, col3)
// );
PoolingOptions poolingOptions = new PoolingOptions();
poolingOptions
.SetCoreConnectionsPerHost(HostDistance.Local, 1280)
.SetMaxConnectionsPerHost(HostDistance.Local, 1280)
.SetCoreConnectionsPerHost(HostDistance.Remote, 1280)
.SetMaxConnectionsPerHost(HostDistance.Remote, 1280);
poolingOptions
.SetMaxSimultaneousRequestsPerConnectionTreshold(HostDistance.Local, 32768)
.SetMinSimultaneousRequestsPerConnectionTreshold(HostDistance.Remote, 2000);
var cluster = Cluster.Builder()
.AddContactPoints("localhost")
.WithPoolingOptions(poolingOptions)
.WithQueryOptions(new QueryOptions().SetConsistencyLevel(ConsistencyLevel.One))
.WithLoadBalancingPolicy(new RoundRobinPolicy())
.Build();
var options = new ParallelOptions();
options.MaxDegreeOfParallelism = 50;
using (var session = cluster.Connect("keyspace1"))
{
var ps = session.Prepare("INSERT INTO table1(col1,col2,col3,col4) VALUES (?,?,?,?)");
var r = Parallel.For(0, 1000, options, (x) =>
{
{
var statement = ps.Bind("123456", DateTime.UtcNow, x, "1234 some log message goes here. Hello world. 123334556567586978089-==00");
var t = session.ExecuteAsync(statement);
t.Wait();
}
});
}
}
還要檢查卡桑德拉配置,以提高清潔卡桑德拉安裝後吞吐量 –
測試中完成的。檢查過的文檔和cassandra.yaml,但我沒有找到任何合理的參數來配置(結果是每10秒插入1000次)。 –
首先,您可以嘗試增加堆大小,更改記錄大小,增加Cassandra寫連接數等,並查看您是否獲得了Imrovement。 Cassandra可以在多節點集羣中進行擴展並且性能優於單節點。 –