Fast transactions between Unity 3D and Neo4j 3.4.5 through HTTP API

Hello everyone,

I have been working on a project in Unity3D game engine, where I used the HTTP API for communication with the Neo4j server.
The project is written in C# and I have used the following approach to open and commit a transaction:

https://docs.microsoft.com/en-us/dotnet/api/system.net.webrequest?view=netframework-4.7.2

Unfortunately, I noticed that for any single transaction with any single query, the process took approximately 3-4 seconds to complete. So I timed all methods involved in this process but none were found to take more than a few milliseconds to return. I concluded that Neo4j actually took all this time to return the JSON response.

I then focused on Neo4j and between meddling with my graph configuration and sending queries from Unity, I finally managed to get each query to execute in less than 50-100 milliseconds.

All I did, was to accept non-local connections by uncommenting from my graph configuration file:

dbms.connectors.default_listen_address=0.0.0.0

Unity runs locally as well as all the transactions I issued with it.
I have researched before posting here and haven't found any relevant information about how accepting non-local connections can result in transactional performance between the Neo4j server and a process that runs locally.

I found this odd and the reason I am opening this topic, is simply because I am really curious as to what really happened in this case and how Neo4j handles it. I suspect that there might be security-related processes involved, but if anyone has a solid explanation, I and future readers will appreciate it.

Thank you in advance!

Sounds really odd.
Perhaps something about your local DNS resolution?

Hi @antonios.triant,

Neo4j by default listens on IPV4 loopback interface and by un-commenting the line you mention, you've enabled it to listen on all interfaces.

My guess about this situation is that name lookup returns in IPV6, IPV4 order that causes a delay in actual connection. I'm not sure how you're creating web requests, but in case you're using host names could you please try it with IP Address (i.e. http://127.0.0.1:7474/) instead and see if it makes any difference?

1 Like

Hello @michael.hunger

Are you reffering to any configuration that has to do with Neo4j? Because the only thing I have changed in my graph's settings is to allow non-local connections as explained above.

If you are reffering to the "hosts" file in C:\Windows\System32\drivers\etc, it contains the default values, no changes there.

Hi @ali_ince,

It seems that what you said is valid!
I was using localhost instead of 127.0.0.1. Now I disallowed non-local connections, used the IP address and it works as before (if not faster).

If I understood correctly when you use host names, Neo4j resolves them to IPv6 addresses rather than IPv4? Can you share the logic behind this functionality?

Many thanks!

Hi @antonios.triant,

Glad that it's now working as expected.

Actually it has nothing to do with neo4j, because neo4j is listening on the port it's told and waits for connections to arrive from clients. Client, on the other side, resolves host names to IP adresses (in this case, one IPV6 and one IPV4 loopback addresses) through the operating system and tries to connect using the returned addresses until it succeeds (or time outs).

If you're working in an IPV6 first environment, one option could be to have neo4j listen at port ::1 so that it will accept connections on both IPV4 and IPV6 loopback addresses.

Ok, thank you for the information @ali_ince and @michael.hunger !