Cassandra Durability Test

29 Nov 2015

This is a test of Cassandra's out-of-the-box durability capabilities, also run on my laptop, the same as with PostgreSQL, above. Here, I use the default binary release of Cassandra 3.0.0 (not any distro-specific packages), unpacked in my home directory.

In your regular user's directory, create this bash script,, that will find and kill -9 your Java Cassandra process:


set -u
set -e
set -o pipefail

# WARNING: this only works when there is just one cassandra node running

CASSPID=$(ps -ef | grep CassandraDaemon | grep -v grep | awk '{ print $2 }')
kill -9 ${CASSPID}

In your regular user's go/src directory, (such as ${HOME}/go/src/, create this main.go file:

package main

import (


func main() {
	cluster := gocql.NewCluster("")
	cluster.ProtoVersion = 4 // have to do this for Cass 3
	cluster.Keyspace = "foo"
	session, err := cluster.CreateSession()
	if err != nil {
		fmt.Fprintf(os.Stderr, "Unable to connect to cluster: %v\n", err)

	i := 0
	for {
		err = session.Query("insert into t (i) values (?)", i).Exec()
		if err != nil {
			fmt.Fprintf(os.Stderr, "Did not insert %d\n", i)
		fmt.Printf("inserted %d\n", i)
	defer session.Close()

Build the above go file like so:

$ cd go/src/
$ go get
$ go build

In a root terminal, turn off your hard drive's write caching, using the same script we wrote for the PostgreSQL durability test, above:

# ./

In the first user terminal, start running Cassandra, in the foreground:

$ cd ${HOME}/apache-cassandra-3.0.0/bin
$ ./cassandra -f

In a second user terminal, create the table we will use (and drop it if it exists from a prior test:

$ cd ${HOME}/apache-cassandra-3.0.0/bin
$ ./cqlsh -e "create keyspace foo with replication = {'class':'SimpleStrategy', 'replication_factor':1};"

$ ./cqlsh -k foo -e "drop table t;"
$ ./cqlsh -k foo -e "create table t (i int primary key);"

In a third user terminal, launch the insert-ints go program:

$ ./insert-ints

In a fourth user terminal, kill Cassandra:

$ ./

Back in your third user terminal, the go program should have stopped, like so:

inserted 3093
inserted 3094
inserted 3095
inserted 3096
inserted 3097
inserted 3098
Did not insert 3099

In your first user terminal, start cassandra back up:

$ ./cassandra -f -p ${HOME}/apache-cassandra-3.0.0/

In second user terminal, look to see how many writes were successfully persisted to disk:

$ ./cqlsh -k foo -e "select count(*) from t;"


(1 rows)

$ ./cqlsh -k foo -e "select max(i) from t;"


(1 rows)

Out of the box, Cassandra does not emphasize durability.