繁体   English   中英

使用Cypher加速py2neo

[英]Speeding up py2neo using Cypher

我正在将一个SQLite3数据库中的图形填充到neo4j中,在Ubuntu linux上使用py2neo和Python 3.2。 尽管速度并不是最重要的考虑因素,但在总共500万行中,图表在大约3小时内只获得了40K行(每个sql行一个关系)。

这是主循环:

from py2neo import neo4j as neo
import sqlite3 as sql

#select all 5M rows from sql-database
sql_str =  """select * from bigram_with_number"""  

#loop through each row
for (freq, first, firstfreq, second, secondfreq) in sql_cursor.execute(sql_str):

    # create the Cypher query string using cypher 2.0 with merge
    # so that nodes are created only if needed

    query = neo.CypherQuery(neo4j_db,"""
        CYPHER 2.0 
            merge (n:word {form: {firstvar}, freq: {freqfirst}})
            merge(m:word {form: {secondvar}, freq: {freqsecond}}) 
            create unique (n)-[:bigram {freq: {freqbigram}}]->(m) return n, m""")
    #execute the string with parameters from sql-query
    result = query.execute(freqbigram = freq, firstvar = first, freqfirst=firstfreq, secondvar=second, freqsecond=secondfreq)

尽管数据库填充得很好,但它需要几周才能完成。 我怀疑有可能更快地做到这一点。

对于批量加载,您可能最好绕过REST接口并使用较低级别的东西,例如Michael Hunger的加载工具: https//github.com/jexp/neo4j-shell-tools 即使在最佳性能下,REST接口也不太可能达到您所需的速度。

顺便说一句,请注意我虽然支持3.3,但我没有正式支持Python 3.2。

暂无
暂无

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

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