与mysql相比neo4j性能(如何提高?)

Posted

技术标签:

【中文标题】与mysql相比neo4j性能(如何提高?)【英文标题】:neo4j performance compared to mysql (how can it be improved?) 【发布时间】:2013-07-23 05:45:06 【问题描述】:

这是对can't reproduce/verify the performance claims in graph databases and neo4j in action books 的跟进。我已经更新了设置和测试,不想过多改变原来的问题。

整个故事(包括脚本等)在https://baach.de/Members/jhb/neo4j-performance-compared-to-mysql

简短版:在尝试验证“图形数据库”一书中的性能声明时,我得到了以下结果(查询包含 n 个人的随机数据集,每个人有 50 个朋友):

My results for 100k people

depth    neo4j             mysql       python

1        0.010             0.000        0.000
2        0.018             0.001        0.000
3        0.538             0.072        0.009
4       22.544             3.600        0.330
5     1269.942           180.143        0.758

“*”:仅单次运行

My results for 1 million people

depth    neo4j             mysql       python

1        0.010             0.000        0.000
2        0.018             0.002        0.000
3        0.689             0.082        0.012
4       30.057             5.598        1.079
5     1441.397*          300.000        9.791

“*”:仅单次运行

在 64 位 ubuntu 上使用 1.9.2 我设置了具有以下值的 neo4j.properties:

neostore.nodestore.db.mapped_memory=250M
neostore.relationshipstore.db.mapped_memory=2048M

和 neo4j-wrapper.conf 与:

wrapper.java.initmemory=1024
wrapper.java.maxmemory=8192

我对 neo4j 的查询如下所示(使用 REST api):

start person=node:node_auto_index(noscenda_name="person123") match (person)-[:friend]->()-[:friend]->(friend) return count(distinct friend);

Node_auto_index 很明显

我能做些什么来加快 neo4j 的速度(比 mysql 更快)吗?

还有another benchmark in ***也有同样的问题。

【问题讨论】:

【参考方案1】:

是的,我认为 REST API 比常规绑定慢得多,这就是您的性能问题。

【讨论】:

好点。是的,我想你会得到不同的结果运行嵌入式和独立(使用过程/插件)。【参考方案2】:

很抱歉,您无法重现结果。但是,在 MacBook Air(1.8 GHz i7,4 GB RAM)上,具有 2 GB 堆、GCR 缓存,但没有缓存预热,也没有其他调整,具有类似大小的数据集(100 万用户,每人 50 个朋友) ,我在 1.9.2 上使用 Traversal Framework 反复得到大约 900 毫秒:

public class FriendOfAFriendDepth4

    private static final TraversalDescription traversalDescription = 
         Traversal.description()
            .depthFirst()
            .uniqueness( Uniqueness.NODE_GLOBAL )
            .relationships( withName( "FRIEND" ), Direction.OUTGOING )
            .evaluator( new Evaluator()
            
                @Override
                public Evaluation evaluate( Path path )
                
                    if ( path.length() >= 4 )
                    
                        return Evaluation.INCLUDE_AND_PRUNE;
                    
                    return Evaluation.EXCLUDE_AND_CONTINUE;

                
             );

    private final Index<Node> userIndex;

    public FriendOfAFriendDepth4( GraphDatabaseService db )
    
        this.userIndex = db.index().forNodes( "user" );
    

    public Iterator<Path> getFriends( String name )
    
        return traversalDescription.traverse( 
            userIndex.get( "name", name ).getSingle() )
                .iterator();
    

    public int countFriends( String name )
    
        return  count( traversalDescription.traverse( 
            userIndex.get( "name", name ).getSingle() )
                 .nodes().iterator() );
    

Cypher 速度较慢,但​​远没有您建议的那么慢:大约 3 秒:

START person=node:user(name=name)
MATCH (person)-[:FRIEND]->()-[:FRIEND]->()-[:FRIEND]->()-[:FRIEND]->(friend)
RETURN count(friend)

亲切的问候

伊恩

【讨论】:

抱歉,neo4j 中的场景是'返回朋友的所有朋友...',没有找到给定朋友之间的路径。我指的是 Neo4j in Action 的第 1 章。 sql 语句是关于查找所有朋友的,表中的结果(返回的记录)也是如此。更重要的是:我绝对无法重现 3 秒。查询例如start person=node(100) match (person)-[:friend]-&gt;()-[:friend]-&gt;()-[:friend]-&gt;()-[:friend]-&gt;(friend) return count(friend); 需要 28.9 秒。很奇怪…… 是的:在 1m 数据集上,在 mysql 上查找给定 A 和 B 之间的路径大约需要 2390 毫秒,而在 Neo4j 上只需大约 25 毫秒。 又名 neo4j 在查询关系(路径)而不是节点方面展示了它的强大功能,对吧?

以上是关于与mysql相比neo4j性能(如何提高?)的主要内容,如果未能解决你的问题,请参考以下文章

与同步类相比,使用非同步类的性能如何提高? [复制]

Datomic 与 Neo4j 相比如何?

在进行大量写入时提高 neo4j 性能

如何提高此 CopyTo 方法的性能?

与 SSE2 相比,为啥 AVX 没有进一步提高性能?

与 Oracle 相比,提高 postgreql 插入性能。 Postgresql 线程的内存利用率低