Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Performance costs of having a transaction over multiple EJBs vs. one EJB

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

like image 541
Big Bad Baerni Avatar asked May 30 '13 08:05

Big Bad Baerni


1 Answers

Have you tried having both EJB's use @TransactionAttribute(TransactionAttributeType.REQUIRED) and letting JBoss decide where to demarcate the transaction instead?

like image 96
Brad Avatar answered Oct 21 '22 13:10

Brad