【问题标题】:neo4j Out of Memory error when using python使用python时neo4j内存不足错误
【发布时间】:2021-01-05 16:44:01
【问题描述】:

在 Python 中运行 neo4j 查询时出现以下内存不足错误。我正在使用neo4j 4.1.0 desktop

neo4j.exceptions.ClientError: {code: Neo.ClientError.Procedure.ProcedureCallFailed} {message: Failed to invoke procedure `gds.alpha.shortestPath.deltaStepping.stream`: Caused by: java.lang.OutOfMemoryError: Java heap space}

我已按照说明更改可用内存:https://neo4j.com/docs/operations-manual/current/configuration/neo4j-conf/ 并为 conf 文件中的相关参数分配了 12GB:

dbms.memory.heap.initial_size=12g
dbms.memory.heap.max_size=12g
dbms.memory.pagecache.size=12g

我的数据库有 63,000 个节点和 57,000 个关系

我的 python 代码如下所示,在循环中调用,id 的值每次都在变化:

neo4j_session = neo4j_driver.session()
results_data = neo4j_session.run("MATCH (start:Person {id: 21) \
        CALL gds.alpha.shortestPath.deltaStepping.stream({ \
            nodeQuery:'MATCH(n:Person) RETURN id(n) AS id', \
            relationshipQuery:'MATCH (p1:Person {id: 21})-[p1Knows:KNOWS]->(p1s)-[r:IS_MEMBER_OF*..10]-(p2s)<-[p2Knows:KNOWS]-(p2:Person) WHERE p1.id <> p2.id and p1Knows.self_rating <> 0 and p1Knows.self_rating < p2Knows.self_rating with p1, p2, reduce(cost = 0, x IN r | cost + coalesce(x.distance, 0)) as cost  RETURN id(p1) AS source, id(p2) AS target, cost AS weight', \
            startNode: start, \
            relationshipWeightProperty: 'weight', \
            delta: 3.0, \
            writeProperty: 'sssp' \
        }) \
        YIELD nodeId, distance \
        where gds.util.isFinite(distance) \
        with nodeId, gds.util.asNode(nodeId) as n, distance \
        RETURN n.name AS Name, distance AS Cost \
        ORDER BY Cost".format(person_id)).data()

neo4j_session.close()

错误不会每次都出现在同一个id上,所以我想知道我是否没有正确使用python驱动程序并且没有清理一些东西?

如果不是,我真的需要 12GB 的内存来查询图表吗?

【问题讨论】:

    标签: python neo4j


    【解决方案1】:

    我总是调用 write_transaction 然后使用 run 执行查询对我来说工作正常,我的数据库比你的大得多,没有错误。 问题可能是您在 for 循环中打开和关闭会话。

     def data(tx):
         # run your for loop here
         tx.run(" RUN YOUR QUERY ")
    
     with driver.session() as session:
        session.write_transaction(data)
     driver.close()
    

    【讨论】:

    • 谢谢。不幸的是仍然有同样的错误:(但很高兴知道write_transaction
    • 你试过直接在 neo4j 上运行 cypher 查询吗?
    • 是的。单独的查询很好。当它们组合成一个循环时,它就会倒下。
    • 尝试在查询之间设置超时
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-06-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-15
    • 2016-10-10
    • 1970-01-01
    相关资源
    最近更新 更多