Post on 19-Jan-2016
CTS405 Connected Applications Choosing A Hosting Model
CTS405 Connected Applications Choosing A Hosting Model
Lance OlsonLance OlsonLead Program ManagerLead Program ManagerMicrosoftMicrosoft
Connected Systems TrackConnected Systems TrackMon 10:45Mon 10:45 CTS200 Service Orientation and the Windows/.NET DeveloperCTS200 Service Orientation and the Windows/.NET Developer
Mon 1:30Mon 1:30 CTS300 Prescriptive Guidance-Juggling Web Services, WSE, .NET Remoting, CTS300 Prescriptive Guidance-Juggling Web Services, WSE, .NET Remoting, System.EnterpriseServices, and MSMQSystem.EnterpriseServices, and MSMQ
Mon 3:15Mon 3:15 CTS308 Applied Web Services in Hewlett Packard's Core eCommerce SolutionsCTS308 Applied Web Services in Hewlett Packard's Core eCommerce Solutions
Mon 5:00Mon 5:00 CTS404 Best Practices for Dealing With State at Multiple Layers Within CTS404 Best Practices for Dealing With State at Multiple Layers Within Your .NET ApplicationsYour .NET Applications
Tue 1:30Tue 1:30 DEVC27 Service Orientation OverviewDEVC27 Service Orientation Overview
Tue 3:15Tue 3:15 CTS301 Managed Programming for Win32 DevelopersCTS301 Managed Programming for Win32 Developers
Wed 2:00Wed 2:00 CTS302 Using Web Services Enhancements v2.0 (WSE) to Secure Web ServicesCTS302 Using Web Services Enhancements v2.0 (WSE) to Secure Web Services
Wed 10:15Wed 10:15 CTS400 Using Web Services Enhancements v2.0 for Messaging Over Multiple CTS400 Using Web Services Enhancements v2.0 for Messaging Over Multiple Machines and NetworksMachines and Networks
Wed 5:30Wed 5:30 CTS303 Applied Web Services at the Ohio State University Medical CenterCTS303 Applied Web Services at the Ohio State University Medical Center
Thur 8:30Thur 8:30 CTS403 Handling Errors with TransactionsCTS403 Handling Errors with Transactions
Thur 8:30Thur 8:30 DEVC35 Web Services InteroperabilityDEVC35 Web Services Interoperability
Thur 1:30Thur 1:30 CTS406 Versioning of Connected .NET ApplicationsCTS406 Versioning of Connected .NET Applications
Thur 1:30Thur 1:30 DEVC16 Distributed Applications Performance PanelDEVC16 Distributed Applications Performance Panel
Thur 5:00Thur 5:00 CTS304 Availability and Reliability - Failure Is Not An OptionCTS304 Availability and Reliability - Failure Is Not An Option
Fri 10:45 CTS405 Choosing a Hosting Model - Dealing with Threads, AppDomains, and Processes
Fri 1:00Fri 1:00 CTS306 Deployment and ManagementCTS306 Deployment and Management
Fri 2:45Fri 2:45 CTS307 Using Service Orientation to Drive Business ProcessesCTS307 Using Service Orientation to Drive Business Processes
Fri 9:00Fri 9:00 DEVC40 Versioning PanelDEVC40 Versioning Panel
Scope Of This TalkScope Of This Talk
In scope…Application executionIn scope…Application executionApplication execution “hosting” as Application execution “hosting” as defined by the process model, threading, defined by the process model, threading, and inherent application services and inherent application services
NOT in scope…Online “hosting” NOT in scope…Online “hosting” businessbusiness
““Hosting” as in application hosting via Hosting” as in application hosting via online sites, co-location, etc.online sites, co-location, etc.
AgendaAgenda
Running managed codeRunning managed code
Hosting environmentsHosting environments
Relating the connected technologiesRelating the connected technologies
Choosing the right modelChoosing the right model
Running Managed CodeRunning Managed Code
Managed Code BasicsManaged Code Basics
All managed code runs in an All managed code runs in an Operating System processOperating System processApplication Domains are Application Domains are the principal managed runtime the principal managed runtime environment environment
Types are loaded per-Application Types are loaded per-Application DomainDomainObject references are scoped Object references are scoped to domainto domainSecurity policy is per domainSecurity policy is per domain
An Operating System process may An Operating System process may host multiple Application Domainshost multiple Application DomainsThere is one default Application There is one default Application Domain per processDomain per process
ProcessProcess
Application DomainApplication Domain
TypeType TypeType TypeType
Application DomainApplication Domain
TypeType TypeType TypeType
Application DomainApplication Domain
TypeType TypeType TypeType
Before The 1st AppDomain…Before The 1st AppDomain…
The CLR is initialized from unmanaged code The CLR is initialized from unmanaged code via a calls into mscoree.dllvia a calls into mscoree.dll
_CorExeMain for managed EXEs_CorExeMain for managed EXEs
_CorDllMain for managed DLLs loaded _CorDllMain for managed DLLs loaded via LoadLibraryvia LoadLibrary
DllGetClassObject for REGASM’ed DLLsDllGetClassObject for REGASM’ed DLLs
CorBindToRuntimeEx et al for “explicit” hostsCorBindToRuntimeEx et al for “explicit” hosts
At most one instance of the CLR per processAt most one instance of the CLR per processOnly one version (e.g., 1.0, 1.1, Whidbey) Only one version (e.g., 1.0, 1.1, Whidbey)
Server (MP) versus Workstation (UP)Server (MP) versus Workstation (UP)
Concurrent GC process-wideConcurrent GC process-wide
Loader optimization settingsLoader optimization settings
The App Domain LifecycleThe App Domain Lifecycle
Each App Domain gets initialized with Each App Domain gets initialized with the followingthe following
.config XML doc (may be in memory).config XML doc (may be in memory)
Auxiliary properties (e.g., APPBASE, Auxiliary properties (e.g., APPBASE, shadow copy, search path)shadow copy, search path)
Security evidence for top-of-stack Security evidence for top-of-stack CASCAS
Assemblies get loaded and code gets Assemblies get loaded and code gets run using cross-domain remotingrun using cross-domain remoting
App Domain unloads and takes down App Domain unloads and takes down assemblies with itassemblies with it
Application DomainApplication Domain
Config SettingsConfig SettingsSecurity EvidenceSecurity EvidencePropertiesProperties
Assembly AAssembly A
Assembly BAssembly B
Hosting EnvironmentsHosting Environments
Hosting OverviewHosting Overview
What does your host do for you?What does your host do for you?Some things are clearSome things are clear
Process managementProcess management
ThreadingThreading
Application domainsApplication domains
But the details are not always obviousBut the details are not always obviousShould I use IIS, an NT service, or Should I use IIS, an NT service, or Enterprise Services?Enterprise Services?
Differences range from subtle to dramaticDifferences range from subtle to dramatic
Some hosts couple process model with Some hosts couple process model with environment and application servicesenvironment and application services
Hosting EnvironmentsHosting Environments
Manual process creationManual process creationManaged Console executableManaged Console executable
Windows FormsWindows Forms
Automatic process creationAutomatic process creationManaged Windows NT ServiceManaged Windows NT Service
Enterprise ServicesEnterprise Services
IIS/ASP.NETIIS/ASP.NET
Hosting In The ConsoleHosting In The Console
Basic usageBasic usageCommon simple test environmentCommon simple test environment
Great for basicGreat for basic batch-style execution batch-style execution
Free threaded environmentFree threaded environment
Loaded by Windows LoaderLoaded by Windows Loader
Code runs in the default Code runs in the default application domainapplication domain
TipsTipsExtremely simple – Extremely simple – No major surprisesNo major surprises
Batch-file level management and Batch-file level management and deploymentdeployment
Be aware of differences when using Be aware of differences when using the console to test your applicationthe console to test your application
App1.exeApp1.exe
Default App DomainDefault App Domain
TypeType TypeType TypeType
Hosting In Windows FormsHosting In Windows Forms
Basic usageBasic usageRich local Windows UIRich local Windows UI
Front end to a multi-tiered Front end to a multi-tiered applicationapplication
Loaded by Windows LoaderLoaded by Windows Loader
Code runs in the default Code runs in the default application domainapplication domain
TipsTipsBe aware of the UI threadBe aware of the UI thread
Use control.BeginInvoke to Use control.BeginInvoke to marshal from IO threads to mainmarshal from IO threads to main
Management and deployment Management and deployment significantly improved significantly improved by ClickOnceby ClickOnce
See DEV364 presentationSee DEV364 presentation
App1.exeApp1.exe
Default App DomainDefault App Domain
TypeType TypeType TypeType
Inspecting A Inspecting A Managed .EXEManaged .EXE
Hosting EnvironmentsHosting Environments
Manual process creationManual process creationManaged Console executableManaged Console executable
Windows FormsWindows Forms
Automatic process creationAutomatic process creationWindows NT ServiceWindows NT Service
Enterprise ServicesEnterprise Services
IIS/ASP.NETIIS/ASP.NET
What Do They Do?What Do They Do?
Activation / startupActivation / startup
Process identityProcess identity
PoolingPooling
ManagementManagement
DebuggingDebugging
ShutdownShutdown
RecyclingRecycling
Starting The Application Enterprise ServicesStarting The Application Enterprise Services
On demand On demand or automaticor automatic
In process – LibraryIn process – Library
Out of proc – Server Out of proc – Server (Dllhost.exe)(Dllhost.exe)
Process instance or Process instance or NT serviceNT service
Dllhost.exe loads CLRDllhost.exe loads CLR
Code runs in default Code runs in default application domainapplication domain
DllHost.exeDllHost.exe
DCOM/RPCDCOM/RPC
App DomainApp Domain
Starting The Application ASP.NET / IIS 6.0Starting The Application ASP.NET / IIS 6.0
On demand start upOn demand start up
W3svc manages W3svc manages processesprocesses
Application runs in Application runs in w3wp.exe instancew3wp.exe instance
One app domain One app domain per applicationper application
Commonly the Commonly the virtual directory virtual directory
http://server.com/myapp1http://server.com/myapp1
W3SVCW3SVC
HTTP.SYSHTTP.SYS
kern
elke
rnel
W3WP.exeW3WP.exe
App App
DomainDomain
Starting The Application NT ServicesStarting The Application NT Services
Automatic start upAutomatic start up
Application runs Application runs in service in service process instanceprocess instance
Manual, Auto, Disabled Manual, Auto, Disabled startup statestartup state
Specify service Specify service dependenciesdependencies
Default app domainDefault app domain
Multiple services Multiple services per processper process
Service Control ManagerService Control Manager
MyService.exeMyService.exe
App DomainApp Domain
Process IdentityProcess Identity
Generally the same feature set Generally the same feature set across all threeacross all three
Run under specified accountRun under specified account
Mark account as interactiveMark account as interactiveCommonly used for debuggingCommonly used for debugging
ASP.NET and Enterprise Services also ASP.NET and Enterprise Services also support caller impersonationsupport caller impersonation
Pooling ProcessesPooling Processes
Process PoolingProcess Pooling Process PinningProcess Pinning
Enterprise Enterprise ServicesServices
YesYes CoCreateInstance CoCreateInstance picks a process picks a process then sticks until then sticks until the client calls the client calls releaserelease
ASP.NET / IIS 6.0ASP.NET / IIS 6.0 YesYes First request gets First request gets round robin, then round robin, then sticks based on sticks based on the connectionthe connection
NT ServicesNT Services NoNo n/an/a
Pooling Application DomainsPooling Application Domains
Enterprise ServicesEnterprise ServicesOne app domain per COM+ applicationOne app domain per COM+ application
One COM+ application per processOne COM+ application per process
ASP.NET / IIS 6.0ASP.NET / IIS 6.0One application domain per IIS applicationOne application domain per IIS application
Many applications per processMany applications per processGet more applications running on the boxGet more applications running on the box
Be aware that applications in the same process must Be aware that applications in the same process must “play well” together“play well” together
NT ServicesNT ServicesOne application domain per processOne application domain per process
Services share the same application domainServices share the same application domain
Pooling ThreadsPooling Threads
Enterprise ServicesEnterprise ServicesOperating System completion port Operating System completion port thread poolthread pool
Limited only by contentionLimited only by contention
ASP.NET / IIS 6.0ASP.NET / IIS 6.0Managed CLR thread poolManaged CLR thread pool
Limited to 20 completion port and 20 Limited to 20 completion port and 20 worker threads per CPU by defaultworker threads per CPU by default
NT ServicesNT ServicesN/AN/A
Request QueuingRequest Queuing
Enterprise ServicesEnterprise ServicesSatisfy all requests eventuallySatisfy all requests eventually
Requests aren’t queued unless you’re Requests aren’t queued unless you’re explicitly using a queuing technologyexplicitly using a queuing technology
Geared towards short and long-lived Geared towards short and long-lived application operationsapplication operations
STA components change everythingSTA components change everythingE.g. VB 6 codeE.g. VB 6 code
Request QueuingRequest Queuing
ASP.NET / IIS 6.0ASP.NET / IIS 6.0Satisfy the majority of requests as quickly as Satisfy the majority of requests as quickly as possiblepossible
Requests are given a time limit to complete workRequests are given a time limit to complete work
Requests are queued once the thread pool limit is Requests are queued once the thread pool limit is reachedreached
Once queue limit is reached requests are rejectedOnce queue limit is reached requests are rejected
Geared towards serving up application UIGeared towards serving up application UI
NT ServicesNT ServicesNone provided by the environmentNone provided by the environment
Managing ProcessesManaging Processes
HealthHealth Command and Command and ControlControl
InspectionInspection
Enterprise Enterprise ServicesServices
Through COM+ System Through COM+ System ApplicationApplication
Start, stop, pause, Start, stop, pause, resume, enable, disableresume, enable, disable
Process dumpProcess dump
Enumerate Enumerate running processes, running processes, classes, classes, transactionstransactions
ASP.NET ASP.NET IIS 6.0IIS 6.0
Process and app Process and app domain level “ping”domain level “ping”
Failure triggersFailure triggers
Start, stop, pause, Start, stop, pause, resumeresume
View running View running processesprocesses
NT NT ServicesServices
Failure triggers Failure triggers Start, stop, pause, Start, stop, pause, continuecontinue
Execute custom Execute custom commandscommands
Enumerate Enumerate servicesservices
Debugging ProcessesDebugging Processes
Enterprise ServicesEnterprise ServicesMemory dumpMemory dump
On failure or on demandOn failure or on demand
Launch in debugger on failureLaunch in debugger on failure
ASP.NET / IIS 6.0ASP.NET / IIS 6.0Put process in “orphan” mode on failure Put process in “orphan” mode on failure for debuggingfor debugging
NT ServicesNT ServicesAttach directly to debugAttach directly to debug
RecyclingRecycling
Time Time LapsedLapsed
MemoryMemory Req. Req. BasedBased
IdleIdle Activation Activation CountCount
ScheduledScheduled
Enterprise Enterprise ServicesServices
YesYes YesYes YesYes YesYes YesYes NoNo
ASP.NET ASP.NET IIS 6.0IIS 6.0
Yes Yes YesYes YesYes YesYes NoNo YesYes
NT NT ServicesServices
N/AN/A
Inspecting Automatic Inspecting Automatic Process Creation Process Creation EnvironmentsEnvironments
Relating Connected Technologies
Relating Connected Technologies
Does The Host Care?Does The Host Care?
Some care about the hostSome care about the hostExposing Web Services in .ASMXExposing Web Services in .ASMX
WSE 1.0WSE 1.0
Others don’tOthers don’tSystem.NetSystem.Net
System.MessagingSystem.Messaging
Does The Host Care?Does The Host Care?
Others VaryOthers Vary
.NET Remoting .NET Remoting In your process, an NT Service, or in IISIn your process, an NT Service, or in IIS
Enterprise Services Enterprise Services In your process, an NT Service, or DllhostIn your process, an NT Service, or Dllhost
WSE 2.0 WSE 2.0 HTTP requires ASP.NETHTTP requires ASP.NET
TCP in your process or an NT ServiceTCP in your process or an NT Service
Most Common IssuesMost Common Issues
Long-lived operations in Long-lived operations in ASP.NET / IIS 6.0ASP.NET / IIS 6.0
Consider using queuesConsider using queuesDatabaseDatabase
Enterprise ServicesEnterprise Services
System.MessagingSystem.Messaging
ASP.NET services coupled ASP.NET services coupled with hostingwith hosting
Mixing the technologiesMixing the technologies““Don’t give me multiple models!”Don’t give me multiple models!”
Choosing The Right ModelChoosing The Right Model
Hosting With ASP.NET / IIS 7Hosting With ASP.NET / IIS 7
ComponentizationComponentization
Protocol independent activationProtocol independent activation
Decouple services from hosting modelDecouple services from hosting model
Enhancing the loaderEnhancing the loaderBetter support for Better support for Enterprise Services scenariosEnterprise Services scenarios
Hosting With IndigoHosting With Indigo
Uses ASP.NET / IIS 6 for HTTP Uses ASP.NET / IIS 6 for HTTP activationactivation
Uses ASP.NET / IIS 7 for HTTP Uses ASP.NET / IIS 7 for HTTP activation plus other protocolsactivation plus other protocols
E.g. SOAP over TCP, IPCE.g. SOAP over TCP, IPC
Expect to see better support for Expect to see better support for Enterprise Services class of scenariosEnterprise Services class of scenarios
Choosing The Right modelChoosing The Right model
Richard Turner’s roadmap talk CTS300Richard Turner’s roadmap talk CTS300Build services using ASMX Build services using ASMX
Components should stay WITHIN Components should stay WITHIN your Servicesyour Services
Use Enterprise Services if you need it’s Use Enterprise Services if you need it’s rich servicesrich services
Use .NET Remoting X-AppDomainUse .NET Remoting X-AppDomain
Use System.Messaging for async Use System.Messaging for async queued messagingqueued messaging
Recommendations Does Your Application…Recommendations Does Your Application…
Need to serve up Web content?Need to serve up Web content?Use ASP.NET / IIS 6.0Use ASP.NET / IIS 6.0
Also need to perform long-lived tasks? Also need to perform long-lived tasks? I.e. order/inventory request processingI.e. order/inventory request processing
Use ASP.NET / IIS 6.0 on the front endUse ASP.NET / IIS 6.0 on the front end
Use queued Enterprise Services in an NT Use queued Enterprise Services in an NT service to perform the long-lived workservice to perform the long-lived work
Need to start at boot time and always Need to start at boot time and always be running?be running?
Use NT ServicesUse NT Services
ConclusionConclusion
Decide how your application needs toDecide how your application needs to
behave, then use the roadmap guidancebehave, then use the roadmap guidance
and the hosting model guidance to drive and the hosting model guidance to drive
your architectureyour architecture
Attend a free chat or web castAttend a free chat or web casthttp://www.microsoft.com/communities/chats/default.mspxhttp://www.microsoft.com/communities/chats/default.mspx http://www.microsoft.com/usa/webcasts/default.asphttp://www.microsoft.com/usa/webcasts/default.asp
List of newsgroupsList of newsgroupshttp://communities2.microsoft.com/http://communities2.microsoft.com/communities/newsgroups/en-us/default.aspxcommunities/newsgroups/en-us/default.aspx
Microsoft Community SitesMicrosoft Community Siteshttp://www.microsoft.com/communities/default.mspxhttp://www.microsoft.com/communities/default.mspx
Locate Local User GroupsLocate Local User Groupshttp://www.microsoft.com/communities/usergroups/default.mspxhttp://www.microsoft.com/communities/usergroups/default.mspx
Community sitesCommunity siteshttp://www.microsoft.com/communities/related/default.mspxhttp://www.microsoft.com/communities/related/default.mspx
Q1:Q1: Overall satisfaction with the sessionOverall satisfaction with the session
Q2:Q2: Usefulness of the informationUsefulness of the information
Q3:Q3: Presenter’s knowledge of the subjectPresenter’s knowledge of the subject
Q4:Q4: Presenter’s presentation skillsPresenter’s presentation skills
Q5:Q5: Effectiveness of the presentationEffectiveness of the presentation
Please fill out a session evaluation on CommNetPlease fill out a session evaluation on CommNet
Connected Systems TrackConnected Systems TrackMon 10:45Mon 10:45 CTS200 Service Orientation and the Windows/.NET DeveloperCTS200 Service Orientation and the Windows/.NET Developer
Mon 1:30Mon 1:30 CTS300 Prescriptive Guidance-Juggling Web Services, WSE, .NET Remoting, CTS300 Prescriptive Guidance-Juggling Web Services, WSE, .NET Remoting, System.EnterpriseServices, and MSMQSystem.EnterpriseServices, and MSMQ
Mon 3:15Mon 3:15 CTS308 Applied Web Services in Hewlett Packard's Core eCommerce SolutionsCTS308 Applied Web Services in Hewlett Packard's Core eCommerce Solutions
Mon 5:00Mon 5:00 CTS404 Best Practices for Dealing With State at Multiple Layers Within CTS404 Best Practices for Dealing With State at Multiple Layers Within Your .NET ApplicationsYour .NET Applications
Tue 1:30Tue 1:30 DEVC27 Service Orientation OverviewDEVC27 Service Orientation Overview
Tue 3:15Tue 3:15 CTS301 Managed Programming for Win32 DevelopersCTS301 Managed Programming for Win32 Developers
Wed 2:00Wed 2:00 CTS302 Using Web Services Enhancements v2.0 (WSE) to Secure Web ServicesCTS302 Using Web Services Enhancements v2.0 (WSE) to Secure Web Services
Wed 10:15Wed 10:15 CTS400 Using Web Services Enhancements v2.0 for Messaging Over Multiple CTS400 Using Web Services Enhancements v2.0 for Messaging Over Multiple Machines and NetworksMachines and Networks
Wed 5:30Wed 5:30 CTS303 Applied Web Services at the Ohio State University Medical CenterCTS303 Applied Web Services at the Ohio State University Medical Center
Thur 8:30Thur 8:30 CTS403 Handling Errors with TransactionsCTS403 Handling Errors with Transactions
Thur 8:30Thur 8:30 DEVC35 Web Services InteroperabilityDEVC35 Web Services Interoperability
Thur 1:30Thur 1:30 CTS406 Versioning of Connected .NET ApplicationsCTS406 Versioning of Connected .NET Applications
Thur 1:30Thur 1:30 DEVC16 Distributed Applications Performance PanelDEVC16 Distributed Applications Performance Panel
Thur 5:00Thur 5:00 CTS304 Availability and Reliability - Failure Is Not An OptionCTS304 Availability and Reliability - Failure Is Not An Option
Fri 10:45 CTS405 Choosing a Hosting Model - Dealing with Threads, AppDomains, and Processes
Fri 1:00Fri 1:00 CTS306 Deployment and ManagementCTS306 Deployment and Management
Fri 2:45Fri 2:45 CTS307 Using Service Orientation to Drive Business ProcessesCTS307 Using Service Orientation to Drive Business Processes
Fri 9:00Fri 9:00 DEVC40 Versioning PanelDEVC40 Versioning Panel
© 2004 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.