【发布时间】: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
【问题讨论】: