Cassandra 在不同查询上的性能

标签 cassandra cqlsh spark-cassandra-connector

在 Cassandra 中,我读到我需要设计表架构,以便达到最小数量的分区。我设计了架构来满足这个要求。但我所处的场景是我需要单独获取所有分区键。所以我打算使用

Select Distinct <partitionKeys> from table

我使用 cqlsh 对大约 15k 行运行了一个不同的查询。速度相当快。

问题

  1. 如果我使用distinct 会出现性能问题吗?
  2. cassandra 如何单独获取分区键?
  3. 我需要了解不同查询的限制。

最佳答案

Will there be any performance issues if I use distinct? How cassandra fetches partition keys alone?

基本上,Cassandra 只需要遍历节点并拉回该表的分区(行)键即可。通过这些键进行查询是 Cassandra 的设计工作原理,因此对于您来说这表现得非常好,我并不感到惊讶。缺点是它可能必须命中所有或大部分节点才能完成操作,因此如果您有大量节点,性能可能会很慢。

这就是 CQL 行和底层存储中的行之间的差异发挥作用的地方。如果您使用 cassandra-cli 工具查看数据,您可以看到分区键的处理方式有所不同。下面是一个示例,其中船员按其船舶存储在表中。

aploetz@cqlsh:presentation> SELECT * FROm shipcrewregistry ;

 shipname | lastname  | firstname | citizenid                            | aliases
----------+-----------+-----------+--------------------------------------+--------------------------------------
 Serenity |      Book |    Derial | 48bc975a-c9f2-474d-8a29-247503445877 |                       {'CLASSIFIED'}
 Serenity |      Cobb |     Jayne | 2d643fb1-54fb-4c98-8d2d-a5bb9c6c8354 |                   {'Hero of Canton'}
 Serenity |      Frye |    Kaylee | d556cf44-348b-4ea3-8c19-ba9d4877818c |                                 null
 Serenity |     Inara |     Serra | a25b7e02-8099-401a-8c41-d9d2ea894b72 |                                 null
 Serenity |  Reynolds |   Malcolm | 169382b7-21b0-47bf-b1c8-19bc008a9060 |             {'Mal', 'Sgt. Reynolds'}
 Serenity |       Tam |     River | af68201f-4135-413e-959c-dd81ea651e52 |                                 null
 Serenity |       Tam |     Simon | aa090e1a-7792-4d7b-bba9-bac66f8c1f15 |                          {'Dr. Tam'}
 Serenity | Washburne |     Hoban | 73f591df-c0dc-44c4-b3f3-9c37453c9537 |                             {'Wash'}
 Serenity | Washburne |      Zoey | 46bc77ad-53ad-4402-b252-a0543005c583 | {'Corporal Alleyne', 'Zoey Alleyne'}

(9 rows)

但是当我在 cassandra-cli 中查询时:

[default@presentation] list shipcrewregistry;
Using default limit of 100
Using default cell limit of 100
-------------------
RowKey: Serenity
=> (name=Book:Derial:48bc975a-c9f2-474d-8a29-247503445877:, value=, timestamp=1424904853420170)
=> (name=Book:Derial:48bc975a-c9f2-474d-8a29-247503445877:aliases:434c4153534946494544, value=, timestamp=1424904853420170)
=> (name=Cobb:Jayne:2d643fb1-54fb-4c98-8d2d-a5bb9c6c8354:, value=, timestamp=1424904853492976)
=> (name=Cobb:Jayne:2d643fb1-54fb-4c98-8d2d-a5bb9c6c8354:aliases:4865726f206f662043616e746f6e, value=, timestamp=1424904853492976)
=> (name=Frye:Kaylee:d556cf44-348b-4ea3-8c19-ba9d4877818c:, value=, timestamp=1428442425610395)
=> (name=Inara:Serra:a25b7e02-8099-401a-8c41-d9d2ea894b72:, value=, timestamp=1428442425621555)
=> (name=Reynolds:Malcolm:169382b7-21b0-47bf-b1c8-19bc008a9060:, value=, timestamp=1424904853505461)
=> (name=Reynolds:Malcolm:169382b7-21b0-47bf-b1c8-19bc008a9060:aliases:4d616c, value=, timestamp=1424904853505461)
=> (name=Reynolds:Malcolm:169382b7-21b0-47bf-b1c8-19bc008a9060:aliases:5367742e205265796e6f6c6473, value=, timestamp=1424904853505461)
=> (name=Tam:River:af68201f-4135-413e-959c-dd81ea651e52:, value=, timestamp=1428442425575881)
=> (name=Tam:Simon:aa090e1a-7792-4d7b-bba9-bac66f8c1f15:, value=, timestamp=1424904853518092)
=> (name=Tam:Simon:aa090e1a-7792-4d7b-bba9-bac66f8c1f15:aliases:44722e2054616d, value=, timestamp=1424904853518092)
=> (name=Washburne:Hoban:73f591df-c0dc-44c4-b3f3-9c37453c9537:, value=, timestamp=1428442425587484)
=> (name=Washburne:Hoban:73f591df-c0dc-44c4-b3f3-9c37453c9537:aliases:57617368, value=, timestamp=1428442425587484)
=> (name=Washburne:Zoey:46bc77ad-53ad-4402-b252-a0543005c583:, value=, timestamp=1428442425596863)
=> (name=Washburne:Zoey:46bc77ad-53ad-4402-b252-a0543005c583:aliases:436f72706f72616c20416c6c65796e65, value=, timestamp=1428442425596863)
=> (name=Washburne:Zoey:46bc77ad-53ad-4402-b252-a0543005c583:aliases:5a6f657920416c6c65796e65, value=, timestamp=1428442425596863)

1 Row Returned.
Elapsed time: 86 msec(s).

这旨在展示 9 个 CQL 行实际上只是“幕后”的 1 行。

I need to know the limitations on distinct query.

在 CQL 中,DISTINCT 仅适用于您的分区键。我不确定有多少行会否定它的用处。 15000 CQL 行应该足够了。但是,如果您有数百万个不同的分区键(高基数),我预计性能会下降......尤其是在集群中有多个节点的情况下。

关于Cassandra 在不同查询上的性能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30758818/

相关文章:

cassandra - Cassandra 中的复合键与 Pig

cassandra - Caasandra PRIMARY KEY column "user"cannot be restricted as preceding column "eventtype"is not restricted

java - DataStax Cassandra Exception : InvalidRequestException(why:there were 2 markers(? ) 在 CQL 中但有 3 个绑定(bind)变量

python - 在 Windows 10 上使用 python 3 运行 cassandra cqlsh

java - Cassandra 卡在 Initializing IndexInfo 上

python - CQLSH 连接错误 : Bad Request: unconfigured columnfamily local

cassandra - 为什么 Cassandra 不加载 CSV 文件中的所有值?

apache-spark - spark 如何选择 cassandra 节点进行读取?

scala - Cassandra spark 连接器编写嵌套的可选案例类

apache-spark - 使用 pyspark 将数据从 pyspark 数据帧插入到另一个 cassandra 表