Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Neo4j Match / Retrieving Query taking too much time 25 sec

My System is 8 core and 16 GB RAM. But still traversing :User nodes takes too much time around 25 seconds.

I am set 2 properties as in neo4j-wrapper.conf :

wrapper.java.initmemory = 6144
wrapper.java.maxmemory = 12288
  • :User returning fields 15-20;
  • 2-3 Indexes (created_at have index)
  • sorting done on created_at DESC
  • total 5 million nodes having database size of almost 8GB
  • :User nodes are 4 Million.
  • Pagination is done. Per page 10 records are fetched.
  • Without ORDER By it gives results in 0.3 seconds.
MATCH (u:User)
RETURN id(u) as id, u.username, u.email, (..15 More fields..), u.created_at as created_at
ORDER BY created_at desc 
SKIP 0 LIMIT 10

How can I reduce response time from Neo4j server? What neo4j.properties can be set to reduce execution time?

like image 825
Somnath Muluk Avatar asked May 15 '15 08:05

Somnath Muluk


2 Answers

Indexes in Neo4j are used for lookup of nodes and not for sorting. If you want to paginate a sorted list of 4M nodes it will take some time.

The way to solve that is by proper data modelling. When adding a new User consider having a :PREV_USER relationship to the one being created before the current one, the users in your system will form a linked list holding the users in timely order.

This linked list is fast and easy to traverse.

like image 147
Stefan Armbruster Avatar answered Oct 21 '22 19:10

Stefan Armbruster


I've had some luck by setting both the init memory and max memory to the same value (so the jvm doesn't have to do any resizing) and also setting the garbage collection. give these values a shot in your conf file:

-Xmx4g #max
-Xms4g #init
-XX:+UseConcMarkSweepG #garbage collector
like image 2
adam Avatar answered Oct 21 '22 19:10

adam