Multi-threading for read-only algorithm through Neo4j Procedure

Skip to first unread message

Shashika Ranga Muramudalige

Jul 23, 2019, 1:10:42 AM7/23/19
to Neo4j
I have a big graph search algorithm which has implemented through Neo4j java API (Using as a Neo4j Procedure). I am trying to use threads (thread-pool) in order to improve the performance of the algorithm. The algorithm is totally a read-only but each thread needs to be a transaction in Neo4j to satisfy the ACID properties.

try (Transaction tx= db.beginTx()) {

Since this is a transaction, I think a node can be accessed by a single thread at once. Please correct me if I am wrong.
  • Is there a way to avoid this and access the same node by multiple threads at once because the algorithm performs read-only operations? (Otherwise, I cannot achieve significant performance improvement)
At the end of the execution, I have to collect all the results from threads and use Stream<Object>  to retrieve search results. So, threads are not totally executed independently because a common data structure is needed to collect all thread results after threads execution. To address that, I have used Callable<Object> interface. The problem with this approach is, it waits to all thread results sequentially. Some threads which start later can be finished the execution earlier compared to some other older threads. Since results are collected sequentially, already finished threads have to wait until get their chance.
  • Is there a way to overcome this issue or any alternate for Callable interface that we can collect results to a common data structure as soon as threads complete their work?

Reply all
Reply to author
0 new messages