1、WEB相关内容,Charles Ju Senior PFE, Microsoft,调试,CLR Process/Module/Class/MethodTable/MethodDescription 垃圾回收原理 Windbg SOS 符号加载 常用命令,Assembly/Module (!dumpassembly/!dumpmodule),System Domain,Shared Domain,Assembly (Foo1.dll),Assembly (Foo2.dll),Assembly (Foo3.dll),AppDomain (!dumpdomain),EEClass (!dumpcla
2、ss),EEClass (Class3),EEClass (Class2),EEClass (Class1),MethodTable (!dumpmt),MethodDesc (FunctionOne),MethodDesc (FunctionTwo),MethodDesc (FunctionThree),W3wp.exe,AppDomain #1,AppDomain #2,EEClass (Class4),MethodDesc (!dumpmd),The .NET Runtime within a Process: MethodDesc,.NET Threading,A managed th
3、read is a thread object; it can live on a native thread Managed code often calls into unmanaged code,Example,Unmanaged code: JIT,Managed code: called an un-JITted method,Managed code,Unmanaged code: EE found out the target managed method and made the call,Managed code: made a late binding call,Manag
4、ed code,Unmanaged code: ThreadProc calls managed ThreadStart Delegate,call stack grows,CLR Threads Finalizer GC (Server mode) Debugger Timer Threadpool (I/O & Worker) Managed Threads System.Threading.Thread Associated with native threads,.NET Source code,IL and Metadata,Managed Execution Phases,Nati
5、ve Code,Compile Time,Run Time,Phase,.NET Source code,IL and Metadata,IL and Metadata,Native Code,JIT (CLR),Compile,Execute the native code,MyModule:Func1,First call?,CILJit:compileMethod (x86) PreJit:compileMethod (x64) verifies and compiles the IL,Native code, GCInfo, EH data,etc.,Store native code
6、 in memory,Store the address in MethodDesc,Execute the native code,Yes,Retrieve address of native code from MethodDesc,No,Managed Execution: JIT Compilation,Understanding Managed Memory,Managed heaps Loader heap Native heaps Threads Images (.dll files) Other (virtual allocations) Free,0x00000000,0x7
7、FFFFFFF,GC Sequence,Mark gc_heap:mark_phase,Sweep make_free_lists,Plan gc_heap:plan_phase,Relocate gc_heap:relocate_phase,Compact gc_heap:compact_phase,Compact?,SuspendEE,RestartEE,No,Yes,Gen 0,Gen 1,Mark,Plan,Relocate+Compact,Gen 2,3,1,2,5,6,7,9,8,10,4,11,12,13,14,15,16,GC Sequence in Motion,Proces
8、s1.exe,Managed heap,Gen2,Gen1,Gen0,1,2,3,4,Not a finalizable object,Finalizable object, follows Dispose pattern,Finalizable object, doesnt follow Dispose pattern,5,Mark,Sweep,Compact,6,7,8,9,10,11,12,13,14,15,16,17,18,Finalizers: Visual Overview,Build an Exception Information Table for each executab
9、le,Search for an entry for the current method in the table to handle the exception,Handler found?,Create an exception object,Search for an entry for the caller of the current method in the call stack,Exception occurs,Beginning of call stack?,no,no,yes,yes,Exception-Handling Model,Populate exception
10、object Execute finally blocks,Populate exception object Execute finally blocks Resume execution,Unhandled exception event,Terminate process!,Notify Debugger 1st Chance,Notify Debugger2nd Chance,Unhandled Exceptions (UhE),Occurs when an exception is thrown and no catch filter accepts the exception ob
11、ject Set up UnhandledExceptionEventHandler Delegate that is triggered by an unhandled exception CLR handles UhEs differently, depending on the type of thread on which the UhE occurred,调试,常见场景 阻塞 高CPU 高内存 进程崩溃,SQL Server索引调优,数据存储 堆表 索引存储及查找 创建索引 执行计划 I/O,Basic Page Structure,All pages contain a heade
12、r, a body, and a slot array.,Clustered IndexData Access,HeapData Access,Non-Clustered Indexes with a Heap,All rows on leaf pages have pointers to data rows.,Non-Clustered Index with a Clustered Index,Entries in the nonclustered leaf pages contain clustered index key values,IIS,架构对比 重要的配置文件 常见工具 分析Ha
13、ng与Crash,IIS 6.0 Process Model,Svchost.exe,Inetinfo.exe,WWW Service (w3svc),IIS Admin Service,metabase,FTP Service,SMTP Service,NNTP Service,Lsass.exe,Windows Authentication,HTTPAPI,Web garden (w3wp.exe),SSL,Winsock,TCPIP.SYS,HTTP.SYS,User Kernel,Application Pool (w3wp.exe),IISCORE,IIS 6.0 Request F
14、low,HTTP.SYS,User Kernel,aspnet_isapi.dll,ISAPI Filter Notifications,custom errors,authentication,logging,compression,determine handler,NotifyAuth,Notify PreProc,NotifyLog,NotifyResponse,CGI,Static,ISAPI,url map,Begin req,authentication,authorization,resolve cache,map handler,handler exec,update req
15、 cache,rel req state,end request,IHttpHandlers,trace.axd,page handler,IHttpModule Events,ASPX Request,Static Request,IIS 7.5 Process Model,Configuration (applicationhost.config),Svchost.exe,Inetinfo.exe,WWW Service (w3svc),IIS Admin Service,metabase,FTP Service,SMTP Service,NNTP Service,LSASS.EXE,HT
16、TPAPI,Web garden (w3wp.exe),Winsock,TCPIP.SYS,HTTP.SYS,User Kernel,Application Pool (w3wp.exe),WAS,Managed Mods,Managed Mods,Managed Mods,SSL,Windows Auth,IIS 7.5 Request Flow,Integrated pipeline,begin,authenticate,authorize,resolve cache,map handler,acquire state,pre-execute handler,execute handler
17、,release state,update cache,log,end,IHttpModule,Native or Managed Handlers,*.aspx,trace.axd,Managed IHttpHandler,isapi ext,static file,Native Module,Native Handler,User Kernel,HTTP.SYS,IIS 7.5 Processing Modes,Classic Mode Similar to IIS 6.0 Use as a migration path to Integrated mode .NET modules do
18、 not have access to native content processing Duplication of processing steps (e.g., Authentication)Integrated Mode New, Native Model for IIS 7.0 and 7.5 Unified Request Processing Model .NET processing has access to static requests, etc.,Classic Mode,Authentication,Forms Authentication,Windows Auth
19、entication,Map Handler,ASP.NET,HTTP Request,HTTP Response,Integrated Mode,Basic Auth,Windows Auth,Forms Auth,Static File,ASPX,ISAPI (ASP etc.,),CGI,Windows Process Activation Service (WAS),Core Dependency for a Web ServerConfiguration ManagerProcess ManagerListener Adapter InterfaceSupport for Non-H
20、TTP Protocols,Configuration Store,Machine.Config,applicationHost.Config,Root Web.config,Site Web.Config,Application Web.Config,Directory Web.Config,Core Component Interaction,HTTP.SYS,W3SVC,WAS,Worker Process,Configuration Store,1,2,9,3,8,4,5,6,7,10,11,12,Kernel,User,Configuration Hierarchy,MACHINE/
21、WEBROOT/APPHOST/SiteName/VirtualDir/,Machine.config,Root web.config,applicationHost.config,optional web.config,optional web.config,optional web.config,.NET Framework,IIS,Machine.config,Present in the framework folder: %windir%Microsoft.NETFrameworkvX.X.XXXXConfig %windir%Microsoft.NETFramework64vX.X
22、.XXXXConfigOne file per system per framework versionContains settings for .NET Framework at a system levelTop of the configuration hierarchy when specifying a path,Additional Configuration Files,administration.config UI settings Modules, Delegation settings, etc. IIS Manager Users credentialsredirec
23、tion.config Used when Shared Configuration is enabled Points to the remote applicationHost.config used with Shared Configuration,Appcmd.exe,%windir%system32inetsrvappcmd.exeProvides a single command line interface for managing the entire Web server Allows piping output to file system; choice of text
24、 or XML outputAdministrator-level permission required to run it,APPCMDUI,Wraps Appcmd.exe to provide an auto-complete interfaceProvides help for commands, including sample outputNo support provided by CSSDownload from http:/ v2,Set-ExecutionPolicy RemoteSigned Import-Module WebAdministration get-com
25、mand -module WebAdministration File system IIS: Cd Dir,IIS Log Files,Web logs (w3svc# logfile directory) have a new home in IIS 7.x they are now located in c:inetpublogslogfiles TimeTaken HTTP Status Codes & Sub-Status Codes The HTTP Error logs remain in c:windowssystem32logfileshttperr Failed Reque
26、st Tracing logs are located in c:inetpublogsFailedReqLogFiles Detailed log of failed requests Not enabled by default Use System and Application Event Logs for troubleshooting service errors and worker process failures,Failed Request Event Buffering (FREB),Enable no-repro instrumentation for “failed
27、requests” Turn tracing on, but only keep the events for “failed requests” Allow for custom failure definitions per URL Time taken Status/substatus codes Enable per-URL trace configuration Define what to trace on a per URL basis Example: only trace aspnet events for “*.aspx” Persist failure log files
28、 beyond process lifetime,Event Tracing for Windows (ETW),High-performance, low-overhead tracing mechanism built into Windows Provider/consumer architecture Applications can register their own event providers Many, many providers in Server 2008 R2 Logman query providers to list Can trace: IIS startup
29、/shutdown Requests Configuration changes Much more,ETW,logman query providers logman query providers “ASP.NET Events“ logman start aspnet -p “ASP.NET Events“ 0xF 0x05 -o aspnet.etl -ets Logman stop aspnet -ets tracerpt aspnet.etl -o aspnetdump.csv -of CSV,Runtime Status and Control API (RSCA),API to
30、 obtain runtime status & control of: AppPools Worker Processes Web Sites App Domains Provide means of obtaining current runtime state of Application Pools, Web Sites, Application Domains, & Worker Processes Provide direct & consistent way to start/stop web sites Expose detailed runtime state data,To
31、ols,IIS Logs Failed Request Event Buffering Event Tracing for Windows Runtime Status and Control API Configuration Auditing Best Practices Analyzer Delegation Configuration Tool Fiddler Logparser Performance Monitor,Tools (continued),Process Monitor Network Monitor WCAT WFetch Debugging Tools for Wi
32、ndows DebugDiag,Identifying Hangs,Application stops responding to requests Requests Executing and Requests Queued counters increasing Blank pages, timeouts or HTTP 500 errors to clients Low or high CPU hang?,Troubleshooting Hangs,Switch off all proactive recycling Wait for problem to occur again Gat
33、her Perfmon data Run ADPlus in hang mode (or use ProcDump) OrphanWorkerProcess, OrphanActionExe may help Get at least two dumps in the case of a high CPU hang Analyze Perfmon data Analyze memory dump in DebugDiag or WinDBG,Identifying Crashes,Browser errors “The connection with the server was reset”
34、 “The remote procedure call failed” “The RPC server is unavailable” ASP 0115 / HTTP 500 Event logs WAS event Ids 5009, 5011 IIS logs HTTPERR logs Connection_Abandoned_By_ReqQueue DefaultAppPool,Troubleshooting Crashes,Review event logs Review IIS logs for HTTP 500/ASP 0115 errors Switch off all proactive recycling Run ADPlus in crash mode or use ProcDump.exe Analyze memory dump in DebugDiag or WinDBG,