我有一个宽的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 *仅可以缓存感兴趣的列?
答案 0 :(得分:0)
您可以代替使用大量列,而可以使用单个聚簇键,将较重的读取列作为早期排序,然后限制rows_per_partition以仅捕获这些键。
与仅缓存整行相比,您可能不会获得很多好处。同样,尽管键高速缓存通常对于读取性能而言是巨大的,但行高速缓存实际上仅在非常特定的情况下才有帮助(并且在某些情况下很不利),因此请确保对其进行基准测试,因为os高速缓存通常足以将重要位保留在内存中。 >
答案 1 :(得分:0)
回答我自己的问题: Cassandra将缓存该行的所有列。
摘自Jeff Carpenter和Eben Hewitt的“ Cassandra The Definitive Guide”(第二版):
行缓存可缓存整个行,并可以提高对频繁访问的行的读取访问速度,但会占用更多内存。
实验:
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>从tb1的pk1 = 2和ck1 = 1处选择pk1,ck1,normal_col2;
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 *将缓存整个行而不是特定的列。