34
Maximizing COM+ Maximizing COM+ Application Application Throughput Throughput Steve Swartz Steve Swartz Program Manager Program Manager COM+ Team COM+ Team Microsoft Corporation Microsoft Corporation 1-402 1-402

Maximizing COM+ Application Throughput Steve Swartz Program Manager COM+ Team Microsoft Corporation 1-402

Embed Size (px)

Citation preview

Page 1: Maximizing COM+ Application Throughput Steve Swartz Program Manager COM+ Team Microsoft Corporation 1-402

Maximizing COM+ Maximizing COM+ Application Throughput Application Throughput

Steve SwartzSteve SwartzProgram ManagerProgram ManagerCOM+ TeamCOM+ TeamMicrosoft CorporationMicrosoft Corporation

1-4021-402

Page 2: Maximizing COM+ Application Throughput Steve Swartz Program Manager COM+ Team Microsoft Corporation 1-402
Page 3: Maximizing COM+ Application Throughput Steve Swartz Program Manager COM+ Team Microsoft Corporation 1-402

OverviewOverview

Throughput: What and HowThroughput: What and How COM+ ThreadingCOM+ Threading COM+ Process PoolingCOM+ Process Pooling COM+ SynchronizationCOM+ Synchronization COM+ ActivationCOM+ Activation

Page 4: Maximizing COM+ Application Throughput Steve Swartz Program Manager COM+ Team Microsoft Corporation 1-402

DemoDemo

Page 5: Maximizing COM+ Application Throughput Steve Swartz Program Manager COM+ Team Microsoft Corporation 1-402

ThroughputThroughput

Throughput definedThroughput defined Throughput and infrastructureThroughput and infrastructure Throughput and scalabilityThroughput and scalability Throughput and performanceThroughput and performance Performance vs. scalabilityPerformance vs. scalability

Page 6: Maximizing COM+ Application Throughput Steve Swartz Program Manager COM+ Team Microsoft Corporation 1-402

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

Page 7: Maximizing COM+ Application Throughput Steve Swartz Program Manager COM+ Team Microsoft Corporation 1-402

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

Page 8: Maximizing COM+ Application Throughput Steve Swartz Program Manager COM+ Team Microsoft Corporation 1-402

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

Page 9: Maximizing COM+ Application Throughput Steve Swartz Program Manager COM+ Team Microsoft Corporation 1-402

OverviewOverview

Throughput: What and HowThroughput: What and How COM+ ThreadingCOM+ Threading COM+ Process PoolingCOM+ Process Pooling COM+ SynchronizationCOM+ Synchronization COM+ ActivationCOM+ Activation

Page 10: Maximizing COM+ Application Throughput Steve Swartz Program Manager COM+ Team Microsoft Corporation 1-402

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

Page 11: Maximizing COM+ Application Throughput Steve Swartz Program Manager COM+ Team Microsoft Corporation 1-402

COM ThreadsCOM Threads

RPC Thread Pool

(MTA)

Main STA

MTA Pool

Process

Page 12: Maximizing COM+ Application Throughput Steve Swartz Program Manager COM+ Team Microsoft Corporation 1-402

COM+ ThreadsCOM+ Threads

RPC Thread Pool

(MTA)

Main STA

MTA Pool

STA Pool

Process

Page 13: Maximizing COM+ Application Throughput Steve Swartz Program Manager COM+ Team Microsoft Corporation 1-402

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

Page 14: Maximizing COM+ Application Throughput Steve Swartz Program Manager COM+ Team Microsoft Corporation 1-402

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:

Page 15: Maximizing COM+ Application Throughput Steve Swartz Program Manager COM+ Team Microsoft Corporation 1-402

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

Page 16: Maximizing COM+ Application Throughput Steve Swartz Program Manager COM+ Team Microsoft Corporation 1-402

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

Page 17: Maximizing COM+ Application Throughput Steve Swartz Program Manager COM+ Team Microsoft Corporation 1-402

OverviewOverview

Throughput: What and HowThroughput: What and How COM+ ThreadingCOM+ Threading COM+ Process PoolingCOM+ Process Pooling COM+ SynchronizationCOM+ Synchronization COM+ ActivationCOM+ Activation

Page 18: Maximizing COM+ Application Throughput Steve Swartz Program Manager COM+ Team Microsoft Corporation 1-402

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

Page 19: Maximizing COM+ Application Throughput Steve Swartz Program Manager COM+ Team Microsoft Corporation 1-402

Example: Process PoolingExample: Process Pooling

What you have to change to use What you have to change to use Process Pools:Process Pools:

Page 20: Maximizing COM+ Application Throughput Steve Swartz Program Manager COM+ Team Microsoft Corporation 1-402

OverviewOverview

Throughput: What and HowThroughput: What and How COM+ ThreadingCOM+ Threading COM+ Process PoolingCOM+ Process Pooling COM+ SynchronizationCOM+ Synchronization COM+ ActivationCOM+ Activation

Page 21: Maximizing COM+ Application Throughput Steve Swartz Program Manager COM+ Team Microsoft Corporation 1-402

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

Page 22: Maximizing COM+ Application Throughput Steve Swartz Program Manager COM+ Team Microsoft Corporation 1-402

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

Page 23: Maximizing COM+ Application Throughput Steve Swartz Program Manager COM+ Team Microsoft Corporation 1-402

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

Page 24: Maximizing COM+ Application Throughput Steve Swartz Program Manager COM+ Team Microsoft Corporation 1-402

Example: SynchronizationExample: Synchronization

What you have to change to use What you have to change to use COM+ synchronizationCOM+ synchronization

Page 25: Maximizing COM+ Application Throughput Steve Swartz Program Manager COM+ Team Microsoft Corporation 1-402

OverviewOverview

Throughput: What and HowThroughput: What and How COM+ ThreadingCOM+ Threading COM+ Process PoolingCOM+ Process Pooling COM+ SynchronizationCOM+ Synchronization COM+ ActivationCOM+ Activation

Page 26: Maximizing COM+ Application Throughput Steve Swartz Program Manager COM+ Team Microsoft Corporation 1-402

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

Page 27: Maximizing COM+ Application Throughput Steve Swartz Program Manager COM+ Team Microsoft Corporation 1-402

Optimizing COM+ ActivationOptimizing COM+ Activation

JITJIT Object PoolingObject Pooling Recent TPC-C benchmarksRecent TPC-C benchmarks

Page 28: Maximizing COM+ Application Throughput Steve Swartz Program Manager COM+ Team Microsoft Corporation 1-402

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

Page 29: Maximizing COM+ Application Throughput Steve Swartz Program Manager COM+ Team Microsoft Corporation 1-402

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

Page 30: Maximizing COM+ Application Throughput Steve Swartz Program Manager COM+ Team Microsoft Corporation 1-402

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

Page 31: Maximizing COM+ Application Throughput Steve Swartz Program Manager COM+ Team Microsoft Corporation 1-402

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

Page 32: Maximizing COM+ Application Throughput Steve Swartz Program Manager COM+ Team Microsoft Corporation 1-402

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

Page 33: Maximizing COM+ Application Throughput Steve Swartz Program Manager COM+ Team Microsoft Corporation 1-402

Example: Example: JIT and Object Pooling JIT and Object Pooling

QueuedPoolof

MTAThreads

JITtedObjects

inObjectPool

ISAPISQL

Server

Page 34: Maximizing COM+ Application Throughput Steve Swartz Program Manager COM+ Team Microsoft Corporation 1-402