private static void findParh(Node endNode) throws InterruptedException{
Stack <Node>stack = new Stack<Node>();
stack.push(endNode);
RelationshipType is_inside_type =
DynamicRelationshipType.withName("IS_INSIDE");
RelationshipType connected_to_type =
DynamicRelationshipType.withName("CONNECTED_TO");
while(!stack.isEmpty()){
Node node = stack.peek();
boolean all_visited = true;
boolean inside = false;
Iterator<Relationship> rel_is_inside =
node.getRelationships(is_inside_type, Direction.INCOMING).iterator();
Iterator<Relationship> rel_connected_to =
node.getRelationships(connected_to_type, Direction.INCOMING).iterator();
if(!rel_connected_to.hasNext() && !rel_is_inside.hasNext()) stack.pop();
int i = 0;
while (rel_is_inside.hasNext()) {
i++;
inside = true;
Relationship relation = rel_is_inside.next();
stack.push(relation.getStartNode());
}
while(rel_connected_to.hasNext()){
Relationship relation2 = rel_connected_to.next();
if(!visited.contains(relation2.getStartNode().getId())) {
visited.add(relation2.getStartNode().getId());
all_visited = false;
stack.push(relation2.getStartNode());
}
}
if(all_visited && !inside) stack.pop();
}
}
This method takes node with label Equipment and name='name' as
argument. There are 77 nodes with Equipment label with an index on property
'name' and 921104 nodes with label Cable. I do not want to limit depth as I
want to find all endnodes (m) from this path. All the relationships are
unidirectional. Traversing this path '(n:Equipment)<-[IS_INSIDE*]-()' takes
about 300ms, however I actually never succeed to finish the whole query. I
am running it on 64-bit Windows, RAM 8 GB.
Thanks for your quick answer.
четверг, 30 января 2014 г., 12:04:30 UTC+1 пользователь Michael Hunger
написал:
>
> Can you share your java code? Do you run the bidirectional pattern
> matcher?
>
> How much RAM do you have in total? What kind of disk and OS ?
>
> How many :Cable nodes do you have? And how many :Equipment nodes?
>
> How many paths are returned from that query?
>
> Have you considered limiting the max depth?
>
> Do you have an index for :Equipment(name) ?
>
> Michael
>
> Am 30.01.2014 um 11:49 schrieb Alina Arm <[email protected] <javascript:>
> >:
>
> I have a database with 2.217.731 nodes and 3.127.475 relationships, where
> nodes are different equipment and relationships between them are like
> "CONNECTED_TO", "IS_INSIDE", etc.
>
> I am trying to traverse the graph to find specific nodes. In Cypher it
> would look like
>
> MATCH (n:Equipment)<-[IS_INSIDE*]-()<-[CONNECTED_TO*]-(m:Cable)
> where n.name = "name" RETURN m
>
> using Java Core API, which as I know should be the fastest way to query
> Neo4j and take seconds, however it runs for tens of minutes.
>
> I am using neo4j-2.0.0 and java version "1.7.0_45", max Java Heap size 7
> gigs
>
> Neo4j properties:
>
> Map<String, String> config = new HashMap<>();
>
> config.put( "neostore.nodestore.db.mapped_memory", "1800M" );
> config.put( "neostore.relationshipstore.db.mapped_memory", "3G" );
> config.put( "neostore.propertystore.db.mapped_memory", "100M" );
> config.put( "neostore.propertystore.db.strings.mapped_memory",
> "150M" );
> config.put( "neostore.propertystore.db.arrays.mapped_memory",
> "10M" );
>
> inserter = BatchInserters.inserter("target/graphDb", config);
>
> I am new in Neo4j and do not know how to tune it to achieve better
> performance. Any suggestions?
>
> --
> 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] <javascript:>.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>
--
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/groups/opt_out.