Transaction execution time should be minimal. The reason is obvious: a transaction occupies expensive resources. As long as the transaction executes, no other transaction can access those resources. Every resource manager the transaction accesses has to lock relevant data, isolating that transaction from the rest of the world. As long as the locks are held, nobody else can access the data. The more transactions per second your application can process, the better its scalability and throughput.
Transaction execution usually requires, at most, a few seconds. For lengthy operations, consider using a short transaction backed up by a compensating transaction.
COM+ allows you to configure a maximum execution time for your transactions. If your transaction reaches that timeout, COM+ aborts it automatically. Transaction timeouts prevent resource manager deadlocks from hanging the system. Eventually, one of the two transactions deadlocking each other would reach the timeout and abort, allowing the other transaction to proceed.
You can configure two kinds of transaction timeouts. The first is a
machine-wide parameter called the global transaction
timeout
. The global timeout applies to all
transactions on that machine. You configure the global timeout by
right-clicking on the My Computer icon in the Component Services
Explorer, selecting Properties from the context menu, and selecting
the Options tab (see Figure 4-13). The default
timeout is set to 60 seconds, but you can set it to any value you
like, up to 999 seconds. A global timeout set to zero means an
infinite timeout. Transactions on that machine never time out.
Infinite
timeout is useful mostly for debugging, when you want to try to
isolate a problem in your business logic by stepping through your
code and you do not want the transaction you debug to time out while
you figure out the problem. Be extremely careful with infinite
timeout in all other cases because it means there are no safeguards
against transaction deadlocks.
You can also configure transaction timeout at the component level, on its Transactions tab. Component-level transaction timeout is disabled by default, and you have to explicitly enable it. Component-level transaction timeout means that any transaction this component is part of must end within the time specified, or else COM+ aborts it. Obviously, the component-level timeout is effective only if it is less than the global timeout. The default component-level timeout is set by COM+ to zero, which indicates infinity. You can use component-level timeout in two cases. The first case is during development, when you want to test the way your application handles aborted transactions. By setting the component-level timeout to a small value (such as one second), you cause your transaction to fail and can thus observe your error handling code. The second case in which you set the component-level transaction timeout to be less than the global timeout is when you believe that the component is involved in more than its fair share of resource contention, resulting in deadlocks. In that case, you should abort the transaction as soon as possible and not wait for the global timeout to expire.