0
votes

I've built a Java application that uses Spring and Neo4J in REST mode. The Neo4j is installed on Linux Red Hat machine and I changed nothing in its default configuration.

Queries / inserts run VERY slow when I use my Java Services to query data, but the same queries run fast when I do the same operations through the remote web admin.

for example, I have a query that runs in few milliseconds when I run it from the web admin, but it takes more than 30 seconds (!!) to return when calling it from my Rest service. Currently, I don't have a lot data on my DB (yet) - few thousands of nodes.

I don't have a clue where the problem might be - I guess that if directly it runs fast, it should be fast too when running from my service, isn't it?

This is an example query (I indented it for easy read):

   @Query("start movie=node({0}) 
           match (topic)<-[r:relatesToTopic]-(movie) 
           where r.orderInTop5? is not null and r.orderInTop5?>0 
           return topic order by r.orderInTop5 asc;")
    public Iterable<Topic> findTopTopics(Content content);

Directly in the web admin, it looks like this:

start movie=node(50537) 
match (topic)<-[r:relatesToTopic]-(movie)
where r.orderInTop5? is not null and r.orderInTop5?>0 
return topic.name  , topic.category, r.orderInTop5
order by r.orderInTop5 asc;

If it matters, the relatesToTopic relationship is declared on an abstract parent class and not on the Movie class itself.

I think I have a general problem because it is slow for any query or create. Services that doesn't use the Neo4J run very fast.

Can it be the REST configuration? something else?

I appreciate any ideas where to look for or what to test.

Thanks Carmel

2

2 Answers

1
votes

I found that the problem is not with the neo4j itself but rather with the iterating over the results.

My repository extends org.springframework.data.neo4j.repository.GraphRepository. I use 'findAll()' method that returns Iterator, as is.

The next() operation takes 1-4 seconds!

I read in another forum that I should use RestCypherQueryEngine for querying but how can I do that when using Spring-neo4j?

This is my Spring definition:

<neo4j:config graphDatabaseService="graphDatabaseService" />

    <bean id="graphDatabaseService" class="org.springframework.data.neo4j.rest.SpringRestGraphDatabase">
        <constructor-arg value="${db.neo4j.restAddress}" />
    </bean>

    <neo4j:repositories base-package="com.vo.insight.processed" />

Thanks a lot Carmel

1
votes

Carmel,

SDN over REST is not yet providing high-performance access.

You might try to use repository methods annotated with cypher and returning only plain data, so don't return "topic" but the topic properties that you need and then use a @MapResult or @QueryResult mapping to access your return values.

See: http://docs.spring.io/spring-data/data-neo4j/docs/2.3.x/reference/htmlsingle/#d0e964