Neo4j 使用cypher查询时,螺栓连接的速度有选择地慢,而基于Web的GUI总是快
我有两个问题:q1和q2。我使用下面的代码查询我的neo4j数据库Neo4j 使用cypher查询时,螺栓连接的速度有选择地慢,而基于Web的GUI总是快,neo4j,cypher,bolt,neo4j-python-driver,Neo4j,Cypher,Bolt,Neo4j Python Driver,我有两个问题:q1和q2。我使用下面的代码查询我的neo4j数据库 driver = GraphDatabase.driver("bolt://localhost:7687",auth= neo4j_user,neo4j_password)) neo4j_session = driver.session() t = time.time() neo4j_session.run(q1,q1_parameters) print(time.time()-t) t = time.time() neo
driver = GraphDatabase.driver("bolt://localhost:7687",auth= neo4j_user,neo4j_password))
neo4j_session = driver.session()
t = time.time()
neo4j_session.run(q1,q1_parameters)
print(time.time()-t)
t = time.time()
neo4j_session.run(q2,q2_parameters)
print(time.time()-t)
neo4j在web界面上以大约10毫秒的时间执行q1和q2。上述代码也在大约10毫秒内执行q1,但q2在1秒内执行
为什么neo4j bolt connection不喜欢特定的查询q2,即使web界面的执行速度快了100倍?我相信这不是连接开销,因为q1的执行速度几乎和任何一种方式一样快您不应该为每个查询创建新的驱动程序和会话 Python Bolt驱动程序的示例提供了以下快速示例,说明如何使用相同的驱动程序和会话在3个写事务和1个读事务中运行4个查询:
谢谢你的回复。我应该明确指出,我不会每次都创建一个新会话。我只做了一次会话,并不断重复使用多次发送带有不同参数的q1和q2。一个快一个慢。两者在Web GUI中都很快。
from neo4j.v1 import GraphDatabase
driver = GraphDatabase.driver("bolt://localhost:7687", auth=("neo4j", "password"))
def add_friends(tx, name, friend_name):
tx.run("MERGE (a:Person {name: $name}) "
"MERGE (a)-[:KNOWS]->(friend:Person {name: $friend_name})",
name=name, friend_name=friend_name)
def print_friends(tx, name):
for record in tx.run("MATCH (a:Person)-[:KNOWS]->(friend) WHERE a.name = $name "
"RETURN friend.name ORDER BY friend.name", name=name):
print(record["friend.name"])
with driver.session() as session:
session.write_transaction(add_friends, "Arthur", "Guinevere")
session.write_transaction(add_friends, "Arthur", "Lancelot")
session.write_transaction(add_friends, "Arthur", "Merlin")
session.read_transaction(print_friends, "Arthur")