py2neoを使用して、さまざまな深度の完全なバイナリツリーを構築しようとしています。私はpy2neoトランザクションを使用してサーバーにcreate文を送信しようとしていましたが、実行時はひどいです。py2neoトランザクションでグラフを作成する際のパフォーマンスの問題
深さ8(255ノード)のツリーの構築には約16.7秒かかります。トランザクションがコミットされている間、その時間の大半は費やされます(I Transaction.processランタイム)。何が問題なの? cypherステートメントはそれぞれ1つのMatchとnode + relationship Createです。
ここツリー
def buildBinaryTree(self):
depth = 1
tx = self.graph.begin()
g = self.graph
leaves = []
leaves.append("Root")
tx.run('CREATE(n {ruleName: "Root"})')
timeSum = 0
while depth < self.scale:
newLeaves = []
for leaf in leaves:
leftName = leaf + 'L'
rightName = leaf + 'R'
newLeaves.append(leftName)
newLeaves.append(rightName)
start = timer()
statement = ('MATCH(n {ruleName: "' + leaf + '"}) '
'WITH n CREATE (n)-[:`LINKS TO`]'
'->({ruleName: "' + leftName + '"})')
tx.run(statement)
statement = ('MATCH(n {ruleName: "' + leaf + '"}) '
'WITH n CREATE (n)-[:`LINKS TO`]'
'->(m {ruleName: "' + rightName + '"})')
tx.run(statement)
end = timer()
timeSum += (end - start)
leaves = newLeaves
depth += 1
print("Depth = " + str(depth))
print(timeSum)
start = timer()
print("Processing...")
tx.process()
print (timer() - start)
print("Committing...")
tx.commit()
print("Committed")
print (timer() - start)
を構築し、規模= 8
building tree...
Depth = 2
Depth = 3
Depth = 4
Depth = 5
Depth = 6
Depth = 7
Depth = 8
0.009257960999775605
Processing...
16.753949095999815
Committing...
Committed
17.28687257200022
他の人が問題を理解するために使用しているコードを含めてください。 – manassehkatz