Skip to content
This repository was archived by the owner on Dec 19, 2025. It is now read-only.
Denis Sheahan edited this page Feb 29, 2012 · 9 revisions

Put

Using cassandra-cli on one of the cluster nodes we create a simple schema, with a Keyspace called MemberKeySp and a Column Family Customer

create keyspace MemberKeySp
  with placement_strategy = 'NetworkTopologyStrategy'
  and strategy_options = [{us-east : 3}]
  and durable_writes = true;

use MemberKeySp;

create column family Customer
  with column_type = 'Standard'
  and comparator = 'UTF8Type'
  and default_validation_class = 'BytesType'
  and key_validation_class = 'UTF8Type'
  and rows_cached = 0.0
  and row_cache_save_period = 0
  and keys_cached = 100000.0
  and key_cache_save_period = 14400
  and read_repair_chance = 0.0
  and gc_grace = 864000
  and min_compaction_threshold = 4
  and max_compaction_threshold = 32
  and replicate_on_write = false
  and row_cache_provider = 'ConcurrentLinkedHashCacheProvider'
  and comment = 'Customer Records';

To insert a Put into the experiment right click on Thread Group -> Add -> Sampler -> Cassandra Put

Looking at the screen shot the following fields are required for the simple Put

  • ColumnFamily specifies which column family to send the request to

  • ROW KEY specifies the row key to use. This can be a random variable, constant text or a JMeter variable, either generated by a bean shell or read from a csv file. In the example we have used a variable ${rowid} from a csv file

  • COLUMN NAME the name of the column to insert, also a random, constant or JMeter variable. In the example we have chosen a Random value

  • COLUMN VALUE the value to store for this column, random, constant or JMeter variable. In the example we have chosen a JMeter variable ${value} read from a csv file.

  • Serializers - each field needs to define the Java serializer to use when communicating with Cassandra. Selecting the serializer is very important for correct operation. This can be one of AsciiSerializer, BooleanSerializer, DateSerializer, BytesSerializer, CharSerializer, StringSerializer, FloatSerializer, UUIDSerializer, IntegerSerializer, DoubleSerializer, ShortSerializer, LongSerializer, BigIntegerSerializer.

  • Counter Indicates that this column is a Counter

The View Results tree shows if each transaction suceeded, displayed in Green, or had an Error, displayed in Red. The result of running our Cassandra Put for a csv file with 25 entries is shown below. On the left I have highlighted the success and in the sampler result I have highlighted the Row key used for the mutation, its column name and value. Also highlighted is the latency in miliseconds for the transaction.

We can check whether the rows were inserted on the Cassandra cluster using cassandra-cli

[default@unknown] use MemberKeySp;
Authenticated to keyspace: MemberKeySp
[default@MemberKeySp] list Customer;
Using default limit of 100
-------------------
RowKey: 3
=> (column=266, value=746573745f646174615f646464, timestamp=1330034215605000)
-------------------
RowKey: 6
=> (column=59, value=746573745f646174615f676767, timestamp=1330034216403000)
-------------------
RowKey: 5
=> (column=610, value=746573745f646174615f666666, timestamp=1330034216138000)
-------------------
RowKey: 19
=> (column=924, value=746573745f646174615f747474, timestamp=1330034217553000)

If there is an error the left hand column will be highlighted in Red. In this case the Error Count in the Sampler Result will be non-zero. An indication of the failure (Usually a Java stack trace) will be thrown in the Response Data window. In the example screenshot the simple Put failed because I choose BytesArraySerializer for the Value and we got a NumberFormatException

The jmx file for this simple Put test is here and the csv file is here

Counter Put

First lets create a new counter column family CustomerCounter in our MemberKeySp Keyspace

  use MemberKeySp;
 
  create column family CustomerCounter
  with column_type = 'Standard'
  and comparator = 'UTF8Type'
  and default_validation_class = 'CounterColumnType'
  and replicate_on_write = true
  and key_validation_class = 'UTF8Type'
  and rows_cached = 0.0
  and row_cache_save_period = 0
  and keys_cached = 100000.0
  and key_cache_save_period = 14400
  and read_repair_chance = 0.0
  and gc_grace = 864000
  and min_compaction_threshold = 4
  and max_compaction_threshold = 32      
  and row_cache_provider = 'ConcurrentLinkedHashCacheProvider'
  and comment = 'Customer Counters';

Two modifications are needed for Counters. First we set the default_validation_class to CounterColumnType and second we must set the replicate_on_write to true or the Put will fail.

To Put a Counter value with JMeter we use the CassandraPut Sampler. As can be seen from the screenshot below, we check the Counter box (circled in red) to indicate this is a counter. have put 10 in the Value field (also circled in red) as I want all the counters to be initialized to this value. I have used the ${value} from the csv file as the name of the counter in this case. The Serializer for the counter has to be Long as it requires an i64 value.

We can check the counters have been initialized using the cassandra-cli on the cluster

 list CustomerCounter;
 Using default limit of 100
 -------------------
 RowKey: 3
 => (counter=test_data_ddd, value=10)
 -------------------
 RowKey: 6
 => (counter=test_data_ggg, value=10)
 -------------------
 RowKey: 5
 => (counter=test_data_fff, value=10)
 -------------------

Note the Value in a Cassandra Counter Put is relative. If the counter does not exist it will be loaded with the Value. If the counter does exist it will be incremented or decremented by Value. In the example above on the second pass if we set Value to -5 the result will be 5 in all the counters as indicated bu cassandra-cli

 [default@MemberKeySp] list CustomerCounter;
 Using default limit of 100
 -------------------
 RowKey: 3
 => (counter=test_data_ddd, value=5)
 -------------------
 RowKey: 6
 => (counter=test_data_ggg, value=5)
 -------------------
 RowKey: 5
 => (counter=test_data_fff, value=5)

Also note Counters cannot be currently be mixed woth regular columns. Counters require their own Column Family.

The jmx file for the counter put experiment is here.

Batch Put

If we want to put multiple colums in a single row we use the Batch Put Option. Right click Thread Group -> Add -> Sampler -> Cassandra Batch Put. A sample screenhot is shown below

This is very similar to Put but you can specify multiple columns for the row. The format for each column is <column name>:<value>

Note the columns can be Counters as in a regular Put, just check the Counter box (highlighted in red). Note that due to a limitation in Cassandra all the columns in the row must be counters if doing a Batch Put.

View Results Tree now shows us each transaction was a Batch Put and the Sampler result has all the column names and values

Again cassandra-cli shows us our data was inserted correctly

[default@unknown] use MemberKeySp;
Authenticated to keyspace: MemberKeySp
[default@MemberKeySp] list Customer;
Using default limit of 100
-------------------
RowKey: 3
=> (column=580, value=746573745f646174615f646464, timestamp=1330036037925001)
=> (column=constant, value=746573745f646174615f646464, timestamp=1330036037925000)
-------------------
RowKey: 6
=> (column=628, value=746573745f646174615f676767, timestamp=1330036038190001)
=> (column=constant, value=746573745f646174615f676767, timestamp=1330036038190000)

The jmx file for this simple batch put experiment is hwrw

Composite Put

Often Cassandra keyspaces use composite columns to store data. Lets create a new Column Family (CustomerComposite) with a Composite Column consisting of an Integer:UTF8

use MemberKeySp;

create column family CustomerComposite
  with column_type = 'Standard'
  and comparator = 'CompositeType(org.apache.cassandra.db.marshal.IntegerType,org.apache.cassandra.db.marshal.UTF8Type)'
  and default_validation_class = 'BytesType'
  and key_validation_class = 'UTF8Type'
  and memtable_operations = 1.0
  and memtable_throughput = 64
  and rows_cached = 1000.0
  and row_cache_save_period = 0
  and keys_cached = 300000.0
  and key_cache_save_period = 14400
  and read_repair_chance = 0.0
  and gc_grace = 864000
  and min_compaction_threshold = 4
  and max_compaction_threshold = 32
  and replicate_on_write = false
  and row_cache_provider = 'ConcurrentLinkedHashCacheProvider'
  and comment = 'Customer-specific, ABTest allocations';

We create a csv file which contains 3 fields that looks like this.

0,1:comp111,ef3e0b
0,2:comp222,1de7c16
0,3:comp333,2cdba21
0,4:comp444,3bcf82c
0,5:comp555,4ac3637
1,0:comp666,59b7442
1,1:comp777,68ab24d
1,2:comp888,779f058
1,3:comp999,8692e63
1,4:comp101010,9586c6e
1,5:comp111111,a47aa79

In JMeter right click on the Thread Group -> Add -> Sampler -> Cassandra Composite Put. The screenshot below shows our example. Note we dont need to specify the format of the composite column as this is derived from the schema

As with all Puts this Composite column can be a Counter by checking the box (highlighted in red on the screenshot). In this case the Counter will be incremented / decremented by the amount in Value. The serializer must be a Long for Counters.

The View Reults Tree shows the Composite Put success and the Composite Column name

cassandra-cli shows us how these Composite Columns have been loaded

[default@MemberKeySp] list Customer;
Using default limit of 100
-------------------
RowKey: 3
=> (column=0:comp181818, value=10d25cc6, timestamp=1330057016537000)
=> (column=1:comp191919, value=11c19ad1, timestamp=1330057016648000)
=> (column=2:comp202020, value=12b0d8dc, timestamp=1330057016759000)
=> (column=3:comp212121, value=13a016e7, timestamp=1330057016872000)
=> (column=4:comp222222, value=148f54f2, timestamp=1330057016981000)
=> (column=5:comp232323, value=157e92fd, timestamp=1330057017093000)
-------------------
RowKey: 0
=> (column=1:comp111, value=ef3e0b, timestamp=1330057014678000)
=> (column=2:comp222, value=01de7c16, timestamp=1330057014789000)
=> (column=3:comp333, value=02cdba21, timestamp=1330057014898000)
=> (column=4:comp444, value=03bcf82c, timestamp=1330057015004000)
=> (column=5:comp555, value=04ac3637, timestamp=1330057015118000)
-------------------
RowKey: 2
=> (column=0:comp121212, value=0b36e884, timestamp=1330057015883000)
=> (column=1:comp131313, value=0c26268f, timestamp=1330057015996000)
=> (column=2:comp141414, value=0d15649a, timestamp=1330057016101000)
=> (column=3:comp151515, value=0e04a2a5, timestamp=1330057016210000)
=> (column=4:comp161616, value=0ef3e0b0, timestamp=1330057016318000)
=> (column=5:comp171717, value=0fe31ebb, timestamp=1330057016429000)
-------------------

The jmx file for this simple composite put experiment is here and the csv file is here

Clone this wiki locally