Possible optimization:TransactionScope 2 - 2.5 tx/sec gain
Posted: Wed 20 Feb 2013 06:57
I'm not yet sure if it's a bug (now working code), or you have missed optimization opportunity (no such code at all).
Currently your driver when enlisting in TransactionScope always do two phase commit, even when it is the only participant of transaction, PREPARE TRANSACTION; COMMIT PREPARED is executed on successful transaction end.
I did some benchmarks, and using TransactionScope is 2-2.5 times slower then using Connection.BeginTransaction() due to always doing 2PC with PREPARE TRANSACTION.
I guess your are always enlisting with Transaction.EnlistVolatile(IEnlistmentNotification) which will always call prepare then commit, when you could do Transaction.EnlistVolatile(ISinglePhaseNotification) or EnlistPromotableSinglePhase
Currently your driver when enlisting in TransactionScope always do two phase commit, even when it is the only participant of transaction, PREPARE TRANSACTION; COMMIT PREPARED is executed on successful transaction end.
I did some benchmarks, and using TransactionScope is 2-2.5 times slower then using Connection.BeginTransaction() due to always doing 2PC with PREPARE TRANSACTION.
I guess your are always enlisting with Transaction.EnlistVolatile(IEnlistmentNotification) which will always call prepare then commit, when you could do Transaction.EnlistVolatile(ISinglePhaseNotification) or EnlistPromotableSinglePhase
Code: Select all
[TestMethod]
public void TX()
{
using (TransactionScope ts = new TransactionScope())
{
PgSqlConnection connection = new PgSqlConnection("...;Enlist=true;Unicode=true");
connection.Open();
ts.Complete();
}
}