简体   繁体   English

Neo4J 保存查询性能(GrapheneDB)

[英]Neo4J save query performance (GrapheneDB)

I have created a .Net application that utilizes a Neo4J Graph Database (with GrapheneDB as a provider).我创建了一个 .Net 应用程序,它使用 Neo4J 图形数据库(使用 GrapheneDB 作为提供者)。 I am having performance issues when I save a new graph object.保存新图形对象时遇到性能问题。 I am not keeping a history of the graph so each time I save, I first delete the old one including nodes and relationships, then I save the new one.我没有保留图表的历史记录,所以每次保存时,我首先删除旧的,包括节点和关系,然后保存新的。 I have not indexed my nodes yet.我还没有索引我的节点。 I don't think this is the problem because loading multiple of these graphs at a time is very fast.我不认为这是问题,因为一次加载多个这些图非常快。

My save method steps through each branch and merges the nodes and relationships.我的保存方法遍历每个分支并合并节点和关系。 (I left the relationships out of each step for cleanliness). (为了清洁,我在每一步都忽略了关系)。 After the full query is created the code is executed in one shot.创建完整查询后,代码将一次性执行。

  1. merge the root node 37 and node 4合并根节点 37 和节点 4
  2. merge type1 node 12-17 with 4将 type1 节点 12-17 与 4 合并
  3. merge type2 node 18-22 with 4将 type2 节点 18-22 与 4 合并
  4. merge 2 with 37将 2 与 37 合并
  5. merge 7-11 with 2将 7-11 与 2 合并
  6. merge 5 with 37 (creates relationships)将 5 与 37 合并(创建关系)
  7. merge 23-26 with 5将 23-26 与 5 合并
  8. merge 6 with 37 (creates relationships)将 6 与 37 合并(创建关系)
  9. merge 30-27 with 6将 30-27 与 6 合并

Nodes 2, 4, 5, 6 can have 100-200 leaf nodes.节点 2、4、5、6 可以有 100-200 个叶节点。 I have about 100 of these graphs in my database.我的数据库中有大约 100 个这样的图表。 This save can take the server 10 - 20 seconds on production and sometimes times out.此保存可能需要服务器 10 - 20 秒的生产时间,有时会超时。

在此处输入图片说明

I have tried saving a different way, and it takes longer but doesn't timeout as frequently.我尝试以不同的方式保存,它需要更长的时间,但不会经常超时。 I create groups of nodes first.我首先创建节点组。 Each node stores the root id 37. Each group is created in a separate execution.每个节点存储根 id 37。每个组都是在单独的执行中创建的。 After the nodes are created I create relationships by selecting child nodes and the root node.创建节点后,我通过选择子节点和根节点来创建关系。 This splits the query up into separate smaller queries.这会将查询拆分为单独的较小查询。

How can I improve the performance of this save?如何提高此保存的性能? Loading 30 of these graphs takes 3-5 seconds.加载其中 30 个图表需要 3-5 秒。 I should also note that the save got significantly less performant as more data was added.我还应该注意到,随着添加更多数据,保存的性能显着降低。

Since you delete all the nodes (and their relationships) beforehand, you should not be using MERGE at all, as that requires a lot of scanning (without the relevant indexes) to determine whether each node already exists.由于您事先删除了所有节点(及其关系),因此根本不应该使用MERGE ,因为这需要大量扫描(没有相关索引)来确定每个节点是否已经存在。

Try using CREATE instead (as long as the CREATE s avoid creating duplicates).尝试改用CREATE (只要CREATE避免创建重复项)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM