Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Neo4j 事务性能和如何减轻事务管理器的负担?_Neo4j_Spring Data Neo4j - Fatal编程技术网

Neo4j 事务性能和如何减轻事务管理器的负担?

Neo4j 事务性能和如何减轻事务管理器的负担?,neo4j,spring-data-neo4j,Neo4j,Spring Data Neo4j,我正在使用SDN 2.1.0-RC4进行身份、访问和角色管理,而不使用AspectJ。 该系统旨在管理约12万用户,数据从遗留和人力资源应用程序中提取。 我每天有500到30000次更新,所以性能可能是一个敏感的话题 我用默认配置运行了一些工作台 我用了一种非常简单和愚蠢的方式。 简单的课堂 @TypeAlias("event") @NodeEntity public class Event { @GraphId private Long graphId; @Inde

我正在使用SDN 2.1.0-RC4进行身份、访问和角色管理,而不使用AspectJ。 该系统旨在管理约12万用户,数据从遗留和人力资源应用程序中提取。 我每天有500到30000次更新,所以性能可能是一个敏感的话题 我用默认配置运行了一些工作台

我用了一种非常简单和愚蠢的方式。 简单的课堂

@TypeAlias("event")
@NodeEntity
public class Event {

    @GraphId
    private Long graphId;

    @Indexed
    private Long eventId;

    @RelatedTo(type="PREVIOUS_EVENT", direction=Direction.OUTGOING)
    private Event previous;

    private String description;

        /.../
}
我一个接一个地插入数据

    /.../
/**
 * 
 */
public void loadAllData() {

    Event root = new Event();
    root.setEventId(0L);
    root.setDescription("ROOT");

    repository.save(root);
    Event curr = root;


    for(int i = 0; i< SIZE; i ++) {
        curr = insertData(curr, i );
    }
}


/**
 * @param curr
 * @param i
 * @return
 */
public Event insertData(Event curr, int i) {
    long lastTime = System.currentTimeMillis();
    Event evt = new Event();
    evt.setEventId(curr.getEventId()+1);
    evt.setPrevious(curr);
    evt.setDescription("event #"+i);
    repository.save(evt);
    curr = evt;
    delais[i] = System.currentTimeMillis() - lastTime;
    return curr;

}
/.../
2) neo4j事务的使用

@Override
public void loadAllData() {
    gds = getContext().getBean(GraphDatabaseService.class);
    super.loadAllData();
}       

@Override
public Event insertData(Event curr, int i) {                
    Transaction tx = gds.beginTx();
    try {
        curr = super.insertData(curr, i);
        tx.success();
    } catch(Exception e) {
        tx.failure();
    } finally {
        tx.finish();
    }
    return curr;

}
我知道基准测试是一个拖拉的主题,它不是我想要的。所以,把这些价值观当作是:一个愚蠢的测试

结果

JtaTransactionManager

平均47,20毫秒,最小21,00毫秒,最大425,00毫秒

GraphDatabaseService

平均0,90毫秒,最小0,00毫秒,最大3,00毫秒

与本机neo4j服务器相比,JtaTransactionManager速度非常慢,但JtaTransactionManager是一个全局的、雄心勃勃的TransactionManager

我的目的是如何减轻或创建一个自定义transactionManager的负担,减少野心,缩小范围,但仍然使用@Transactional注释

也许我错过了什么

感谢您提供的任何潜在帮助或建议

PS:我的配置

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:neo4j="http://www.springframework.org/schema/data/neo4j"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
        http://www.springframework.org/schema/data/neo4j http://www.springframework.org/schema/data/neo4j/spring-neo4j-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">

    <context:annotation-config/>
    <context:spring-configured/>

    <context:component-scan base-package="benchmark"/>

    <neo4j:repositories base-package="benchmark.repository"/>
    <neo4j:config graphDatabaseService="graphDatabaseService"/>


    <bean id="graphDatabaseService" class="org.neo4j.kernel.EmbeddedGraphDatabase" 
      destroy-method="shutdown">
         <constructor-arg index="0" value="data/benchmark.db" />
    </bean>


</beans>


Marc DeXeT

您使用两种完全不同的事务批量大小

使用“neo4j”TM,您可以使用一个全局tx范围,一次完成所有更新(也就是数百或数千次操作)

使用
@Transactional
可以获得单个操作的发送范围。因此,事务的开销只为每个操作添加一次

因此,试着在
loadAllData()
周围加上@Transactional


此外,为了提高插入速度,请尝试使用
template.createRelationshipBetween(....,duplicate=true)
而不是
evt.setPrevious(curr)
。因此,您可以跳过所有增量检测和重复消除

谢谢@Transactionnal是一种级联功能,不是吗?我认为深层方法调用事务是由第一级方法事务包装的。所以“public void run(){upper()//…commit is done}@Transactional public void upper(){lower();//…commit is not done}@Transactional public void lower(){//…do something..////尚未提交}
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:neo4j="http://www.springframework.org/schema/data/neo4j"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
        http://www.springframework.org/schema/data/neo4j http://www.springframework.org/schema/data/neo4j/spring-neo4j-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">

    <context:annotation-config/>
    <context:spring-configured/>

    <context:component-scan base-package="benchmark"/>

    <neo4j:repositories base-package="benchmark.repository"/>
    <neo4j:config graphDatabaseService="graphDatabaseService"/>


    <bean id="graphDatabaseService" class="org.neo4j.kernel.EmbeddedGraphDatabase" 
      destroy-method="shutdown">
         <constructor-arg index="0" value="data/benchmark.db" />
    </bean>


</beans>