0
votes

I need to store the hit wise customer data in Cassandra. And every time customer does any activity a new row get inserted in the table. So that's why i have used the SizeTieredCompactionStrategy. So that i have all the data in less number of SSTtable as compared to leveledcompaction strategy.
Now once i insert some testing row and run the following command 'bin/nodetool compact' so that data get write to SSTable from memtable. After that i do the 10-15 read request. As i have enabled the key cache. It should return the data from cache except for the first request. But as i can see in the logs i don't see anything whether i am getting the data from cache or not? Can anyone help me with this?

Also, after dropping the keyspace and columnfamily. Why the size of my data/saved_cache/commitlog folder remain same. Shouldn't it decrease?

Keyspace and ColumnFamily(Table) Definition :
    CREATE KEYSPACE cw WITH REPLICATION = { 'class' : 'NetworkTopologyStrategy', 'datacenter1' : 3 };

    CREATE TABLE cw.usertracking (
        Col1 text PRIMARY KEY,
        Col2 timestamp,
        Col3 text,
        Col4 bigint,
        Col5 timestamp,
        Col6 bigint,
        Col7 bigint,
        Col8 bigint,
        Col9 bigint
    ) WITH bloom_filter_fp_chance = 0.01
        AND caching = '{"keys":"ALL", "rows_per_partition":"10"}'
        AND comment = ''
        AND compaction = {'min_threshold': '4', 'cold_reads_to_omit': '0.05', 'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32'}
        AND compression = {'chunk_length_kb': '64', 'sstable_compression': 'org.apache.cassandra.io.compress.DeflateCompressor'}
        AND dclocal_read_repair_chance = 0.1
        AND default_time_to_live = 0
        AND gc_grace_seconds = 864000
        AND max_index_interval = 2048
        AND memtable_flush_period_in_ms = 0
        AND min_index_interval = 128
        AND read_repair_chance = 0.0
        AND speculative_retry = '99.0PERCENTILE';

Logs of Tracing on :

activity                                                                                               | timestamp                  | source        | source_elapsed
--------------------------------------------------------------------------------------------------------+----------------------------+---------------+----------------
                                                                                     Execute CQL3 query | 2015-04-10 13:05:15.655000 | 192.168.1.200 |              0
                                                        Message received from /192.168.1.200 [Thread-7] | 2015-04-10 13:05:15.653000 | 192.168.1.202 |             23
                            Executing single-partition query on usertimespentpage [SharedPool-Worker-2] | 2015-04-10 13:05:15.653000 | 192.168.1.202 |            220
                                                     Acquiring sstable references [SharedPool-Worker-2] | 2015-04-10 13:05:15.653000 | 192.168.1.202 |            235
                                                      Merging memtable tombstones [SharedPool-Worker-2] | 2015-04-10 13:05:15.653000 | 192.168.1.202 |            259
        Skipped 0/0 non-slice-intersecting sstables, included 0 due to tombstones [SharedPool-Worker-2] | 2015-04-10 13:05:15.654000 | 192.168.1.202 |            318
                                       Merging data from memtables and 0 sstables [SharedPool-Worker-2] | 2015-04-10 13:05:15.654000 | 192.168.1.202 |            344
                                               Read 1 live and 0 tombstoned cells [SharedPool-Worker-2] | 2015-04-10 13:05:15.654000 | 192.168.1.202 |            378
                                             Enqueuing response to /192.168.1.200 [SharedPool-Worker-2] | 2015-04-10 13:05:15.654000 | 192.168.1.202 |            452
                                               Sending message to /192.168.1.200 [WRITE-/192.168.1.200] | 2015-04-10 13:05:15.654000 | 192.168.1.202 |            575
                                                        Message received from /192.168.1.200 [Thread-7] | 2015-04-10 13:05:15.655000 | 192.168.1.201 |             11
                            Executing single-partition query on usertimespentpage [SharedPool-Worker-2] | 2015-04-10 13:05:15.655000 | 192.168.1.201 |            198
 Parsing select * from userTimeSpentPage where cwc ='321KqwLrW2OY8IMT9aHJD3Bj27'; [SharedPool-Worker-1] | 2015-04-10 13:05:15.655000 | 192.168.1.200 |             45
                                                     Acquiring sstable references [SharedPool-Worker-2] | 2015-04-10 13:05:15.655000 | 192.168.1.201 |            207
                                                              Preparing statement [SharedPool-Worker-1] | 2015-04-10 13:05:15.655000 | 192.168.1.200 |            147
                                                      Merging memtable tombstones [SharedPool-Worker-2] | 2015-04-10 13:05:15.655000 | 192.168.1.201 |            227
                                               Sending message to /192.168.1.201 [WRITE-/192.168.1.201] | 2015-04-10 13:05:15.655000 | 192.168.1.200 |            455
        Skipped 0/0 non-slice-intersecting sstables, included 0 due to tombstones [SharedPool-Worker-2] | 2015-04-10 13:05:15.655000 | 192.168.1.201 |            280
                                       Merging data from memtables and 0 sstables [SharedPool-Worker-2] | 2015-04-10 13:05:15.655000 | 192.168.1.201 |            285
                                               Read 1 live and 0 tombstoned cells [SharedPool-Worker-2] | 2015-04-10 13:05:15.655001 | 192.168.1.201 |            322
                                             Enqueuing response to /192.168.1.200 [SharedPool-Worker-2] | 2015-04-10 13:05:15.655001 | 192.168.1.201 |            423
                                               Sending message to /192.168.1.200 [WRITE-/192.168.1.200] | 2015-04-10 13:05:15.655001 | 192.168.1.201 |            527
                                               Sending message to /192.168.1.202 [WRITE-/192.168.1.202] | 2015-04-10 13:05:15.656000 | 192.168.1.200 |           1221
                                                        Message received from /192.168.1.201 [Thread-4] | 2015-04-10 13:05:15.657000 | 192.168.1.200 |           2094
                                          Processing response from /192.168.1.201 [SharedPool-Worker-2] | 2015-04-10 13:05:15.657000 | 192.168.1.200 |           2134
                                                        Message received from /192.168.1.202 [Thread-5] | 2015-04-10 13:05:15.657000 | 192.168.1.200 |             --
                                          Processing response from /192.168.1.202 [SharedPool-Worker-1] | 2015-04-10 13:05:15.657000 | 192.168.1.200 |             --
                                                                                       Request complete | 2015-04-10 13:05:15.657232 | 192.168.1.200 |           2232
2

2 Answers

2
votes

1) Your understanding of Cassandra seems to be fairly light. Trying to ensure that all of your data always ends up in a single sstable is not reasonable. Compaction is something that will happen, and you should understand why it happens, but not rely on it happening to consolidate your data to make it easier to cache - the key cache will cache relevant keys, that's sufficient for most use cases. If you need lower latencies beyond that, consider using another caching layer in front of cassandra such as memcached.

2) You're serving the request out of the memtable without really touching the sstable at all - it's found a single cell in the memtable, and it's not reconciling that with any sstable cells:

    Skipped 0/0 non-slice-intersecting sstables, included 0 due to tombstones [SharedPool-Worker-2] | 2015-04-10 13:05:15.655000 | 192.168.1.201 |            280
                                   Merging data from memtables and 0 sstables [SharedPool-Worker-2] | 2015-04-10 13:05:15.655000 | 192.168.1.201 |            285

                                           Read 1 live and 0 tombstoned cells [SharedPool-Worker-2] | 2015-04-10 13:05:15.655001 | 192.168.1.201 |            322

3) The commitlog will not shrink - it's a journal of all activity that gets replayed on startup. All of the writes exist until it is purged.

0
votes

I don't know what version of Cassandra you are using, but in 2.1 you can use JMX, check the "Caches" MBean. The values for "KeyCacheHits" and "KeyCacheSize" should tell you how many reads that hits the key cache and how large the key cache currently is.