Search code examples
performanceentity-frameworkdb2transactionscopemstdc

Performance transaction scope against DB2 table


We are trying to track down the cause of a performance problem.

We have a table with a single row that contains a primary key and a counter. Within a transaction we read the value of the counter, increment the value by one and save the new value.

The read and update is done using Entity Framework, we use a serializable transaction scope, we need to ensure that a counter value is read once only.

Most of the time this takes 0.1 seconds, then sometimes it takes over 1 second. We have not been able to find any pattern as to why this happen.

Has anyone else experienced variable performance when using transaction scope? Would it help to drop using transaction scope and set the transaction directly on the connection?


Solution

  • We have now solved this problem.

    The root of the problem was that the DB2 provider does not support transaction promotion. This results in Transaction Scope using MSDTC distributed transactions for everything.

    We replaced the use of Transaction Scope with transactions set on the database connection.

    Composite services that included the code in the question were then reduced from 3 seconds to 0.3 seconds.