n4kin
n4kin

Reputation: 19

using Cassandra c# driver with multi-thread

I'm using c# driver for Cassandra with multi-threads processing. At first, I tried to create a connection and execute command and then close the connection after done the work. But it's seem not to work for me, sometimes it's got an exception that No hosts available.

So, I changed to working with static connection. it's seem to work as well. But when thread is working too fast, it's broken again. I've to put some Thread.Sleep for 1 second then it works.

And with this static solution, I tried to use Asynchronous process, BeginExecute and it's not work for me as well, exception No Hosts Available.

So, anyone has better ideas or better implementation on multi-threads processing working with Cassandra c# driver, it would be appreciate if you can share.

Thank you in advance.

Cheers, Kin

Upvotes: 1

Views: 1743

Answers (3)

David
David

Reputation: 101

If you use asynchronous method,it looks like that:

Statement sta=new SimpleStatement("Select * from XXX where XXX;");
session.ExecutAsync(sta);

Upvotes: 1

Alex Popescu
Alex Popescu

Reputation: 4002

  1. Make sure your setup is satisfying the connection requirements

  2. The C# driver should definitely work in a multi-threading environment (1 cluster object, 1 session object/keyspace)

  3. It's difficult to say why you are seeing the NoHostAvailable exception without seeing any code.

Upvotes: 0

user1968030
user1968030

Reputation:

CassandraSession can only have one connection at a time. It probably isn't thread safe now that I think about it. But the Connection Pool is thread safe, so if you use that you will always have a high availability connection

Upvotes: 1

Related Questions