maximizing com+ application throughput steve swartz program manager com+ team microsoft corporation...
TRANSCRIPT
Maximizing COM+ Maximizing COM+ Application Throughput Application Throughput
Steve SwartzSteve SwartzProgram ManagerProgram ManagerCOM+ TeamCOM+ TeamMicrosoft CorporationMicrosoft Corporation
1-4021-402
OverviewOverview
Throughput: What and HowThroughput: What and How COM+ ThreadingCOM+ Threading COM+ Process PoolingCOM+ Process Pooling COM+ SynchronizationCOM+ Synchronization COM+ ActivationCOM+ Activation
DemoDemo
ThroughputThroughput
Throughput definedThroughput defined Throughput and infrastructureThroughput and infrastructure Throughput and scalabilityThroughput and scalability Throughput and performanceThroughput and performance Performance vs. scalabilityPerformance vs. scalability
Throughput and ResourcesThroughput and Resources
Maximizing throughput means Maximizing throughput means using resources efficientlyusing resources efficiently
Minimize create/destroy costsMinimize create/destroy costs Acquire late/release early Acquire late/release early Avoid creating too many resourcesAvoid creating too many resources Avoid waiting for resource Avoid waiting for resource Avoid requiring particular Avoid requiring particular
resourcesresources Avoid holding unused resourcesAvoid holding unused resources
Throughput and COM+Throughput and COM+
COM+ services relevant to COM+ services relevant to throughput:throughput:
Thread models & poolsThread models & pools Synchronization domainsSynchronization domains Process poolsProcess pools JIT and Object PoolsJIT and Object Pools
Costs to keep in mindCosts to keep in mind
XProcess vs. XThread callsXProcess vs. XThread calls Regular vs. context marshallingRegular vs. context marshalling Activations and callsActivations and calls Cross-machine hops vs. Cross-machine hops vs.
localizationlocalization
OverviewOverview
Throughput: What and HowThroughput: What and How COM+ ThreadingCOM+ Threading COM+ Process PoolingCOM+ Process Pooling COM+ SynchronizationCOM+ Synchronization COM+ ActivationCOM+ Activation
COM+ Threading ModelsCOM+ Threading Models
Apartments vs. threads Apartments vs. threads Single threaded apartmentsSingle threaded apartments
Concurrency & reentrancyConcurrency & reentrancy Thread-local storageThread-local storage STAs are a bottleneckSTAs are a bottleneck
The multi-threaded apartmentThe multi-threaded apartment The neutral apartmentThe neutral apartment
COM ThreadsCOM Threads
RPC Thread Pool
(MTA)
Main STA
MTA Pool
Process
COM+ ThreadsCOM+ Threads
RPC Thread Pool
(MTA)
Main STA
MTA Pool
STA Pool
Process
STA Pool vs. MTA PoolSTA Pool vs. MTA Pool
STA pooled objectsSTA pooled objects Contend for a specific threadContend for a specific thread Cannot take advantage of new threadsCannot take advantage of new threads
MTA pooled objectsMTA pooled objects Contend for all threadsContend for all threads Can take advantage of new threadsCan take advantage of new threads
Example: STA PoolExample: STA Pool
What you have to change to use the What you have to change to use the STA Thread Pool:STA Thread Pool:
Server App HintsServer App Hints
Server App==OutOfProc COM+ AppServer App==OutOfProc COM+ App Stick to one thread modelStick to one thread model Concentrate on parent objectsConcentrate on parent objects Avoid shared child objectsAvoid shared child objects Neutral apartment for infrastructure Neutral apartment for infrastructure
objectsobjects
Library App HintsLibrary App Hints
Library App==InProc COM+ AppLibrary App==InProc COM+ App Behavior of caller mattersBehavior of caller matters
Are your object references shared?Are your object references shared? Are you called from different kinds of Are you called from different kinds of
apartments?apartments? Specify known caller’s threading Specify known caller’s threading
modelmodel ““Both” for single user/unknown Both” for single user/unknown
caller caller ““Neutral” for many userNeutral” for many user
OverviewOverview
Throughput: What and HowThroughput: What and How COM+ ThreadingCOM+ Threading COM+ Process PoolingCOM+ Process Pooling COM+ SynchronizationCOM+ Synchronization COM+ ActivationCOM+ Activation
Process Pooling???Process Pooling???
Process pools can help throughput Process pools can help throughput when you’ve got:when you’ve got: Single-threaded applicationsSingle-threaded applications Applications that serialize the Applications that serialize the
processing of requestsprocessing of requests Apps prone to server sized Apps prone to server sized
slowdowns or bottlenecksslowdowns or bottlenecks
Example: Process PoolingExample: Process Pooling
What you have to change to use What you have to change to use Process Pools:Process Pools:
OverviewOverview
Throughput: What and HowThroughput: What and How COM+ ThreadingCOM+ Threading COM+ Process PoolingCOM+ Process Pooling COM+ SynchronizationCOM+ Synchronization COM+ ActivationCOM+ Activation
STA SynchronizationSTA Synchronization
Prevents concurrent accessPrevents concurrent access Allows reentrancy (to avoid Allows reentrancy (to avoid
deadlocks)deadlocks) Allows multiple copies (in different Allows multiple copies (in different
apartments)apartments) A Throughput BottleneckA Throughput Bottleneck
COM+ ActivitiesCOM+ Activities
Synchronization domainsSynchronization domains Four levels of configurationFour levels of configuration
Requires NewRequires New RequiresRequires SupportsSupports Not supportedNot supported
Cross-apartment, not out-of-procCross-apartment, not out-of-proc
COM+ SynchronizationCOM+ Synchronization
Prevents concurrent accessPrevents concurrent access Allows reentrancy Allows reentrancy Allows multiple copiesAllows multiple copies Can be used in MTACan be used in MTA Less of a throughput bottleneckLess of a throughput bottleneck
Example: SynchronizationExample: Synchronization
What you have to change to use What you have to change to use COM+ synchronizationCOM+ synchronization
OverviewOverview
Throughput: What and HowThroughput: What and How COM+ ThreadingCOM+ Threading COM+ Process PoolingCOM+ Process Pooling COM+ SynchronizationCOM+ Synchronization COM+ ActivationCOM+ Activation
Programming ModelsProgramming Models
COM+: Fewer longer-lived clientsCOM+: Fewer longer-lived clients IIS: Many transient clientsIIS: Many transient clients Focus on COM+ model, BUT…Focus on COM+ model, BUT… … … IIS is COM+’s longer-lived clientIIS is COM+’s longer-lived client
Optimizing COM+ ActivationOptimizing COM+ Activation
JITJIT Object PoolingObject Pooling Recent TPC-C benchmarksRecent TPC-C benchmarks
JITJIT
On Activation, Proxy/Stub createdOn Activation, Proxy/Stub created Object created at first useObject created at first use Object controls its own lifetimeObject controls its own lifetime JIT enables scalable programming JIT enables scalable programming
modelmodel JIT is not useful by itselfJIT is not useful by itself
Object PoolingObject Pooling
Pool of stateful instantiationsPool of stateful instantiations Request/wait architectureRequest/wait architecture When should I pool objectsWhen should I pool objects
When create costs are relatively highWhen create costs are relatively high When use costs are relatively lowWhen use costs are relatively low When an object will be reused oftenWhen an object will be reused often Experiment!Experiment!
Don’t pool objects with client-Don’t pool objects with client-specific statespecific state
Object & Connection PoolsObject & Connection Pools
Object Pools are 2x fasterObject Pools are 2x faster Object Pools are asynchronousObject Pools are asynchronous Object Pools handle min/max wellObject Pools handle min/max well Object Pools handle more Object Pools handle more
resourcesresources Object Pools handle more resource Object Pools handle more resource
typestypes
JIT and Object PoolingJIT and Object Pooling
JIT caches COM infrastructureJIT caches COM infrastructure Object pool caches state, objectsObject pool caches state, objects Together, theyTogether, they
Minimize overhead of starting workMinimize overhead of starting work Minimize size of resource cachesMinimize size of resource caches Maximize throughputMaximize throughput
Example: Example: JIT and Object Pooling JIT and Object Pooling
What you have to change to use JIT What you have to change to use JIT and Object Pooling:and Object Pooling: Client does not call Release()Client does not call Release() Server must call SetComplete()Server must call SetComplete() Server must implement IObjectControlServer must implement IObjectControl Server must be thread-neutralServer must be thread-neutral Server must enlist itselfServer must enlist itself
Example: Example: JIT and Object Pooling JIT and Object Pooling
QueuedPoolof
MTAThreads
JITtedObjects
inObjectPool
ISAPISQL
Server