Hello Alx,
Here is my take on this so far:
...
GraphDatabaseService database = new
GraphDatabaseFactory().newEmbeddedDatabase( DB_PATH ); // thread safe, can
pass to other threads
registerShutdownHook( database ); // very important, so you don't corrupt
your database, like I have done
ExecutorService exector = Executors.newFixedThreadPool(X); // tune X
...
executor.execute(new Runnable() {
@Override
public void run() {
try(Transaction tx = database.beginTx()) {
// do graph op(s) on subsection of graph
...
tx.success();
}
}
});
...
executor.shutdown();
executor.awaitTermination(...);
Depending on the graph and your memory situation, you may be I/O bound
rather than CPU bound, so multiple threads may not help at all. The new
allSimplePaths algorithm implementation may be of help as well.
*I am assuming* that one can read one Node or Relation while writing to
another without lock contention (i.e. locks are at the Node and Relation
level); it would be nice to get a clear answer on this.
I would be interested in any results (good or bad) that you get.
On Monday, May 12, 2014 11:50:46 AM UTC-7, Alx wrote:
>
> I am starting to work with Neo4j Java API. I want to run a global
> traversal query on my database which takes quite a long time due to
> aggregations. I am thinking of using multiple threads to traverse through
> the database. So far on my Java project I have:
>
> public static void main( String[] args )
>
> {
>
> GraphDatabaseService database = new
> GraphDatabaseFactory().newEmbeddedDatabase( DB_PATH );
>
> registerShutdownHook( database );
>
>
> try (Transaction tx = database.beginTx())
> {
> retrieveConnections(database, startNode, endNode);
> tx.success();
>
> out.println(“Finished”);
> }
>
> }
>
> What is the best approach here? By using the startNode and endNode I could
> separate the threads to avoid conflicting issues. Should I call multiple
> threads inside the 'tx' transaction? Are there any examples with
> multithreading in Neo4j that I can look up? I would appreciate any help.
>
>
--
You received this message because you are subscribed to the Google Groups
"Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.