Python3中如何提高节点和关系的插入速度
发布于 6 年前 作者 ringwong 2802 次浏览 来自 问答

目标:

通过一个Python脚本,定时向Neo4j中插入节点和关系,请问有什么方法(包括改进代码,更改Neo4j配置)来提高插入速度?

环境:

Ubuntu16.04、Neo4j 3.4.5 社区版、Python3中的驱动为neo4j-driver1.6.1

现状描述:

插入1836个节点、1950条关系,耗时约40秒,Neo4j的配置均为默认

代码:

cypher_string_list中是若干条cypher语句

    @classmethod
    def insert_data(cls, tx, cypher_string_list):
        for cypher_string in cypher_string_list:
            tx.run(cypher_string)
			
	def main(self):
	    with self._driver.session() as sess:
		    sess.write_transaction(self.insert_data, cy_list)

插入的方式是使用事务插入,插入节点时是直接merge,插入关系时是先match出两个待链接的节点,然后再merge关系 请问有什么要优化和注意的地方吗?谢谢!

1 回复

你相当于一条一条提交。是比较慢。不知道python有没有批量提交。

回到顶部