【问题标题】:Cassandra performance on distinct queryCassandra 在不同查询上的性能
【发布时间】:2015-08-25 20:26:20
【问题描述】:

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

Select Distinct <partitionKeys> from table

我使用 cqlsh 对大约 15k 行运行了一个不同的查询。它非常快。

问题

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

【问题讨论】:

    标签: cassandra cqlsh spark-cassandra-connector


    【解决方案1】:

    如果我使用 distinct 会有任何性能问题吗? cassandra 如何单独获取分区键?

    基本上,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 行“在引擎盖下”。

    我需要知道不同查询的限制。

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

    【讨论】:

    • 我不太了解 cassandra 中的实际行存储。 cqlsh 中显示的行如何映射到底层 cassandra 中的实际行?请给我任何好的链接来理解它。
    • @Knight71 当然! John Berryman 写了一篇关于这个主题的很棒的文章:planetcassandra.org/blog/…
    猜你喜欢
    • 2017-01-27
    • 2015-08-18
    • 2018-10-19
    • 2011-03-11
    • 2017-03-30
    • 2017-08-13
    • 2014-02-06
    • 1970-01-01
    相关资源
    最近更新 更多