pchalamet / cassandra-sharp

high performance .NET driver for Apache Cassandra
114 stars 41 forks source link

Set connection timeout on cassandra nodes #64

Closed MCs88 closed 7 years ago

MCs88 commented 11 years ago

Hi!

Is there any way to set connection timeout for the cassandra nodes? I want to decrease the timeout to switch faster to a next node if connection fails to a node.

pchalamet commented 11 years ago

Hi !

You can set a timeout for the socket (see TransportConfig.ReceiveTimeout). But I’m pretty sure that’s not what you really want because that also implies all socket receive operations undergo the same constraints (and it’s pretty lame to do that at transport level).

Probably there is 2 ways to support this:

Let me know if you want some help in case you go for #2!

MCs88 commented 11 years ago

Definitely the 2nd one is the better solution. I'll look the code, thanks!

MCs88 commented 11 years ago

I've dived into the code. The problem is that in the constructor of LongRunningConnection class, _tcpClient.Connect() is called. The Connect() method throws an exception because cassandra node is not available, so ReadifiyConnection and Authenticate not even called.

Unfortunately the TcpClient class did not expose any field or property to set connection timeout, so there's no elegant way to solve this, only timers...

pchalamet commented 11 years ago

Yeah but that's really different story.

If you can't connect, this should fail quite immediately and connection will fail and a retry on other endpoint will take place.

My guess is you only want to timeout when then server is overloaded and failed to reply quickly - Readify is the right place for that.

-----Original Message----- From: "MCs88" notifications@github.com Sent: ‎16/‎07/‎2013 17:24 To: "pchalamet/cassandra-sharp" cassandra-sharp@noreply.github.com Cc: "Pierre Chalamet" pierre@chalamet.net Subject: Re: [cassandra-sharp] Set connection timeout on cassandra nodes (#64)

I've dived into the code. The problem is that in the constructor of LongRunningConnection class, _tcpClient.Connect() is called. The Connect() method throws an exception because cassandra node is not available, so ReadifiyConnection and Authenticate not even called. Unfortunately the TcpClient class did not expose any field or property to set connection timeout, so there's no elegant way to solve this, only timers... — Reply to this email directly or view it on GitHub.

MCs88 commented 11 years ago

Sometimes we have network connectivity issues, and "quite immediately" is ~20sec per node actually in my tests. We have 3 nodes in a datacenter, so it's 60+ sec to switch to another datacenter, which is out of the http request execution time.

pchalamet commented 11 years ago

Probably something like that then: http://stackoverflow.com/questions/1062035/how-to-config-socket-connect-timeout-in-c-sharp

pchalamet commented 11 years ago

But this should probably be mixed with a cancellation token to span timeout on connect and readify.

MCs88 commented 11 years ago

Thanks, I'll take a look at it!

pchalamet commented 10 years ago

You seem to have done a fix in your fork. Are you ok with it ? Do you want to send a pull request ? Thanks.

MCs88 commented 10 years ago

Sorry for this big delay. Next week I'll review my changes and I'll send the pull request.