# Importing Relationships in Parallel is slow

**URL:** <https://community.neo4j.com/t/importing-relationships-in-parallel-is-slow/62532>\
**Category:** Procedures & APOC\
**Tags:** apoc\
**Created:** [May 15, 2023, 4:02pm UTC](https://community.neo4j.com/t/importing-relationships-in-parallel-is-slow/62532 "2023-05-15T16:02:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![john.e.duong](https://avatars.discourse-cdn.com/v4/letter/j/c5a1d2/32.png) [@john.e.duong](https://community.neo4j.com/u/john.e.duong)\
**Post date:** [May 15, 2023, 4:02pm UTC](https://community.neo4j.com/t/importing-relationships-in-parallel-is-slow/62532/1 "2023-05-15T16:02:54Z")

</div>

I'm a bit new to the Neo4j, cypher and apoc.

I have this custom apoc function that is similar to apoc.periodic.iterate which is a java procedure that bins and create relationships in rounds and ensure no two nodes are ever written to at the same time.  
This is the code basically copying for our use.  
[https://github.com/Lnofeisone/graph-iterateRelationship/blob/master/IterateRelationship.java](https://github.com/Lnofeisone/graph-iterateRelationship/blob/master/IterateRelationship.java)

The import is from a rmdbs to neo4j.  
We are trying to transition from Neo 3.5 --\> Neo 4.4 Community Edition  
The data size is probably over 10 million nodes

I updated the some of the IterateRelationship.java to match the APOC 4.4 API

Previously the processing time was quick on neo4j 3.5. We are testing now Neo4j 4.4 CE and the custom function is quite slow.

```auto
while (iteratorThreads.stream().anyMatch(x -> !x.isRetired()) &&iteratorThreads.stream().filter(x -> !x.isRetired()).allMatch(x -> !x.isFree())) {
		while (iteratorThreads.stream().filter(x -> !x.isRetired()).allMatch(IteratorThread::isWorking)) { // none done yet, block for a bit
			LockSupport.parkNanos(1000);}
// do work
}

```

So I noticed this section of code takes a long time to complete. From what I can guess is happening in this section of code is a thread is going to execute the transaction to create a relationship between two nodes. This was fast in 3.5 but slow on 4.4. CE

My question is there some thing to identify the slow down or speed this up?

---

<div class="post-metadata">

**Author:** ![mckenzma](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/mckenzma/32/78_2.png) [@mckenzma](https://community.neo4j.com/u/mckenzma)\
**Post date:** [May 26, 2023, 2:25pm UTC](https://community.neo4j.com/t/importing-relationships-in-parallel-is-slow/62532/2 "2023-05-26T14:25:50Z")

</div>

I am helping @john.e.duong work on this and we are hung up getting a solid understanding of how the core changes from 3.5 to 4.x and newer are affecting this function that is intended to expand `apoc.periodic.iterate`.

Any guidance would be appreciated.

---

<div class="post-metadata">

**Author:** ![mckenzma](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/mckenzma/32/78_2.png) [@mckenzma](https://community.neo4j.com/u/mckenzma)\
**Post date:** [September 13, 2023, 12:32pm UTC](https://community.neo4j.com/t/importing-relationships-in-parallel-is-slow/62532/3 "2023-09-13T12:32:15Z")

</div>

@john.e.duong was able to identify his error. There was an errant loop that grew exponentially within the function causing it to get stuck and nothing related to the changes within `apoc.periodic.iterate`.
