0

我尝试了一个关于 SNS 的实验,并且我使用了 cypher 和 traversal API 来查询。目前,每个查询大约需要 40 毫秒。但是当我使用多线程查询时,性能急剧下降,每次查询花费近 200 毫秒。大约有100万个节点和2亿个关系,我使用gcr cache_type。如果需要,请参阅我的实验以获取详细信息。

我使用visualVM查找多线程的热点,我发现NodeManager.lockId花费了很多时间(实际上是lock)。NodeManager.lockId 源如下:

private ReentrantLock lockId( int id )
{
    int stripe = (id / 32768) % LOCK_STRIPE_COUNT;
    if ( stripe < 0 )
    {
        stripe *= -1;
    }
    ReentrantLock lock = loadLocks[stripe];
    lock.lock();
    return lock;
}

public Node getNodeById( int nodeId ) throws NotFoundException
{
    NodeImpl node = nodeCache.get( nodeId );
    if ( node != null )
    {
        return new NodeProxy( nodeId, this );
    }
    ReentrantLock loadLock = lockId( nodeId );
    try
    {
        if ( nodeCache.get( nodeId ) != null )
        {
            return new NodeProxy( nodeId, this );
        }
        if ( !persistenceManager.loadLightNode( nodeId ) )
        {
            throw new NotFoundException( "Node[" + nodeId + "]" );
        }
        node = new NodeImpl( nodeId );
        nodeCache.put( nodeId, node );
        return new NodeProxy( nodeId, this );
    }
    finally
    {
        loadLock.unlock();
    }
}

如果没有缓存节点,似乎在获取节点时会出现锁。所以我想知道GCR缓存类型的机制,因为如果我将node_cache_size和relationship_cache_size设置为默认值,它会比我设置的更快:

config.put( "node_cache_size", "1G");
config.put( "relastionship_cache_size", "8G");

请告诉我有关 GCR 缓存类型的详细信息,以及如何配置缓存类型和预热。我想在使用多线程时提高性能。谢谢

4

1 回答 1

0

GCR cache is documented at bottom of http://docs.neo4j.org/chunked/stable/configuration-caches.html#_object_cache. For more on GCR implementation details look at the code at https://github.com/neo4j/neo4j/tree/master/enterprise/ha/src/main/java/org/neo4j/kernel/impl/cache and the tests at https://github.com/neo4j/neo4j/tree/master/enterprise/ha/src/test/java/org/neo4j/kernel/impl/cache

For warming up, iterate over all nodes and relationships using GlobalGraphOperations.getAllNodes() and GlobalGraphOperations.getAllRelationships().

于 2013-09-25T09:09:44.150 回答