2

Note - there's a similar issue to this elsewhere on Stackoverflow, but it was related to Spring Data, and I'm not using Spring Data.

I have a simple social graph built from Twitter data. ~120,000 nodes and ~200,000 relationships so far.

The performance of Neo4J seems to be a bit hit-and-miss, with queries like this occasionally taking 200 secs:

MATCH p=(:User {twId: 838853137247141888})-[:FOLLOWS*0..3]->(:User {twId: 40002648}) 
RETURN SUM(REDUCE(s = 1.0, n IN NODES(p)[0..-1] | s / SIZE((n)-->()))) AS connectedness

I've looked in logs/debug.log and note a regular stream of the following, even when there are no queries taking place on the graph:

2017-05-27 18:50:40.041+0000 WARN  [o.n.k.i.c.MonitorGc] GC Monitor: Application threads blocked for 2436ms.
2017-05-27 18:50:46.831+0000 WARN  [o.n.k.i.c.MonitorGc] GC Monitor: Application threads blocked for 5705ms.
2017-05-27 18:50:55.631+0000 WARN  [o.n.k.i.c.MonitorGc] GC Monitor: Application threads blocked for 8699ms.
2017-05-27 18:50:56.450+0000 WARN  [o.n.k.i.c.MonitorGc] GC Monitor: Application threads blocked for 719ms.

My .neo4j-community.vmoptions contains only the following

-Xmx6G

(I tried a large heap to see if this would solve the problem - it didn't)

I'm running Neo4J Community v3.1.3 on MacOS Sierra 10.12.4

To be honest I'm not sure where to start when it comes to profiling Neo or working out what the server is up to, and the documentation hasn't been very helpful with my particular issue.

Tips much appreciated.

Update:

I'm also seeing the following in my debug.log on startup

2017-05-27 19:23:06.439+0000 ERROR [o.n.k.a.i.s.LuceneSchemaIndexProvider] Failed to open index:3, requesting re-population. Lock held by this virtual machine: /Users/chris/social-graph/schema/index/lucene/3/1/write.lock
org.apache.lucene.store.LockObtainFailedException: Lock held by this virtual machine: /Users/chris/social-graph/schema/index/lucene/3/1/write.lock
        at     org.apache.lucene.store.NativeFSLockFactory.obtainFSLock(NativeFSLockFactory.java:127)
        at     org.apache.lucene.store.FSLockFactory.obtainLock(FSLockFactory.java:41)
        at     org.apache.lucene.store.BaseDirectory.obtainLock(BaseDirectory.java:45)

Update:

Indices

Query Plan

Showing all JVM args: JVisualVM Overview

Oddly the VisualVM output doesn't tally with the reported 10sec GCs in debug.log JVisualVM output

3
  • 1
    Can you confirm if you have a unique constraint or an index on :User(twId)? Without that index, your queries are going to crawl. You can prefix your query with PROFILE to get a visual plan of the query execution. Could you run that, expand all elements of the plan, export it, and add the image to the description? May 27, 2017 at 19:28
  • Thanks for getting back to me @InverseFalcon - I have added the output of :schema, and also the query plan. I do indeed have an index on :User(twId) May 27, 2017 at 19:32
  • 1
    You're probably quite aware of it, but watch out for divide by zero errors here, looks like that might be a risk if a node in the path has no outgoing relationships. May 27, 2017 at 20:56

2 Answers 2

1

Tips: jvisualvm will give you a lot of info on your running jvms, like which GC is used (in the overview tab, maybe you'll have-XX:+UseG1GC).

4
  • Thanks for the suggestion. I have updated my question with screenshots from JVisualVM May 27, 2017 at 19:52
  • 1
    there is no jvm memory args. Max is not 6G. See if you do not have env vars hijacking that value. Also, look at your conf/neo4j.conf file
    – Jerome_B
    May 27, 2017 at 20:00
  • Agreed - this is odd, though, as I followed instructions on the Neo4J launcher app, which told me to edit /Users/chris/Documents/Neo4j/.neo4j-community.vmoptions I did so, and included -Xmx6G May 27, 2017 at 20:08
  • I have also tried adding a -Xmx5G option to /Applications/Neo4j Community Edition 3.2.0.app/Contents/Resources/app/bin/neo4j-community.vmoptions but this has no effect May 27, 2017 at 20:15
1

As far as tuning the query itself, you may want to use index hints to force the plan to match on both nodes first before running the expansion, instead of the default behavior of expanding from one node then filtering the end node.

See how this works for you, both in terms of speed and PROFILE:

MATCH (start:User {twId: 838853137247141888}), (end:User {twId: 40002648}) 
USING INDEX start:User(twId)
USING INDEX end:User(twId)
MATCH p=(start)-[:FOLLOWS*0..3]->(end)
RETURN SUM(REDUCE(s = 1.0, n IN NODES(p)[0..-1] | s / SIZE((n)-->()))) AS connectedness

Note that this may not work in Neo4j 3.2, I think they've removed the RULE planner, which is needed to take advantage of the index hints.

EDIT

There IS a way around the above 3.2 restriction...it won't be as performant as the above query on 3.1.x (according to profiled db hits), but it should be more performant than the original query.

MATCH (start:User {twId: 838853137247141888}), (end:User {twId: 40002648}) 
MATCH p=(start)-[:FOLLOWS*0..3]->(x)
WHERE x = end
RETURN SUM(REDUCE(s = 1.0, n IN NODES(p)[0..-1] | s / SIZE((n)-->()))) AS connectedness
4
  • Thanks very much for the suggestion. I've just upgraded to 3.2 as it happens :-s I get "Failed to fulfil the hints of the query. Could not solve these hints: USING INDEX end:User(twId)" May 27, 2017 at 20:24
  • Having said the above, I have restructured the query as per your example (two match statements) and it runs 10x faster! May 27, 2017 at 20:25
  • 1
    Awesome to hear it, though take care if you plan on jumping to 3.2, as multiple index hints are currently erroring out, and I'm unsure if this is something that will be fixed or not, since it seems to rely on using the RULE planner, which was removed with 3.2. I'll add a variation of this query that should work on 3.2 and be more performant than the default, though it won't be as performant as the first version I provided. May 27, 2017 at 20:49
  • I get a 30% speedup with the WHERE x = end! Another very helpful suggestion - thanks very much. May 27, 2017 at 21:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.