Spring Neo4j:通过不同的控制台执行相同的密码查询会花费不同的时间 [英] Spring Neo4j: Same cypher query taking different time when executed through different consoles

查看:86
本文介绍了Spring Neo4j:通过不同的控制台执行相同的密码查询会花费不同的时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过不同的控制台执行相同的密码查询会花费不同的时间:

Same cypher query taking different time when executed through different consoles:

通过 spring-data-neo4j执行:(耗时8秒)

@Query(
"MATCH (user:User {uid:{0}})-[:FRIEND]-(friend:User)" +
"RETURN friend"
)
public List<User> getFriends(String userId);

通过 http://localhost:7474/browser/执行:(花费250毫秒)

Executed via http://localhost:7474/browser/ : (took 250 ms)

通过 http://localhost:7474/webadmin/#/console/执行:(耗时18毫秒)

Executed via http://localhost:7474/webadmin/#/console/ : (took 18 ms)

即使通过控制台执行的查询非常快并且花费的时间在可接受的范围内,但是对于生产而言,我必须从我的Java应用程序中执行那些查询,在这种情况下,查询所花费的时间是完全不可接受的.

Even though queries executed via console are very fast and taking time under acceptable range but for production I have to execute those queries from my java app and in which case the time taken by queries are totally unacceptable.

@NodeEntity
public class User extends AbstractEntity {

    @RelatedToVia(elementClass = Friendship.class, type = FRIEND, direction = BOTH)
    private Set<Friendship>     friendships;

    ...
}

推荐答案

在进行基准测试时,请确保您至少运行了3次测试并计划删除第一个测试.我发现对于任何给定的查询,需要一两次运行来预热Neo4j的缓存.这与大多数RDBMS的缓存方式不同.

Make sure when benchmarking that you run tests at least 3 times and plan to drop the first one. I find that it takes one or two runs to warm the cache for Neo4j for any given query. This is different than most RDBMS which don't cache the same way.

我的做法是运行5次测试查询,并删除第2个.无论数据集的大小如何(我使用成千上万个节点进行测试),以及测试的复杂性,这对我来说都是一致的脚本(我有一些Cypher语句运行超过50条左右的行,多个WITH,等等).我发现,在前两次运行之后,同一查询从一次运行到下一次的性能往往保持在相同的值附近.

My practice is to run test queries 5 times and drop the first 2. This works pretty consistently for me regardless of the size of data set (I test with tens of thousands and hundreds of thousands of nodes) and the complexity of the script (I have some Cypher statements that run more than 50 or so lines, multiple WITHs, etc). What I've found is that after the first two runs, the performance from one run to the next of the same query tends to stay right around the same value..

因此,请确保在生产中已为常见查询预热了缓存.并确保您有足够的内存可用于JVM和Neo4j.如果Neo4j可以访问足够的内存,则大多数数据集都小于几个GB,因此可以容纳在内存中.

So make sure that in production you've warmed your cache for your common queries. And make sure that you've got sufficient memory available to the JVM and Neo4j. Most data sets are smaller than a few GB and so can fit in memory, if Neo4j has access to enough memory.

最后,请确保您已建立索引(例如CREATE INDEX ON:User(uid)).将大多数图形及其属性加载到内存中,并在正确的索引位置,Neo4j应该真正执行.

Finally, be sure you have your indexes in place (e.g. CREATE INDEX ON :User(uid)). With most of the graph and its properties loaded in memory, and the right indexes in place, Neo4j should really perform.

这篇关于Spring Neo4j:通过不同的控制台执行相同的密码查询会花费不同的时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆