Recently I have been given the task to research and deliver a proof of concept of the effects of a NoSQL database. I have chosen Neo4j as the NoSQL database for this .NET application.
The thing is... When I execute a query using the Neo4j Client, it runs in 10-20 ms which is fantastic. Whenever I execute that query through code it takes 150-200 ms, which is huge difference.
The query is the following (a Bank is the dutch equivalent of a database)
The goal I want to achieve is get every Bank with their Children (To get the whole hierarchy):
MATCH (bank:Bank)-[:PARENT_OF]->(bank2:Bank)
Return (bank.id),collect(bank2.id)
This is the code I have used to execute the query.
var query = client.Cypher.Match("(bank:Bank)-[:PARENT_OF]->(child:Bank)")
.Return((bank, child) => new
{
Bank = bank.As<Bank>(),
Children = child.CollectAs<Bank>()
});
var list = query.Results
My question is: Why is the query 10 times slower through code as opposed to the Neo4j Client?
I presume you're comparing to the web version?
There are lots of overheads with using the client - things like the OGM
(Object Graph Mapping) sap up some performance, and then you have to add the overhead of things like the actual HTTP calls.
The client on the web (localhost:7474) doesn't have to contend with this.
You might also notice that the web client displays different things - things which the API is not returning. I imagine you get a graph showing the Bank
s all joined together with nice relationships - if you run the query and look at the REST
response - you'll notice there is no relationship data there, so it must be calling something else.
I know this isn't an ideal answer :/