【问题标题】:Transaction performance and how to lighten transaction manager?事务性能以及如何减轻事务管理器?
【发布时间】:2012-10-22 23:16:59
【问题描述】:

我正在使用没有 AspectJ 的 SDN 2.1.0-RC4 进行身份、访问和角色管理。 该系统旨在管理大约 120 000 名用户,并且数据是从遗留应用程序和 HR 应用程序中提取的。 我每天有 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;

}
/.../

我通过重载这些方法来测试几个

1) 使用@Transactional

@Override
@Transactional
public Event insertData(Event curr, int i) {
    return super.insertData(curr, i);
}

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 毫秒

图形数据库服务

平均 0.90 毫秒,最小 0.00 毫秒,最大 3.00 毫秒

JtaTransactionManager 与原生 neo4j 服务器相比非常慢,但 JtaTransactionManager 是一个全局且雄心勃勃的 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 spring-data-neo4j


    【解决方案1】:

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

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

    使用@Transactional,您拥有单个操作的 tx 范围。因此,事务的开销是为每个操作添加的,而不是只添加一次。

    所以尝试在loadAllData() 周围放置一个@Transactional。

    为了获得更高的插入速度,请尝试使用template.createRelationshipBetween(...., duplicate=true) 而不是evt.setPrevious(curr)。所以你跳过所有的增量检测和重复消除。

    【讨论】:

    • 谢谢。 @Transactionnal 是一个级联功能,不是吗?深度方法调用事务由我假设的第一级方法事务包装。所以 'public void run() { upper() //... 提交完成 } @ Transactional public void upper() { lower(); //... 提交没有完成 } @ Transactional public void lower() { //.. 做点什么 ..// // 它还没有提交 }
    猜你喜欢
    • 2016-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-02
    • 2021-10-17
    • 2016-10-06
    • 2016-05-17
    • 1970-01-01
    相关资源
    最近更新 更多