简体   繁体   English

Neo4j-查询性能下降

[英]Neo4j - query performance degradation

Here is my query: 这是我的查询:

MATCH (p:Publisher)-[r:PUBLISHED]->(w:Woka)-[s:AUTHORED]-(a:Author) 
MATCH (l:Language)-[t:USED]->(w:Woka) 
WHERE (a.author_name =~ '.*Camus.*' and a.author_name =~ '.*Albert.*') 
RETURN p.publisher_name, w.woka_title, a.author_name, l.language_name;

The first time this is executing the result is returned in 3.8 seconds. 第一次执行此结果将在3.8秒内返回。 For the second execution couple minutes later the result is returned in 15.1 seconds. 在几分钟后的第二次执行中,结果将在15.1秒内返回。 The more I am executing the longer the response time. 我执行的越多,响应时间就越长。 For the third execution the response time is increasing and several moments later I am getting the results between 30 and 90 seconds. 对于第三次执行,响应时间增加了,稍后,我得到了30到90秒之间的结果。

I am the only user of this (development) database. 我是该(开发)数据库的唯一用户。 No data is added or deleted or changed there. 此处未添加,删除或更改任何数据。 No indexes are dropped or created also there. 也没有在那里删除或创建索引。 When closing two out of three connections to the database the response time goes back to 15 seconds. 当关闭与数据库的三个连接中的两个时,响应时间回到15秒。

Memory is set 4GB as init and max up to 8GB. 内存设置为4GB作为init,最大可设置为8GB。 Server has 16GB total memory. 服务器总内存为16GB。

What is happening here? 这是怎么回事 Why the response time differs so much? 为什么响应时间差异如此之大?

How big is your graph? 您的图表有多大? Could be that it allocates a lot of heap for caching and then there is not enough space for running the queries without garbage collection. 可能是因为它为缓存分配了很多堆,然后没有足够的空间来运行没有垃圾回收的查询。

I presume your relationships are all 1:n, if not add a WITH distinct p,w,a in between the two matches. 我假设您的关系都是1:n,如果没有,则在两个匹配项之间添加一个WITH distinct p,w,a

Your query is also suboptimal, and will probably create a lot of intermediate results, you can use PROFILE to look at the query plan. 您的查询也不理想,可能会产生很多中间结果,您可以使用PROFILE查看查询计划。

Try this: 尝试这个:

PROFILE
MATCH (a:Author)
WHERE (a.author_name =~ '.*Camus.*' and a.author_name =~ '.*Albert.*') 
MATCH (p:Publisher)-[:PUBLISHED]->(w:Woka)<-[:AUTHORED]-(a)
MATCH (l:Language)-[:USED]->(w:Woka) 
RETURN p.publisher_name, w.woka_title, a.author_name, l.language_name;

I borrowed from other solutions and I changed the params as following in the file conf/neo4j.properties (server restarted after that): 我借鉴了其他解决方案,并在文件conf / neo4j.properties中更改了参数,如下所示(此后服务器重新启动):

neostore.nodestore.db.mapped_memory=512M
neostore.relationshipstore.db.mapped_memory=512M
neostore.propertystore.db.mapped_memory=512M
neostore.propertystore.db.strings.mapped_memory=512M
neostore.propertystore.db.arrays.mapped_memory=512M

The results are now returning, in average, 300% faster narrowing the time from 90 seconds to 30 seconds and I am not getting disconnected anymore from the web interface to the database. 现在,结果平均返回的速度提高了300%,将时间从90秒缩小到30秒,而且我不再从Web界面到数据库断开连接了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM