neo4j性能与mysql相比(如何改进?)

Joe*_*ach 40 python mysql performance neo4j

这是一个跟进,无法重现/验证图表数据库和neo4j在动作书中的性能声明.我已经更新了设置和测试,并且不想过多地更改原始问题.

整个故事(包括脚本等)在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
Run Code Online (Sandbox Code Playgroud)

"*":仅限单次运行

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
Run Code Online (Sandbox Code Playgroud)

"*":仅限单次运行

在64位ubuntu上使用1.9.2我已经使用这些值设置了neo4j.properties:

neostore.nodestore.db.mapped_memory=250M
neostore.relationshipstore.db.mapped_memory=2048M
Run Code Online (Sandbox Code Playgroud)

和neo4j-wrapper.conf:

wrapper.java.initmemory=1024
wrapper.java.maxmemory=8192
Run Code Online (Sandbox Code Playgroud)

我对neo4j的查询看起来像这样(使用REST api):

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

显然,Node_auto_index就位

有什么我可以做的来加速neo4j(比mysql更快)?

此外,Stackoverflow中还有另一个基准测试具有相同的问题.

Ian*_*son 4

很抱歉您无法重现结果。然而,在 MacBook Air(1.8 GHz i7,4 GB RAM)上,具有 2 GB 堆、GCR 缓存,但没有缓存预热,也没有其他调整,具有类似大小的数据集(100 万用户,每人 50 个朋友) ,我在 1.9.2 上使用遍历框架反复得到大约 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() );
    }
}
Run Code Online (Sandbox Code Playgroud)

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

START person=node:user(name={name})
MATCH (person)-[:FRIEND]->()-[:FRIEND]->()-[:FRIEND]->()-[:FRIEND]->(friend)
RETURN count(friend)
Run Code Online (Sandbox Code Playgroud)

亲切的问候

伊安

  • 是的:在 1m 数据集上,在 mysql 上查找给定 A 和 B 之间的路径大约需要 2390 毫秒,而在 neo4j 上只需要大约 25 毫秒。 (3认同)
  • 抱歉,neo4j 中的实际场景是“返回朋友的所有朋友...”,而不是找到给定朋友之间的路径。我指的是《Neo4j in Action》的第​​一章。sql语句是查找所有好友,表中的结果(返回的记录)也是如此。更重要的是:我绝对无法重现这 3 秒。查询例如 `start person=node(100) match (person)-[:friend]-&gt;()-[:friend]-&gt;()-[:friend]-&gt;()-[:friend]-&gt;( friend) return count(friend);` 需要 28.9 秒。很奇怪... (2认同)