【问题标题】:Can Cassandra row cache only cache on specific columns?Cassandra 行缓存只能缓存在特定列上吗?
【发布时间】:2019-01-06 23:40:54
【问题描述】:

我有一个 C* 表,它很宽,有些列读起来很重。我正在考虑使用行缓存,但不知道行缓存是否可以存储特定列。如果需要存储该行的所有单元格,则要缓存的内容可能会增长过快而无法达到目的。

架构如下:

CREATE TABLE tb1 (
    pk1 int,
    ck1 int,
    read_heavy_col1 int,
    read_heavy_col2 int,
    normal_col1 int,
    normal_col2 int,
    ...
    PRIMARY KEY (pk1, ck1)
)

问题是行缓存是否能够仅缓存pk1, ck1, read_heavy_col1, read_heavy_col2 而忽略normal_col1, normal_col2, ...

根据DataStax Configuring data caches

如果新缓存的数据不包括由配置的所有单元格 用户,Cassandra 执行另一次读取。

这是否意味着 C* 只能缓存感兴趣的列?

【问题讨论】:

  • 你有多少列?
  • 说 20 个普通列,但只有 2 个被定期访问

标签: cassandra


【解决方案1】:

您可以不使用大量列,而是使用单个集群键,重读列较早排序,然后限制 rows_per_partition 以仅捕获这些。

与仅缓存整行相比,您可能不会获得很多好处。此外,虽然键缓存通常对于读取性能而言非常重要,但行缓存实际上只在非常特定的情况下有所帮助(并且在某些情况下会受到伤害),因此请务必对其进行基准测试,因为操作系统缓存通常足以将重要位保留在内存中。

【讨论】:

  • 集群键用于其他业务用途,不能更改
【解决方案2】:

回答我自己的问题: Cassandra 将缓存该行的所有列。

来自 Jeff Carpenter 和 Eben Hewitt 的“Cassandra The Definitive Guide”(第 2 版):

行缓存缓存整行,可以加快对频繁访问的行的读取访问,但会消耗更多内存。

实验:

abc@cqlsh:test> SELECT pk1, ck1, read_heavy_col1 FROM tb1 WHERE pk1=2 and ck1=1;

 pk1 | ck1 | read_heavy_col1
-----+-----+-----------------
   2 |   1 |               1

(1 rows)

Tracing session: 53aac630-11be-11e9-9cb3-fbffb1c1e13b

 activity                                                                                               | timestamp                  | source       | source_elapsed
--------------------------------------------------------------------------------------------------------+----------------------------+--------------+----------------
                                                                                     Execute CQL3 query | 2019-01-06 22:21:15.667000 | x.x.x.x |              0
 Parsing SELECT pk1, ck1, read_heavy_col1 FROM tb1 WHERE pk1=2 and ck1=1; [Native-Transport-Requests-1] | 2019-01-06 22:21:15.668000 | x.x.x.x |            310
                                                      Preparing statement [Native-Transport-Requests-1] | 2019-01-06 22:21:15.668000 | x.x.x.x |            568
                                                Executing single-partition query on roles [ReadStage-2] | 2019-01-06 22:21:15.669000 | x.x.x.x |           1259
                                                             Acquiring sstable references [ReadStage-2] | 2019-01-06 22:21:15.669000 | x.x.x.x |           1345
                                                              Key cache hit for sstable 2 [ReadStage-2] | 2019-01-06 22:21:15.669000 | x.x.x.x |           1475
                Skipped 0/1 non-slice-intersecting sstables, included 0 due to tombstones [ReadStage-2] | 2019-01-06 22:21:15.669000 | x.x.x.x |           1569
                                                Merged data from memtables and 1 sstables [ReadStage-2] | 2019-01-06 22:21:15.669000 | x.x.x.x |           1768
                                                   Read 1 live rows and 0 tombstone cells [ReadStage-2] | 2019-01-06 22:21:15.669000 | x.x.x.x |           1869
                                                Executing single-partition query on roles [ReadStage-3] | 2019-01-06 22:21:15.672000 | x.x.x.x |           4579
                                                             Acquiring sstable references [ReadStage-3] | 2019-01-06 22:21:15.672000 | x.x.x.x |           4701
                                                              Key cache hit for sstable 2 [ReadStage-3] | 2019-01-06 22:21:15.672000 | x.x.x.x |           4812
                Skipped 0/1 non-slice-intersecting sstables, included 0 due to tombstones [ReadStage-3] | 2019-01-06 22:21:15.672000 | x.x.x.x |           4891
                                                Merged data from memtables and 1 sstables [ReadStage-3] | 2019-01-06 22:21:15.672000 | x.x.x.x |           5001
                                                   Read 1 live rows and 0 tombstone cells [ReadStage-3] | 2019-01-06 22:21:15.673000 | x.x.x.x |           5081
                                                                           Row cache miss [ReadStage-3] | 2019-01-06 22:21:15.674000 | x.x.x.x |           6227
                                                  Executing single-partition query on tb1 [ReadStage-3] | 2019-01-06 22:21:15.674000 | x.x.x.x |           6387
                                                             Acquiring sstable references [ReadStage-3] | 2019-01-06 22:21:15.674000 | x.x.x.x |           6445
                Skipped 0/0 non-slice-intersecting sstables, included 0 due to tombstones [ReadStage-3] | 2019-01-06 22:21:15.674001 | x.x.x.x |           6514
                                                                           Caching 3 rows [ReadStage-3] | 2019-01-06 22:21:15.674001 | x.x.x.x |           6647
                                                Merged data from memtables and 0 sstables [ReadStage-3] | 2019-01-06 22:21:15.675000 | x.x.x.x |           7231
                                                   Read 1 live rows and 0 tombstone cells [ReadStage-3] | 2019-01-06 22:21:15.675000 | x.x.x.x |           7443
                                                                                       Request complete | 2019-01-06 22:21:15.676482 | x.x.x.x |           9482

然后缓存行,获取普通列: abc@cqlsh:test> SELECT pk1, ck1, normal_col2 FROM tb1 WHERE pk1=2 and ck1=1;

 pk1 | ck1 | normal_col2
-----+-----+-------------
   2 |   1 |           1

(1 rows)

Tracing session: a178ae90-11be-11e9-9cb3-fbffb1c1e13b

 activity                                                                                           | timestamp                  | source       | source_elapsed
----------------------------------------------------------------------------------------------------+----------------------------+--------------+----------------
                                                                                 Execute CQL3 query | 2019-01-06 22:23:26.201000 | x.x.x.x |              0
 Parsing SELECT pk1, ck1, normal_col2 FROM tb1 WHERE pk1=2 and ck1=1; [Native-Transport-Requests-1] | 2019-01-06 22:23:26.202000 | x.x.x.x |            205
                                                  Preparing statement [Native-Transport-Requests-1] | 2019-01-06 22:23:26.202000 | x.x.x.x |            393
                                            Executing single-partition query on roles [ReadStage-3] | 2019-01-06 22:23:26.202000 | x.x.x.x |            968
                                                         Acquiring sstable references [ReadStage-3] | 2019-01-06 22:23:26.203000 | x.x.x.x |           1413
                                                          Key cache hit for sstable 2 [ReadStage-3] | 2019-01-06 22:23:26.203000 | x.x.x.x |           1564
            Skipped 0/1 non-slice-intersecting sstables, included 0 due to tombstones [ReadStage-3] | 2019-01-06 22:23:26.203000 | x.x.x.x |           1685
                                            Merged data from memtables and 1 sstables [ReadStage-3] | 2019-01-06 22:23:26.203000 | x.x.x.x |           1841
                                               Read 1 live rows and 0 tombstone cells [ReadStage-3] | 2019-01-06 22:23:26.203000 | x.x.x.x |           1930
                                            Executing single-partition query on roles [ReadStage-5] | 2019-01-06 22:23:26.204000 | x.x.x.x |           2307
                                                         Acquiring sstable references [ReadStage-5] | 2019-01-06 22:23:26.204000 | x.x.x.x |           2375
                                                          Key cache hit for sstable 2 [ReadStage-5] | 2019-01-06 22:23:26.204000 | x.x.x.x |           2475
            Skipped 0/1 non-slice-intersecting sstables, included 0 due to tombstones [ReadStage-5] | 2019-01-06 22:23:26.204000 | x.x.x.x |           2584
                                            Merged data from memtables and 1 sstables [ReadStage-5] | 2019-01-06 22:23:26.204000 | x.x.x.x |           2691
                                               Read 1 live rows and 0 tombstone cells [ReadStage-5] | 2019-01-06 22:23:26.204000 | x.x.x.x |           2761
                                                                        Row cache hit [ReadStage-3] | 2019-01-06 22:23:26.205000 | x.x.x.x |           3301
                                               Read 1 live rows and 0 tombstone cells [ReadStage-3] | 2019-01-06 22:23:26.205000 | x.x.x.x |           3489
                                                                                   Request complete | 2019-01-06 22:23:26.204726 | x.x.x.x |           3726

显然 C* 将缓存整行而不是特定列。

【讨论】:

    猜你喜欢
    • 2018-02-14
    • 2017-01-29
    • 1970-01-01
    • 2011-03-16
    • 1970-01-01
    • 2014-09-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多