Database Reference
In-Depth Information
Figure 5.5. Performance of node lookup using index compared to iterating through all nodes
The solid line shows that the average time taken to find a node, if you simply search all
nodes, is directly proportional to the number of nodes in the graph. This is not too surpris-
ing;themorenodesyouhave,themoreyou'llstumbleblindlyaroundthegraphbeforeyou
happen upon the user node you're looking for.
In marked contrast, the dotted line shows the time taken to find the user node using an
email index. While this number varies a little, the variation is small, with an average of 0.1
to 0.3 milliseconds per search. When the test tops out at 1 million users, the search of all
nodes is on average one thousand times slower than finding the user with an index.
Notes on the lookup benchmark
Note that it's considered bad practice to store the Neo4j ID externally for lookups because
it'spossiblethatthisIDmaychangeinsomecircumstances. ThenodeIDshouldbetreated
asaninternalimplementationdetailofNeo4jandshouldn'tbestoredinordertoenablefast
access.
The other way you can get at the nodes in the graph is via the getAllNodes method,
which returns an Iterable that allows you to iterate through all the nodes in the graph.
This can be a viable strategy for smaller datasets, but there's a performance overhead to
loading large parts of the graph each time you need to find a particular node.
 
Search WWH ::




Custom Search