Database Reference
In-Depth Information
10.5.1. Avoid fine-grained operations
As a general rule, when performing any kind of operations over a network, you should aim
tominimizethenumberofnetworkhopsrequiredtocarryoutthatoperation,andthissame
principle should also be applied to the manner in which the REST API is used. The raw,
low-level REST API operations are very fine-grained, typically operating on a single node
or relationship at any time. They can generate a lot of unnecessary network traffic if used
inappropriately.
Rather than only using the discoverable low-level REST API for retrieving data, you
should consider the following alternatives that may result in far fewer network calls and
much better performance:
• Use the Cypher REST endpoint
• Use the Traversal REST endpoint
• Create a server plugin or unmanaged extension to return results
For creating data, consider these options:
• Use the mutating functionality in the Cypher API
• Use the REST batch API
• Create a server plugin or unmanaged extension to perform your task
If you use the raw REST API with its hypermedia-driven approach to get the information
you need for the example scenario, you'll need a total of 602 network calls in order to ac-
complish this. Assuming the Neo4j server is running locally on port 7474, you'd need to
do the following:
• 1 GET onhttp://localhost:7474/db/data/node/0togettheinitialinformationondata
and options available for Adam.
• 1 GET on http://localhost:7474/db/data/node/{nId}/relationships/all/
IS_FRIEND_OF to get a listing of all the IS_FRIEND_OF relationships to and
from Adam (see listing 10.6 for request/response details).
• 600 GET sonhttp://localhost:7474/db/data/node/{nId}/propertiestogeteachofthe
relationship structures returned in this first call (there will be 600 entries). You'd
then use the end URI to construct the next call, which will return all of the prop-
erties for the ending (friend) node. The JSON returned in each of these calls could
then be parsed and used to only return those names starting with a J .
Search WWH ::




Custom Search