0

Is there any performance penalty to define all methods as transactional using Spring AOP based declarative transaction management? See the config below. The reason is that I do not know what method name developers will give for non transactional methods. One option is I start with a wild card list and developers update the list if the method name does not fall under the defined list.

<tx:advice id="txAdvice" transaction-manager="transactionManager">
    <tx:attributes>
        <tx:method name="*" />
    </tx:attributes>
</tx:advice>

<aop:config>
    <aop:pointcut id="dtxops" expression="bean(*Service)" />
    <aop:advisor advice-ref="txAdvice" pointcut-ref="dtxops" />
</aop:config>
Sharad Yadav
  • 2,951
  • 5
  • 20
  • 18

2 Answers2

1

It depends on what underlying transaction manager you are using. The default spring "transaction per thread, no XA transactions" probably doesn't have a any penalty. If you are using JBoss with the XA transaction manager, then it will write some data to a transaction log .

-- original -- Even then, I think you'd find the performance penalty to be fairly small.

-- edited -- In my experience, I haven't seen a huge increase in performance when converting to Readonly using the JBoss transaction manager. Per the comment below, at least one user saw a 30% performance increase which is significant.

Dave
  • 13,518
  • 7
  • 42
  • 51
  • I disagree, first off, adding extra reflective method calls and transaction openings for no reason is resource (and thus performance) wasteful. And further more, even if all that this would add is log entries (it does a lot more than that, but lets suppose), those can still bring down an app. I've seen 30% performance increase when excessive logging was removed. So I don't really think that in this scenario "the performance penalty is fairly small" – Shivan Dragon Oct 10 '11 at 15:32
  • My experience has been that changing to Readonly in JBoss was quite visible in the profiler, but compared to Database IO and CPU intensive logic, it was still small. So in my case I didn't see a 30% performance increase. – Dave Oct 10 '11 at 19:29
1

Theoretically there's a performance penality to adding AOP (and thus introspection/reflection) overhead to more methods than necessary. Also there's the added overhead of opening and closing more transactions than needed. It should be up to the developer coding the data-acces layer to know when and if a transaction should be started IMHO.

Shivan Dragon
  • 15,004
  • 9
  • 62
  • 103