Timeout on read does not work?

539 views
Skip to first unread message

alexey.rodri...@soundcloud.com

unread,
Jun 15, 2015, 12:18:41 PM6/15/15
to go...@googlegroups.com
Hi there!

I have a question about controlling the timeout behaviour of Cassandra queries.

I am trying to set up a Cassandra client using gocql. This client is very simple in that it only performs look ups and it doesn't update the database. I want my client to timeout when Cassandra does not respond within a given time frame. I noticed that there is the Timeout parameter in ClusterConfig, and that NewCluster (which I use) sets it to 600ms. However, I am not getting read errors when this timeout is exceeded, I have set this timeout very low (1ms for example) to check whether this parameter works, but I still don't get a timeout error.

I am missing something on how this parameter should be used?

Thank you!

Alexey

Ben Hood

unread,
Jun 15, 2015, 1:16:41 PM6/15/15
to alexey.rodri...@soundcloud.com, go...@googlegroups.com
Hi Alexey,

Could you post a short running example of the code that you are having
issues with please?

Cheers,

Ben
> --
> You received this message because you are subscribed to the Google Groups "gocql" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to gocql+un...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Alexey Rodriguez Yakushev

unread,
Jun 15, 2015, 2:21:57 PM6/15/15
to Ben Hood, go...@googlegroups.com

Hi Ben, here is a copy paste of the offending code with slight edits to remove irrelevant details:

cluster := gocql.NewCluster(hosts...)
cluster.Keyspace = ...
cluster.Consistency = gocql.Quorum
cluster.Authenticator = gocql.PasswordAuthenticator{...}
cluster.Timeout = 50 * time.Millisecond // Low deadline for testing purposes

session, err := cluster.CreateSession()
if err != nil {
log.Fatalf("could not connect to cassandra cluster %s", err)
}

return &cassandra{
session: session,
}

And later in the code the session is used (s is a cassandra struct that contains the session field):

start := time.Now()
if err := s.session.Query(query).Scan(&text); err != nil {
return ..., fmt.Errorf("could not select: %s", err.Error())
}
elapsed := time.Since(start)
fmt.Printf("Response time: %v\n", elapsed)


A printout of a run:

connect: failed to connect to "IP:9042": dial tcp IP:9042: i/o timeout
connect: failed to connect to "IP:9042": dial tcp IP:9042: i/o timeout
Response time: 137.591482ms

Interestingly, it seems that the latency checking is performed when the connection is performed (if I decrease Timeout, the connection code will abort after a few timeout errors). Unfortunately, the latency checking is not performed for the query itself.

Cheers,

Alexey

Alexey Rodriguez Yakushev

unread,
Jun 15, 2015, 2:27:31 PM6/15/15
to Ben Hood, go...@googlegroups.com
In case the query is relevant (I wouldn't think so), here is how it looks like:

const (
Query = "SELECT value FROM %s WHERE key = %s"
)


On Mon, Jun 15, 2015 at 7:16 PM, Ben Hood <0x6e...@gmail.com> wrote:

Chris Bannister

unread,
Jun 15, 2015, 5:40:24 PM6/15/15
to Alexey Rodriguez Yakushev, Ben Hood, go...@googlegroups.com
Currently there is a limitation with the query sending code is that it will only set read timeouts once it has received a header because otherwise the conn read loop can be looping for a long time without any data on the socket.

I'll create an issue and start working on it, its quite a simple fix.

Alexey Rodriguez Yakushev

unread,
Jun 16, 2015, 5:59:35 AM6/16/15
to Chris Bannister, Ben Hood, go...@googlegroups.com
That's great Chris.

I'll be tracking this issue then:


Cheers,

Alexey
Reply all
Reply to author
Forward
0 new messages