在Neo4J 3.5中创建200K与节点的关系需要花费大量时间吗? [英] creating 200K relationships to a node is taking a lot of time in Neo4J 3.5?

查看:109
本文介绍了在Neo4J 3.5中创建200K与节点的关系需要花费大量时间吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个这样的顶点

Vertex1

{
    name:'hello',
    id: '2',
    key: '12345',
    col1: 'value1',
    col2: 'value2',
    .......
}

Vertex2,Vertex3,..... Vertex200K

{
    name:'hello',
    id: '1',
    key: '12345',
    col1: 'value1',
    col2: 'value2',
    .......
}

密码查询

MATCH (a:Dense1) where a.id <> "1" 
WITH a 
MATCH (b:Dense1) where b.id = "1" 
WITH a,b 
WHERE a.key = b.key 
MERGE (a)-[:PARENT_OF]->(b)

最终结果应为 Vertex1 ,度数应为 200K ,因此,应存在20万个关系.但是,上面的查询花费大量时间,几乎使吞吐量降低到500/秒.关于如何更快地建立关系/优势的任何想法?

The end result should be Vertex1 should have a degree of 200K, therefore, there should be 200K relationships. However, the above query takes a lot of time pretty much killing the throughput to 500/second. Any ideas on how to create relationships/edges quicker?

当我运行配置文件时,上面的密码查询将永远运行并且不会返回,因此我将大小从200K减小到20K,这是配置文件向我显示的内容.

When I run the profile and the cypher query above it keeps running forever and doesn't return so I reduced the size from 200K to 20K and here is what the profile is showing me.

推荐答案

鉴于您的内存限制以及与您的关系合并相关的高数据库命中率,问题很可能是您试图在一个数据库中合并200k关系单笔交易.您可能应该使用 apoc.periodic.iterate()来自 APOC程序:

Given your memory constraints, and the high db hits associated with your MERGE of the relationships, the issue is likely that you're trying to MERGE 200k relationships in a single transaction. You should probably batch this by using apoc.periodic.iterate() from APOC Procedures:

CALL apoc.periodic.iterate("
MATCH (a:Dense1) 
WHERE a.id <> '1'
MATCH (b:Dense1) 
WHERE b.id = '1' AND a.key = b.key 
RETURN a, b",
"MERGE (a)-[:PARENT_OF]->(b)",
{}) YIELD batches, total, errorMessages
RETURN batches, total, errorMessages 

这应该一次批量合并10k.

This should batch those merges 10k at a time.

此外,如果您偶然发现这些关系尚不存在,请使用CREATE而不是MERGE,这样会更快.

Also, if you happen to know for a fact that those relationships don't yet exist, use CREATE instead of MERGE, it will be faster.

这篇关于在Neo4J 3.5中创建200K与节点的关系需要花费大量时间吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆