1 / 52

使用微軟工具來進行 IIS 6.0 除錯與資料探勘

使用微軟工具來進行 IIS 6.0 除錯與資料探勘. 胡士亮 平台架構技術經理 台灣微軟 開發工具暨平台推廣處. 內容大綱. 甚麼是 Log Parser 開始使用 Log Parser Log Parser 2.2 版新功能 Log Parser 進階使用情境 網站應用程式除錯基礎 除錯工具介紹  Debug Diagnostics 1.0 功能介紹 常見的網站應用程式除錯情境. Log Parser Basics Key Concepts. Log Parser requires… Input Format [+options] Query

morty
Download Presentation

使用微軟工具來進行 IIS 6.0 除錯與資料探勘

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 使用微軟工具來進行IIS 6.0 除錯與資料探勘 胡士亮 平台架構技術經理 台灣微軟 開發工具暨平台推廣處

  2. 內容大綱 • 甚麼是Log Parser • 開始使用Log Parser • Log Parser 2.2 版新功能 • Log Parser 進階使用情境 • 網站應用程式除錯基礎 • 除錯工具介紹 •  Debug Diagnostics 1.0 功能介紹 • 常見的網站應用程式除錯情境

  3. Log Parser BasicsKey Concepts • Log Parser requires… • Input Format • [+options] • Query • Output Format • [+options] • [+options] • Query Language: • Supports most of the true SQL language syntax • Extends the language with additional functions

  4. Demonstration 1First Walk-ThroughLog Parser Command-Line Help Simple QueryUsing Input/Output Parameters

  5. Log Parser BasicsFunctions • To get a list of functions • [2.1]logparser –h 2 • [2.2]logparser –h FUNCTIONS • Examples: • Conversion Functions • TO_TIMESTAMP • TO_LOCALTIME • TO_INT • String Handling • STRLEN • SUBSTR • STRCAT • Other • REVERSEDNS • QUANTIZE • EXTRACT_EXTENSION [2.2] • CASE [2.2]

  6. Log Parser BasicsFunction Example • Convert log file timestamp from UTC time to local time: SELECT TO_DATE( TO_LOCALTIME( TO_TIMESTAMP(date, time))) AS date, TO_TIME( TO_LOCALTIME( TO_TIMESTAMP(date, time))) AS time, c-ip, cs-username, s-ip, s-port, cs-method, cs-uri-stem, cs-uri-query, sc-status, sc-win32-status, sc-bytes, cs-bytes, time-taken, cs(User-Agent) FROM C:\WINDOWS\system32\Logfiles\W3SVC1\ex040308.log

  7. Demonstration 2Functions Convert Log File Time from UTC Time to Local TimeExamine Time Taken Per VDir

  8. Log Parser BasicsOutput Templates • logparser -h -o:TPL • Consists of: • Header • Body • Footer • Best for report-style results TEMPLATE OUTPUT <HTML> <HEAD> <TITLE>Hits/Hour for Ledbury Home Page</TITLE> </HEAD> <BODY BGCOLOR="#EFEFFF"> <TABLE BORDER="1" CELLPADDING="2“ CELLSPACING="2"> <TR> <TH COLSPAN="2" ALIGN="CENTER"> Hits/Hour for Ledbury Home Page </TH> </TR> <TR> <TH ALIGN="LEFT">Hour</TH> <TH ALIGN="LEFT"># Hits</TH> </TR> <TR><TD>2004-03-07 22:00:00</TD><TD>1</TD></TR> <TR><TD>2004-03-09 09:00:00</TD><TD>2</TD></TR> <TR><TD>2004-03-10 18:00:00</TD><TD>2</TD></TR> </TABLE> </BODY> </HTML> HEADER BODY FOOTER

  9. Demonstration 3Templates Broken Links ReportEvent Log Messages

  10. Log Parser BasicsImporting Data into SQL Server • Note: Field names in query output are not important -- the field position determines what column the data is inserted into in the SQL table allows for an auto-generated identity column in SQL SELECT 1, TO_TIMESTAMP(date, time) AS LogTimeStamp, s-ip, cs-method, cs-uri-stem, cs-uri-query, s-port, cs-username, c-ip, cs(User-Agent), sc-status, sc-substatus, sc-win32-status INTO W3SVC2 FROM ex040309.log database table

  11. Log Parser BasicsHow do I get started? • Find the column names in your data source: • LogParser –h –i:<IISW3C|IIS|EVT> • or… “SELECT * FROM <datasource>” • For TSV or CSV files: • LogParser –h –i:CSV/TSV <filename> • Understand data provided in the columns • Apply any functions necessary to convert that data into a useful form • [2.2] –queryinfo Option

  12. Building on Log ParserLog Parser COM Architecture • MSUtil.LogQuery • Input and Output Format objects • MSUtil.LogQuery.IISW3CInputFormat • MSUtil.LogQuery.EventLogInputFormat • MSUtil.LogQuery.SQLOutputFormat • MSUtil.LogQuery.CSVOutputFormat • Two ways to run query: • MSUtil.LogQuery.Execute • Returns a LogRecordSet object that allows the script to iterate through the query results • MSUtil.LogQuery.ExecuteBatch • Runs a query with a pre-specified output target (e.g. SQL or CSV)

  13. Building on Log ParserInput/Output Format Parameters • Log Parser 2.1 and 2.0 • Parameters do not always have same name for command-line version and COM version; for example: • logparser file:query.sql –o:NAT –rtp:-1 • NativeOutputFormat.rowsToPrint • http://www.logparser.com/InstantKB/article.aspx?id=10039 • Log Parser 2.2 • Parameters have same name for both command line tool and COM interface

  14. Building on Log ParserVBScript • Create LogQuery object and input/output format objects DIM objLogQuery : SET objLogQuery = WScript.CreateObject("MSUtil.LogQuery") ' Get the IIS Input and W3C output formats DIM w3cInputFormat : SET w3cInputFormat = WScript.CreateObject("MSUtil.LogQuery.IISW3CInputFormat") DIM w3cOutputFormat : SET w3cOutputFormat = WScript.CreateObject("MSUtil.LogQuery.W3COutputFormat") w3cOutputFormat.filemode = 0 ' Create a SQL query query = "SELECT TOP 20 cs-uri-stem, COUNT(*) as Total " & _ "INTO results.log FROM C:\WINDOWS\system32\Logfiles\W3SVC1\ex*.log " & _ "GROUP BY cs-uri-stem ORDER BY Total DESC " objLogQuery.ExecuteBatch query, w3cInputFormat, w3cOutputFormat For an example that uses Execute and LogRecordSet, see \Samples\Scripts\ ErrorCodes.js in Log Parser installation directory. This is also available on TechNet: http://www.microsoft.com/technet/community/scriptcenter/logs/logparser/scripts/ logpar01.mspx.

  15. Building on Log ParserC# Interop • Uses System.Reflection and System.Activator Type comLogQueryType = Type.GetTypeFromProgID("MSUtil.LogQuery", true); object comLogQueryObject = Activator.CreateInstance(comLogQueryType); // Get the IIS Input and W3C output formats Type inputFormatType = Type.GetTypeFromProgID("MSUtil.LogQuery.IISW3CInputFormat", true); object inputFormatObject = Activator.CreateInstance(inputFormatType); Type outputFormatType = Type.GetTypeFromProgID("MSUtil.LogQuery.W3COutputFormat", true); object outputFormatObject = Activator.CreateInstance(outputFormatType); // Create a SQL query string query = "SELECT TOP 20 cs-uri-stem, COUNT(*) as Total "; query += "INTO results.log FROM C:\\WINDOWS\\system32\\Logfiles\\W3SVC1\\ex*.log "; query += "GROUP BY cs-uri-stem ORDER BY Total DESC "; // Invoke the ExcuteBatch method object[] inputArgs = {query, inputFormatObject, outputFormatObject}; comLogQueryType.InvokeMember("ExecuteBatch", BindingFlags.InvokeMethod, null, comLogQueryObject, inputArgs);

  16. Log Parser 2.2 PreviewWhat you want to know… • Releases: • Beta Version => TechNet Subscribers only, April 2004 • Final Version => Summer 2004 • What's new in Log Parser 2.2? … this and more… • New Input Formats • ETW – Event Tracing for Windows® log files and live sessions • TSV – Tab and Space separated value text files • ADS – Reads information from Active Directory objects • REG – Reads information from the Registry • NETMON – Parses NETMON captures • COM – Plug in user-implemented custom Input Formats

  17. Log Parser 2.2 PreviewWhat you want to know… (2) • What's new in Log Parser 2.2? … this and more… • New Output Formats • CHART – Creates charts (requires Microsoft® Office XP or better) • SYSLOG – Sends information to a SYSLOG server or to a SYSLOG-formatted text file • TSV – Writes to a Tab or Space separated value file • Improvements to SQL Engine • Added SQL operators - BETWEEN, CASE, "WITH ROLLUP" in GROUP BY • New Functions – MOD, EXTRACT_EXTENSION … and many more • Performance • Improvements to existing Input/Output Formats • Bug Fixes

  18. Log Parser 2.2 Preview-queryinfo C:\DemoScripts>logparser file:SQLDB_Insert.sql -queryinfo WARNING: Output format not specified - using NAT output format. Query: SELECT 1, TO_TIMESTAMP(date,time) AS LogTimeStamp, [s-ip], [cs-method], [cs-uri-stem], [cs-uri-query], [s-port], [cs-username], [c-ip], [cs(User-Agent)], [sc-status], [sc-substatus], [sc-win32-status], [sc-bytes], [cs-bytes], [time-taken] INTO W3SVC2 FROM ex040309.log Formats selected: Input Format : IISW3C (IIS W3C Extended Log Format) Output Format: NAT (Native Format) Query fields: 1 (I) LogTimeStamp (T) s-ip (S) cs-method (S) cs-uri-stem (S) cs-uri-query (S) s-port (I) cs-username (S) c-ip (S) cs(User-Agent) (S) sc-status (I) sc-substatus (I) sc-win32-status (I) sc-bytes (I) cs-bytes (I) time-taken (I)

  19. Log Parser 2.2 PreviewChart Output Format • Uses Microsoft Office Web Components ChartSpace Object Model • See this link for object model: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/owcvba10/html/octocMSOWCObjectModels.asp • You will need: • Licensed version of Microsoft Office Web Components, available in Microsoft Office XP or better • Use Excel to view different CHART types: • Insert Menu, Chart option – shows the different chart types

  20. Demonstration 4Log Parser 2.2 PreviewChartsHits Per Hour – Radial Chart Status Code Breakdown – Pie Chart

  21. Log Parser 2.2 PreviewCheckPoint – incremental parsing • Parse only what has not been parsed before: • ex*.log … from all log files in a directory • <1> … from all log files for site 1 • System … from the System Event Log • Requires a CheckPoint file to store state: logparser "SELECT TimeGenerated, EventTypeName, Strings FROM System WHERE SourceName = 'W3SVC'" -icheckpoint event.lpc

  22. Demonstration 5CheckPointEvent Log Update E-mail

  23. Session SummaryLog Parser has as many applications as you can imagine… • Flexible and powerful • As with all data mining, the application starts with a question… • Building Blocks for Auditing and Monitoring • Log Parser can parse almost any data source on your server… with the additional input and output formats in Log Parser 2.2, there’s really nothing more you need to build custom auditing and monitoring for your system • Any Text, Any Time • LogParser can read most log files, text documents, and STDOUT/text streams, and generate results in a HUGE number of formats to make them useful and intelligible

  24. 議程大綱 • 簡介 • Crash • Hangs • Memory leaks • Debug diagnostics 延展性 • 總結

  25. Web 應用程式除錯簡介 • 除錯歷史的過去與現在簡介 • 整合工具來解決偵錯情境 • 影響除錯的變數

  26. 簡介 • 過去: 提供許多工具但很少解決方案 • 過去的工具通常不是設計給伺服器端使用 • 沒有一個完整涵蓋所有除錯需求的工具 • 需要除錯的專業知識才能使用工具 • 現在: 更多進階的除錯工具但是仍然要花費許多時間來解決問題 • 仍然缺乏分析工具 • 現存工具並沒有整合成為完整的除錯工具

  27. 這是不是您遇過的惡夢? 談到除錯工具… • 現在有三種設計來解決相同問題的工具 • Dr. Watsons • AutoDump Plus • IIS Crash/Hang Agent • 當 Windows Server 版本更新,除錯工具也隨之改版 • 除錯工具的範例

  28. 影響除錯的變數 • IIS 是一個 “應用程式平台” • 非常容易進行延展的平台 • 功能延展方式包括 Proxy 伺服器、網頁上傳/發布元件、Request Handler 以及其他更多延展功能 • 可延展的平台是非常良好的但是可能很難找出問題所在 • 除錯對任何平台來說都是最糟狀況

  29. 影響除錯的變數 • IIS 的延展能力 • ISAPI • Microsoft ASP.NET • Active Server Pages (ASP) • COM 元件 • 資料層驅動程式,例如 Oracle 與 MDAC 等 • 這些 “延展能力” 元件常常整合並執行在相同的程序中

  30. Crash 情境 • Crash 的背景介紹 • 定義並展示 worker process crashes: 與如何除錯 crash • 使用 DebugDiag 來快速找出 Crash 的根本原因

  31. 背景介紹: Exceptions • 什麼是 exception? • 應用程式如何導致 exceptions? • 什麼是 “已處理” 的 exception? • 未處理的 exceptions 需要除錯與解決 Access Violation: C000 0005 Breakpoint Exception: 8000 0003 Stack Overflow: C000 00FD C++ exception: E06D7363 Managed exception: E0434F4D Invalid Handle: C000 0008

  32. 背景介紹: Heap • 什麼是 heap? • Heap 一個資料結構 • Heap 毀損: • 使用 heap 時必須遵守相關規則 • 當違反規則時就會發生 heap 毀損 • Heap 毀損 crashes • 毀損 heap 的程式通常不是受到影響的程式

  33. 現今除錯 Crashes 工具 • Crash 症狀通常包括可在事件檢視器中看到的事件 • 如果啟用 Dr. Watson, crashes 通常會建立memory.dmp • Memory.dmp 是 crash 程序的快照,可以用來進行事後分析

  34. Hang 情境 • “Process hangs” 的理論 • 現在如何除錯 hang • 使用 DebugDiag 來除錯“process hangs”

  35. “Process Hangs” 的理論 • 什麼是 process? • 什麼是 thread? • 程式碼執行的記憶體界線 • 透過呼叫 CreateProcess 或 CreateProcessAsUser API 由作業系統來配置 • Processes 不執行程式碼 • 包含至少一個 thread • 在 Process 中獨立的指令執行序列

  36. “Process Hangs” 的理論 • Thread 對應用程式造成的影響 • 同步執行能力(虛擬)與 Thread 數量有關 • 真正的同步執行能力與執行單位數量有關 • 1 processor = 一個或多個執行單位 • 常見的 IIS thread pools • ATQ thread pool • ASP thread pool • ASP.NET thread pool

  37. “Process Hangs” 的理論 • 當實作自訂 thread pools 時建議使用ISAPI 延伸 • ATQ thread pool 是敏感且高執行效率的 • 如在 ATQ Thread 中執行長時間作業會導致會嚴重的影響 IIS 效能 • ISAPIs 通常執行時間較長,通常使用自訂的thread pool 來分散 ATQ Thread 的工作量

  38. 失控的 Threads • 失控的 thread 是指陷入無窮迴圈的 thread • 執行消耗大量 CPU 的工作 • 可能是設計要求或是邏輯錯誤 • 失控的 thread 會讓其他 thread 無法使用 CPU 資源 • 通常受到影響的是正常的 threads • 造成伺服器的效能降低

  39. 什麼是 Blocked Thread • 沒有使用任何 CPU 資源的 thread • 等待資料庫呼叫傳回 • 等待 Web Service 呼叫傳回 • 等待 Socket/網路呼叫傳回 • 等待被鎖定的資源 Thread 1 Thread 2 Thread 3 Thread 4

  40. Locks 與 Deadlocks • 什麼是 lock? • 一個同步機制來保護資源不會因為多個 threads 同時存取而導致資料毀損 • 為什麼開發人員要使用locks? • 保護資料 • 保護其他不在記憶體內的資源 • 不良的使用 locks 將影響應用程式 • 造成 blocked threads • 使用多重 locks 在應用程式中可能會造成 deadlock • 當沒有 thread 可用時會造成 Process hangs

  41. 什麼是 Leaks… • 什麼是 leak? • Leaks 種類

  42. Leak 情境 • 為什麼找出與解決 leaks 是非常困難? • 伺服器應用程式常常會將記憶體配置存入 Cache • 應用程式通常是長期執行 • 這些應用程式對外人來說看起來就像是記憶體 leaks • 還有許多其他應用程式快取 • 使用效能監視器靠到記憶體使用不斷成長並不等於是記憶體 leak

  43. Leak 情境 • 什麼是短期的記憶體配置? • 使用大量記憶體的應用程式會造成暫時的記憶體使用尖峰但會在使用後釋放 (不會長時間佔用) 這也不是記憶體 leaks

  44. Leak 情境 • 快取與 memory leaks 的差異? • Memory leaks 是由於不斷的取用記憶體所導致 • 快取記憶體使用情況通常是快速成長,但在應用程式穩定後就不在增加

  45. DebugDiag 的延展性 • 延展性介紹 • DebugDiag 架構與物件模型 • DebugDiag 中的 Script • DebugDiag 中的 Extensions • 自訂與延伸 DebugDiag

  46. DebugDiag 的延展性 • DebugDiag 有兩種延展方式: • 資料收集 • 分析方式 • 資料收集延展性 • 控制 scripts • 兩種用來當作 event handler 的控制 scripts

  47. DebugDiag 的延展性 • DebugDiag 使用規則來產生 scripts • Scripts 可以被修改並延伸 • 所有的控制 scripts 使用 VBScript 撰寫A • Scripts 非常容易的與相容 COM 元件進行呼叫與介接

  48. DebugDiag 的延展性 • 分析 scripts • 使用類似 “ASP+HTML” 的撰寫方式 • 不會被 ASP.dll 處理並且沒有 ASP 的內建物件等功能 • Scripts 可以照環境進行修改與客制化動作 • 分析 Script 的基本物件模型 • 基本物件模型可以被 script 來使用 • 整個物件模型都可以克制化

  49. DebugDiag 的延展性 • DebugDiag 包含了IIS-相關的延伸 • 這個 extension 是使用 SDK 來開發 • 這個 IIS 相關的延伸提供了用 DebugDiag 除錯 IIS 應用程式所需要的相關資訊

  50. 總結 • 要除錯上線的 Web 應用程式而不造成停止服務是非常有挑戰性的 • Web 應用程式結合了來自微軟、自行開發與其他開發商的元件,讓找出 crash, hang, leak 的根本原因是非常困難的 • Crashes 造成 processes 因為未處理的 exception 而結束 • Hangs 是由 race conditions, lock contention, network blocking, database blocking, infinite loops and deadlocks 所造成 • Leaks 是由無法正常釋放用來進行短期作業與快取的記憶體所造成 • Debug Diagnostics 有可延伸的模式來成功的擷取並分析常見的除錯情境並找出根本原因

More Related