Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Neo4J's APOC plugin (3.1.3.6) is running very slow

I recently upgraded my Neo4j to 3.1.3, and alongside that, got the most recent APOC plugin (3.1.3.6).

I had a bit of code that worked fine, and could create ~3 million relationships in about a minute and a half wall time. But now, it's been running for over 8 hours and shows no sign of stopping...

Because the code used to run without any problems, I'm hoping something must have changed between versions that has lead to my code having been borked.

Is it rock_n_roll that should be changed (maybe to apoc.periodic.commit with positional arguments or something)? Thanks for any insight.

Here's what I'm running .

CALL apoc.periodic.rock_n_roll(
  "MATCH (c:ChessPlayer),(r:Record) WHERE c.ChessPlayer_ID = r.ChessPlayer RETURN c,r",
  "CYPHER planner=rule WITH {c} AS c, {r} AS r CREATE (c)-[:HAD_RECORD]->(r)",
  200000)
like image 724
Monica Heddneck Avatar asked Nov 08 '22 22:11

Monica Heddneck


1 Answers

My understanding is that call is querying the Cartesian product of ChessPlayers and Records, and then trying to filter them out row by row, and then doing the batch update on those final results (which eats a lot of memory, I think this one opening transaction is what's killing you). So if you can break it up so that each transaction can touch as few nodes as possible, it should be able to perform massively better (especially if r.ChessPlayer is indexed, since now you don't need to load all of them)

CALL apoc.periodic.rock_n_roll(
  "MATCH (c:ChessPlayer) WHERE NOT EXISTS((c)-[:HAD_RECORD]->()) RETURN c",
  "MATCH (r:Record) WHERE c.ChessPlayer_ID = r.ChessPlayer WITH c,r CREATE UNIQUE (c)-[:HAD_RECORD]->(r)",
  100000)

periodic.commit() would work on a similar principle. The smaller (least nodes touched) you can make each transaction, the faster the batch will become.

like image 154
Tezra Avatar answered Nov 25 '22 03:11

Tezra