DSE:查询超时/慢

Posted

技术标签:

【中文标题】DSE:查询超时/慢【英文标题】:DSE: Query Timeout/Slow 【发布时间】:2019-09-28 02:11:53 【问题描述】:

我目前正在运行一个包含 3 个节点的集群,其中包含 200 个数据和特定顶点,我正在查询总共 25 个 Mill 顶点和 30 个 Mill 边。我正在运行以下查询

g.V().hasLabel('people_node').has("age", inside(0,25)).filter(outE('posted_question').count().is(gt(1))).profile()

我已经在较小的一组约 100 个顶点和边上尝试了此查询,并且分析器显示索引已用于查询的所有部分。但是,我认为问题可能出在我的架构中,如下所示。

架构

schema.propertyKey('id').Text().ifNotExists().create()
schema.propertyKey('name').Text().ifNotExists().create()
schema.propertyKey('age').Int().ifNotExists().create()
schema.propertyKey('location').Point().withGeoBounds().ifNotExists().create()
schema.propertyKey('gender').Text().ifNotExists().create()
schema.propertyKey('dob').Timestamp().ifNotExists().create()

schema.propertyKey('tags').Text().ifNotExists().create()
schema.propertyKey('date_posted').Timestamp().ifNotExists().create()

schema.vertexLabel('people_node').properties('id','name','location','gender','dob').create()
schema.vertexLabel('questions_node').properties('id','tags','date_posted').create()
schema.edgeLabel('posted_question').single().connection('people_node','questions_node').create()

使用的索引

schema.vertexLabel("people_node").index("search").search().by("name").by("age").by("gender").by("location").by("dob").ifNotExists().add()
schema.vertexLabel("people_node").index("people_node_index").materialized().by("id").ifNotExists().add()

schema.vertexLabel("questions_node").index("search").search().by("date_posted").by("tags").ifNotExists().add()
schema.vertexLabel("questions_node").index("questions_node_index").materialized().by("id").ifNotExists().add()

我还阅读了有关“OLAP”查询的信息,我相信我已经激活了它,但查询仍然太慢。任何关于是什么减慢它的建议或见解将不胜感激。

个人资料声明 (OLTP)

gremlin> g1.V().has("people_node","age", inside(0,25)).filter(outE('posted_question').count().is(gt(1))).profile()
==>Traversal Metrics
Step                                                               Count  Traversers
     Time (ms)    % Dur
=============================================================================================================
DsegGraphStep(vertex,[],(age < 25 & age > 0 & l...                     1           1
        38.310    25.54
  query-optimizer
         0.219
    \_condition=((age < 25 & age > 0 & label = people_node) & (true))
  query-setup
         0.001
    \_isFitted=true
    \_isSorted=false
    \_isScan=false
  index-query
        26.581
    \_indexType=Search
    \_usesCache=false
    \_statement=SELECT "community_id", "member_id" FROM "MiniGraph"."people_node_p" WHERE "solr_query" = '"q
                ":"*:*", "fq":["age:0 TO 25"]' LIMIT ?; with params (java.lang.Integer) 50000
    \_options=Optionsconsistency=Optional[ONE], serialConsistency=Optional.empty, fallbackConsistency=Option
              al.empty, pagingState=null, pageSize=-1, user=Optional[cassandra], waitForSchemaAgreement=true,
               async=true
TraversalFilterStep([DsegVertexStep(OUT,[posted...
       111.471    74.32
  DsegVertexStep(OUT,[posted_question],edge,(di...                     1           1
        42.814
    query-optimizer
         0.227
    \_condition=((direction = OUT & label = posted_question) & (true))
    query-setup
         0.036
    \_isFitted=true
    \_isSorted=false
    \_isScan=false
    vertex-query
        29.908
    \_usesCache=false
    \_statement=SELECT * FROM "MiniGraph"."people_node_e" WHERE "community_id" = ? AND "member_id" = ? AND "
                 ~~edge_label_id" = ? LIMIT ? ALLOW FILTERING; with params (java.lang.Integer) 1300987392, (j
                 ava.lang.Long) 1026, (java.lang.Integer) 65584, (java.lang.Integer) 2
    \_options=Optionsconsistency=Optional[ONE], serialConsistency=Optional.empty, fallbackConsistency=Optio
               nal.empty, pagingState=null, pageSize=-1, user=Optional[cassandra], waitForSchemaAgreement=tru
               e, async=true
    \_usesIndex=false
  RangeGlobalStep(0,2)                                                 1           1
         0.097
  CountGlobalStep                                                      1           1
         0.050
  IsStep(gt(1))
        68.209
DsegPropertyLoadStep
         0.205     0.14
                                            >TOTAL                     -           -
       149.986        -

接下来,由于部分查询要快得多,我假设长时间消耗是由于必要的图遍历。因此,是否可以缓存或激活索引 (_usesIndex=false) 以便 OLAP 查询更快?

【问题讨论】:

【参考方案1】:

请您发布 .profile 语句的输出吗?

从语义上讲,您似乎正在尝试查找所有未满 25 岁且已发布超过 1 个问题的“人”。那准确吗?

【讨论】:

我已经更新了帖子并添加了个人资料声明,现在这是在总共约 90 个节点的较小样本量上完成的,是的,我正在尝试搜索所有 25 岁以下的人已发布超过 1 个问题。@Jonathan Lacefield 以我个人对datastax图的经验,即使在中等数据集中进行搜索或过滤操作也会导致性能下降。所以最好将这类操作重定向到 Solr 查询。

以上是关于DSE:查询超时/慢的主要内容,如果未能解决你的问题,请参考以下文章

为啥在elasticsearch慢查询中take_millis和超时之间有很多时间成本

sqlserver查询很慢、而且超时为啥?

oracle数据库约200W数据查询非常慢,查询需要10几秒,经常查询超时,这个正常吗?有没有啥好的办法解决

Redis的慢查询日志

一分钟快速搞懂Redis的慢查询分析

如何在 DSE Search json 查询中使用转义字符?