I have a question about transaction performance and/or costs in following scenarios.
Environment: JBoss 7.1.1 / Oracle 11G / Java 6
Scenario A - 1 EJB:
I've created one EJB which saves a record to a database with CMP (Transaction REQUIRES_NEW):
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public void saveTerminal(TerminalSaveRequest request) {
TerminalEntity terminalEntity = new TerminalEntity();
terminalEntity.setId(request.getId());
...
entityManager.persist(terminalEntity);
}
This EJB is called by an external EJB Client (without any JTA trx) and performes well (1000 inserts / sec). JBoss also documents the exact amount of transactions in the JPA measurement.
Scenario B - 2 EJBS:
I've changed the application and added a further EJB calling the EJB from scenario A, though here I would like to have a "shared" transaction opened by the new EJB. So I've changed the existing EJB as followed (Transaction REQUIRED):
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void saveTerminal(TerminalSaveRequest request) {
TerminalEntity terminalEntity = new TerminalEntity();
terminalEntity.setId(request.getId());
...
entityManager.persist(terminalEntity);
}
In the new EJB I start then the newly required transaction and calling the (local) EJB:
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public void saveTerminal(TerminalSaveRequest request) {
terminal.saveTerminal(request);
}
Now, again everything works as expected (same amount of transactions etc), though the performance has dropped dramatically from 1000 to 200 inserts a second which bothers a lot as the transaction handling between these two EJBs seems to cost like 4 times the insert :(
Further informations:
- No other EJBs or methods are using this transaction.
- Local interfaces
- Local DS
Questions:
- Is it really THAT expensive to have a transaction opened in one EJB and used in another? (As there is still one transaction and one insert as in the first example).
- If one has one "Dispatcher" calling multiple other EJBs in one transaction will the cost of transaction handling be once per transaction or once per EJB call?!
If more informations are needed I'll happily post more.
Thanks for any hints or thoughts about this topic.
Bernhard
@RunAs
)? Can you run a profiler against both versions to see where the time is going? – Elutriate