我在Cassandra中创建了表,并且启用了行缓存,但是启用它不会提高查询性能,查询延迟根本不会改变。
Cassandra版本:3.11.1 配置: row_cache_size_in_mb:10240 row_cache_save_period:3600
table schema:
CREATE TABLE worldscope.test_10 (
year int,
rank int,
cycname text,
name text,
value_0 float,
value_1 float,
value_2 float,
value_3 float,
value_4 float,
value_5 float,
value_6 float,
value_7 float,
value_8 float,
value_9 float,
PRIMARY KEY (year, rank)
) WITH CLUSTERING ORDER BY (rank ASC)
AND bloom_filter_fp_chance = 0.01
AND caching = {'keys': 'ALL', 'rows_per_partition': 100000}
AND comment = ''
AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32', 'min_threshold': '4'}
AND compression = {'chunk_length_in_kb': '64', 'class': 'org.apache.cassandra.io.compress.LZ4Compressor'}
AND crc_check_chance = 1.0
AND dclocal_read_repair_chance = 0.1
AND default_time_to_live = 0
AND gc_grace_seconds = 0
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 = '99PERCENTILE';
查询:从test_10中选择value_1,其中year = 2016
当我运行nodetool时,它会显示命中行缓存,如下所示:
Key Cache : entries 144, size 103.85 KiB, capacity 100 MiB, 567 hits, 723 requests, 0.784 recent hit rate, 14400 save period in seconds
Row Cache : entries 31, size 2.07 MiB, capacity 10 GiB, 279 hits, 310 requests, 0.900 recent hit rate, 3600 save period in seconds
但无论是否启用行缓存,查询延迟仍然相同,在某些测试用例中,启用行缓存后延迟甚至变得更长。
当我运行跟踪时,详细信息如下: 何时启用行缓存:
Tracing session: 0667b5d0-1c33-11e8-8e0d-c18210ebaedc
activity | timestamp | source | source_elapsed | client
---------------------------------------------------------------------------------------------------+----------------------------+-------------+----------------+-------------
Execute CQL3 query | 2018-02-27 21:56:51.117000 | 10.81.220.6 | 0 | 10.81.220.6
Parsing select value_0 from test_10 where year = 20160102 limit 10; [Native-Transport-Requests-1] | 2018-02-27 21:56:51.117000 | 10.81.220.6 | 87 | 10.81.220.6
Preparing statement [Native-Transport-Requests-1] | 2018-02-27 21:56:51.117000 | 10.81.220.6 | 154 | 10.81.220.6
Read-repair DC_LOCAL [Native-Transport-Requests-1] | 2018-02-27 21:56:51.117000 | 10.81.220.6 | 284 | 10.81.220.6
Row cache hit [ReadStage-3] | 2018-02-27 21:56:51.119000 | 10.81.220.6 | 2366 | 10.81.220.6
Read 10 live and 0 tombstone cells [ReadStage-3] | 2018-02-27 21:56:51.119000 | 10.81.220.6 | 2460 | 10.81.220.6
Request complete | 2018-02-27 21:56:51.119563 | 10.81.220.6 | 2563 | 10.81.220.6
未启用行缓存时: 追踪会议:bc0cd420-1c32-11e8-8e0d-c18210ebaedc
activity | timestamp | source | source_elapsed | client
---------------------------------------------------------------------------------------------------+----------------------------+-------------+----------------+-------------
Execute CQL3 query | 2018-02-27 21:54:46.370000 | 10.81.220.6 | 0 | 10.81.220.6
Parsing select value_0 from test_10 where year = 20160102 limit 10; [Native-Transport-Requests-1] | 2018-02-27 21:54:46.370000 | 10.81.220.6 | 124 | 10.81.220.6
Preparing statement [Native-Transport-Requests-1] | 2018-02-27 21:54:46.370000 | 10.81.220.6 | 230 | 10.81.220.6
Executing single-partition query on test_10 [ReadStage-3] | 2018-02-27 21:54:46.370000 | 10.81.220.6 | 570 | 10.81.220.6
Acquiring sstable references [ReadStage-3] | 2018-02-27 21:54:46.370000 | 10.81.220.6 | 610 | 10.81.220.6
Skipped 0/1 non-slice-intersecting sstables, included 0 due to tombstones [ReadStage-3] | 2018-02-27 21:54:46.370000 | 10.81.220.6 | 639 | 10.81.220.6
Key cache hit for sstable 1 [ReadStage-3] | 2018-02-27 21:54:46.370001 | 10.81.220.6 | 690 | 10.81.220.6
Merged data from memtables and 1 sstables [ReadStage-3] | 2018-02-27 21:54:46.371000 | 10.81.220.6 | 847 | 10.81.220.6
Read 10 live and 0 tombstone cells [ReadStage-3] | 2018-02-27 21:54:46.371000 | 10.81.220.6 | 878 | 10.81.220.6
Request complete | 2018-02-27 21:54:46.370998 | 10.81.220.6 | 998 | 10.81.220.6
你看,缓存未启用(998)显然比启用缓存时更快(2563)。
是什么原因?
答案 0 :(得分:3)
您是否使用TRACING
运行了一些查询,并且可以发布结果吗? (见https://docs.datastax.com/en/cql/3.3/cql/cql_reference/cqlshTracing.html)
当缓存命中将阻止磁盘读取时,Cassandra将从行缓存中受益。您的缓存的命中率为0.9,已经很高了。但是由于行缓存的大小只有大约2 MB的数据,我猜你之前的读取是从cassandras memtables而不是从磁盘读取提供的,所以加速效果非常小。
cqlsh:demo> SELECT value_1 FROM test_10 WHERE year = 2018;
value_1
---------
0.1
0.1
0.1
(3 rows)
Tracing session: 8ea1bd70-1ad9-11e8-b37d-63be3c2a5a29
activity | timestamp | source | source_elapsed
-------------------------------------------------------------------------------------------------+----------------------------+--------------+----------------
Execute CQL3 query | 2018-02-26 09:43:53.799000 | 85.10.240.52 | 0
Parsing SELECT value_1 FROM test_10 WHERE year = 2018; [SharedPool-Worker-1] | 2018-02-26 09:43:53.800000 | 85.10.240.52 | 262
Preparing statement [SharedPool-Worker-1] | 2018-02-26 09:43:53.800000 | 85.10.240.52 | 385
reading data from /85.10.240.60 [SharedPool-Worker-1] | 2018-02-26 09:43:53.800000 | 85.10.240.52 | 739
Sending READ message to /85.10.240.60 [MessagingService-Outgoing-/85.10.240.60] | 2018-02-26 09:43:53.800000 | 85.10.240.52 | 1005
READ message received from /85.10.240.52 [MessagingService-Incoming-/85.10.240.52] | 2018-02-26 09:43:53.802000 | 85.10.240.60 | 19
Executing single-partition query on test_10 [SharedPool-Worker-1] | 2018-02-26 09:43:53.802000 | 85.10.240.60 | 184
Acquiring sstable references [SharedPool-Worker-1] | 2018-02-26 09:43:53.802000 | 85.10.240.60 | 278
Merging memtable tombstones [SharedPool-Worker-1] | 2018-02-26 09:43:53.802000 | 85.10.240.60 | 323
Skipped 0/0 non-slice-intersecting sstables, included 0 due to tombstones [SharedPool-Worker-1] | 2018-02-26 09:43:53.802000 | 85.10.240.60 | 373
Merging data from memtables and 0 sstables [SharedPool-Worker-1] | 2018-02-26 09:43:53.802000 | 85.10.240.60 | 401
Read 3 live and 0 tombstone cells [SharedPool-Worker-1] | 2018-02-26 09:43:53.802001 | 85.10.240.60 | 608
Enqueuing response to /85.10.240.52 [SharedPool-Worker-1] | 2018-02-26 09:43:53.803000 | 85.10.240.60 | 709
REQUEST_RESPONSE message received from /85.10.240.60 [MessagingService-Incoming-/85.10.240.60] | 2018-02-26 09:43:53.803000 | 85.10.240.52 | 3972
Sending REQUEST_RESPONSE message to /85.10.240.52 [MessagingService-Outgoing-/85.10.240.52] | 2018-02-26 09:43:53.803000 | 85.10.240.60 | 948
Processing response from /85.10.240.60 [SharedPool-Worker-2] | 2018-02-26 09:43:53.804000 | 85.10.240.52 | 4060
Request complete | 2018-02-26 09:43:53.803553 | 85.10.240.52 | 4553
cqlsh:demo>
相关部分是:
Skipped 0/0 non-slice-intersecting sstables, included 0 due to tombstones [SharedPool-Worker-1] | 2018-02-26 09:43:53.802000 | 85.10.240.60 | 373
Merging data from memtables and 0 sstables [SharedPool-Worker-1] | 2018-02-26 09:43:53.802000 | 85.10.240.60 | 401
我的小型演示案例中没有涉及sstable读取或写入。