Events
May 19, 6 PM - May 23, 12 AM
Calling all developers, creators, and AI innovators to join us in Seattle @Microsoft Build May 19-22.
Register todayThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Object pooling can be extremely effective in certain circumstances, yielding substantial increases in performance. The general idea for reusing objects to best advantage is to pool as many resources as possible, factoring out initialization from actual work performed, and then to administratively tailor the pool characteristics to actual hardware at deployment time. That is, you should proceed according to the following steps:
If you have a component that clients will use briefly and in rapid succession, where a significant portion of object use time is spent in acquiring resources or initializing prior to doing specific work for the client, chances are that writing your component to use object pooling will be a big win for you.
You can write the component so that in the object's constructor you perform as much of the time-consuming work that is uniform for all clients as possible—acquiring one or several connections, running scripts, fetching initialization data from files or across a network, and so forth. This has the effect of pooling every such resource. You are pooling the combination of resources and generic state necessary to perform some work.
In this circumstance, when clients get an object from the pool, they have those resources immediately available. Typically, they will use the object to do some small unit of work, pushing or pulling data, and then the object will call IObjectContext::SetComplete or IObjectContext::SetAbort and return. With rapid-fire use patterns such as this, pooling yields excellent performance benefits. You can fully leverage the simplicity of the stateless automatic transaction programming model yet achieve performance on par with traditional stateful components.
However, if clients use an object for a long time each time they call it, pooling will make less sense. The speed advantage that you gain is marginal as use time increases relative to initialization time. You get diminishing returns that may not justify the cost of the memory necessary to hold a pool of active objects.
A variation on factoring out initialization is that you can use pooling to statistically amortize the cost of acquiring expensive resources. If you take the hit of acquisition or initialization once and then reuse the object, you share that cost across all clients that use the object during its lifetime. Heavy construction time is incurred only once per object.
If you specify a nonzero minimum pool size, that minimum number of objects will be created and pooled when the application starts, ready for any clients that call in to the application.
You can use the maximum pool size to govern very precisely how you use resources. For example, if you have licensed a certain number of database connections, you can control how many connections you have open at any time.
When you take into consideration client use patterns, object use characteristics, and physical resources such as memory and connections, you are likely to find some optimal balance point when you do performance tuning. Pooling objects will yield diminishing returns after a certain point. You can determine what level of performance you require and balance that against what resources are necessary to achieve it.
To facilitate performance tuning when you configure object pooling, you can monitor object statistics for the components in an application. For details, see Monitoring Object Statistics.
Object pooling works very well with the COM+ just-in-time activation service. By pooling objects that are being JIT-activated, you can speed object reactivation. You get the benefits of holding the channel open by JIT activation while mitigating the cost of reactivation. You can use pooling in this case to govern how much memory you wish to allocate to objects that have references active.
You are most likely to be pooling JIT-activated components when they are transactional. Object pooling is optimized to handle transactional components. For more information, see Pooling Transactional Objects.
Events
May 19, 6 PM - May 23, 12 AM
Calling all developers, creators, and AI innovators to join us in Seattle @Microsoft Build May 19-22.
Register todayTraining
Module
Apply Basic Performance Optimization in finance and operations apps - Training
By optimizing your development for performance, you can ensure that your work is useful and appreciated by users. As a finance and operations apps developer, you should understand how your designs can be properly optimized for performance.