Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the nature of Cassandra "write timeout"?

I am running a write-heavy program (10 threads peaks at 25K/sec writes) on a 24 node Cassandra 3.5 cluster on AWS EC2 (each host is of c4.2xlarge type: 8 vcore and 15G ram)

Every once in a while my Java client, using DataStax driver 3.0.2, would get write timeout issue:

com.datastax.driver.core.exceptions.WriteTimeoutException: Cassandra timeout during write query at consistency TWO (2 replica were required but only 1 acknowledged the write)
    at com.datastax.driver.core.exceptions.WriteTimeoutException.copy(WriteTimeoutException.java:73)
    at com.datastax.driver.core.exceptions.WriteTimeoutException.copy(WriteTimeoutException.java:26)
    at com.datastax.driver.core.DriverThrowables.propagateCause(DriverThrowables.java:37)
    at com.datastax.driver.core.DefaultResultSetFuture.getUninterruptibly(DefaultResultSetFuture.java:245)
    at com.datastax.driver.core.AbstractSession.execute(AbstractSession.java:64)

The error happens infrequently and in a very unpredictable way. So far, I am not able to link the failures to anything specific (e.g. program running time, data size on disk, time of the day, indicators of system load such as CPU, memory, network metrics) Nonetheless, it is really disrupting our operations.

I am trying to find the root cause of the issue. Looking online for options, I am a bit overwhelmed by all the leads out there, such as

  • Changing "write_request_timeout_in_ms" in "cassandra.yaml" (already changed to 5 seconds)
  • Using proper "RetryPolicy" to keep the session going (already using DowngradingConsistencyRetryPolicy on a ONE session level consistency level)
  • Changing cache size, heap size, etc. - never tried those b/c there are good reasons to discount them as the root cause.

One thing is really confusing during my research is that I am getting this error from a fully replicated cluster with very few ClientRequest.timeout.write events:

  • I have a fully-replicated 24 node cluster spans 5 aws regions. Each region has at least 2 copies of the data
  • My program runs consistency level ONE at Session level (Cluster builder with QueryOption)
  • When the error happened, our Graphite chart registered no more than three (3) host hiccups, i.e. having the Cassandra.ClientRequest.Write.Timeouts.Count values
  • I already set write_timeout to 5 seconds. The network is pretty fast (using iperf3 to verify) and stable

On paper, the situation should be well within Cassandra's failsafe range. But why my program still failed? Are the numbers not what they appear to be?

like image 596
Bing Wu Avatar asked Sep 03 '16 06:09

Bing Wu


1 Answers

Its not always necessarily a bad thing to see timeouts or errors especially if you're writing at a higher consistency level, the writes may still get through.

I see you mention CL=ONE you could still get timeouts here but the write (mutation) still have got through. I found this blog really useful: https://www.datastax.com/dev/blog/cassandra-error-handling-done-right. Check your server side (node) logs at the time of the error to see if you have things like ERROR / WARN / GC pauses (like one of the comments mentions above) these kind of events can cause the node to be unresponsive and therefor a timeout or other type of error.

If your updates are idempotent (ideally) then you can build in some retry mechanism.

like image 50
markc Avatar answered Oct 17 '22 06:10

markc