2

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?

Daniel
  • 127
  • 7
  • You can also just issue a raw web-request to fetch the underlying data via the transactional endpoint, you'll have to parse the JSON yourself. There are also some other .Net drivers which are just thin wrappers around the http endpoint. – Michael Hunger Feb 29 '16 at 13:41

1 Answers1

3

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 Banks 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 :/

Charlotte Skardon
  • 6,220
  • 2
  • 31
  • 42
  • You are correct about the comparison to the web version. This is an answer that I was already presuming, but was not really sure about. There is enough detail for me to be satisfied with the answer. Indeed, the web client shows the relationships and the rest response contains no such data. Thanks for the answer. I had hoped it would be a problem on my account in stead of external factors. – Daniel Feb 29 '16 at 12:00