【问题标题】:key cache is not enabled in cassandracassandra 中未启用密钥缓存
【发布时间】:2015-04-11 14:38:31
【问题描述】:

我需要将热门客户数据存储在 Cassandra 中。每次客户进行任何活动时,都会在表中插入一个新行。所以这就是我使用SizeTieredCompactionStrategy 的原因。因此,与 leveledcompaction 策略相比,我拥有更少数量的 SSTtable 中的所有数据。
现在,一旦我插入一些测试行并运行以下命令'bin/nodetool compact',以便数据从 memtable 写入 SSTable。之后,我执行 10-15 读取请求。因为我启用了密钥缓存。它应该从缓存中返回数据,除了第一个请求。但正如我在日志中看到的那样,无论我是否从缓存中获取数据,我都看不到任何东西?谁能帮我这个?

此外,在删除键空间和列族之后。为什么我的 data/saved_cache/commitlog 文件夹的大小保持不变。不应该减少吗?

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';

追踪日志:

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

【问题讨论】:

    标签: caching cassandra cassandra-2.0 cassandra-cli


    【解决方案1】:

    1) 您对 Cassandra 的理解似乎相当浅。试图确保您的所有数据始终以单个 sstable 结尾是不合理的。压缩是会发生的事情,您应该了解它为什么会发生,但不要依赖它来整合您的数据以使其更容易缓存 - 密钥缓存将缓存相关的密钥,这对于大多数用例来说已经足够了。如果您需要更低的延迟,请考虑在 cassandra 前面使用另一个缓存层,例如 memcached。

    2) 您在没有真正接触 sstable 的情况下从 memtable 中提供请求 - 它在 memtable 中找到了一个单元格,并且与任何 sstable 单元格都不一致:

        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) 提交日志不会缩小 - 它是所有在启动时重播的活动的日志。所有写入都存在,直到它被清除。

    【讨论】:

    • 但是为什么删除键空间和列族后数据文件夹的大小没有缩小。另外,在 SSTables 的主要压缩数量减少后,我在哪里可以看到?就像你知道的那样,我们可以在 hdfs 中检查 hbase 减少 hfile 的数量。
    • 当您删除键空间或表时,它可能会创建快照,这是您可以在 cassandra.yaml 中启用/禁用的选项
    【解决方案2】:

    我不知道你使用的是什么版本的 Cassandra,但是在 2.1 中你可以使用 JMX,检查“缓存”MBean。 “KeyCacheHits”和“KeyCacheSize”的值应该告诉您有多少读取命中键缓存以及当前键缓存有多大。

    【讨论】:

      猜你喜欢
      • 2019-02-04
      • 2013-05-01
      • 2015-03-05
      • 2012-01-24
      • 1970-01-01
      • 2019-01-15
      • 2015-11-04
      • 1970-01-01
      • 2011-06-23
      相关资源
      最近更新 更多