ASP NET Stability St Louis NET Users Group
ASP. NET Stability St. Louis. NET Users Group April 25, 2005 Preston Page
What’s Great About. NET n n n Advanced Language Options Extensive Framework for Windows, Web and Device Programming Greatly Improved Productivity Enhanced Performance Simplified Deployment Best Stability Yet
When Stability Fails… n n n n n End User Experience Suffers Poor First Impression Lost Credibility Lost Opportunity Lost Revenue Increased Support Costs Increased Operations Costs Panic Mode, Escalations Costly Rewrite
Six Stability Threats 1. 2. 3. 4. 5. 6. Improperly Structured Error Handling “Hidden” Memory Leaks Non-Compliance with Coding Standards Poor Performance Database Issues Inadequate Testing
Improper Error Handling n n n n n Cause of 80 – 90 % of Stability Problems Missing Altogether? Empty Catch Statement Too Much Faith in Garbage Collection No Finally Statement Objects Out of Scope for Finally Inadequate Object Cleanup Missing Logging/Alerting Recursion from Catch Statement Style Problems
Anatomy of Try…Catch Try ' Starts a structured exception handler. ' Place executable statements that may generate ' an exception in this block. Catch [optional filters] ' This code runs if the statements listed in ' the Try block fail and the filter on the Catch ' statement is true. [Additional Catch blocks] Finally ' This code always runs immediately before ' the Try statement exits. End Try ' Ends a structured exception handler.
MSDN Help Sample Function Get. Strings (By. Val File. Name As String) As Collection Dim Strings As New Collection Dim Stream As System. IO. Stream. Reader Stream = System. IO. File. Open. Text(File. Name) Try While True Strings. Add(Stream. Read. Line()) End While Catch eos As System. IO. End. Of. Stream. Exception ' No action is necessary; end of stream Catch IOExcep As System. IOException ‘ Unexpected IO Error Strings = Nothing ' Caller must test Null Finally Stream. Close End Try Return Strings End Function
Subtle Problems… Function Get. Strings (By. Val File. Name As String) As Collection Dim Strings As New Collection Dim Stream As System. IO. Stream. Reader Stream = System. IO. File. Open. Text(File. Name) (1) ‘ Scope Try While True (2) ‘ Deliberate Infinite Loop Strings. Add(Stream. Read. Line()) End While Catch eos As System. IO. End. Of. Stream. Exception (3) ‘ Empty ' No action is necessary; end of stream Catch IOExcep As System. IOException ‘ Unexpected IO Error Strings = Nothing ' Caller must test Null Finally (4) Stream. Close End Try Return Strings (5) ‘ May Not Be Called End Function
Improvements Function Get. Strings(By. Val File. Name As String) As Collection Dim Strings As New Collection Dim Stream As System. IO. Stream. Reader Try Stream = System. IO. File. Open. Text(File. Name) (1) Do While Stream. Peek() >= 0 (2) Strings. Add(Stream. Read. Line()) Loop Catch e As System. Exception (3) Log. Exception(e) Strings = Nothing ' Caller must test Null Finally (4) Stream. Close() Get. Strings = Strings (5) Stream = Nothing Strings = Nothing End Try End Function
Hidden Memory Leaks n n Do Not Immediately Cause Errors Usually Pass Code Scans/Reviews Many Are Not Well Documented Luckily, Existence Can Be Determined by Load Testing
Ten Ways To Leak Memory 1. 2. 3. Improper Structured Error Handling Implicit ADO/ADO. NET Connections Never Close Under Load Failure to call Server. Clear when trapping errors in Application_On. Error causes a memory leak and WP resets
Ten Ways To Leak Memory 4. 5. 6. Calling a delegate function with Begin. Invoke() without calling a matching End. Invoke() Failure to Set Objects to Null Or Nothing Passing or setting an open ADO Connection object to a Property
Ten Ways To Leak Memory 7. 8. 9. Use of Response. Redirect in a Catch Statement leaves threads open, severely limits performance Calling Transactional COM+ Components from ASP. NET Failure to Close Database or Stream Objects
Ten Ways To Leak Memory 10. Failure to Properly Dispose of COM Interop and. NET COM Wrapper Objects Like: System. Enterprise. Services (COM+) System. Directory. Services (ADSI)
Coding Standards Compliance n n n Standards Embody Time Tested Best Practices To Keep You Out Of Trouble Compliance Reduces Support and Maintenance Costs Avoid Common Structural Defects Use FXCop To Scan Code Adapt Rules To Particular Needs
FXCop Demo http: //www. gotdotnet. com/team/fxcop/
FXCop Stability Rules* n n n n n Library design* Localization Interoperability* Mobility Portability Naming conventions Performance* Security* Usage*
Performance Problems n n n Cause Error Conditions Under Load Reduce Scalability Increase Hosting Costs Increase Support Costs Poor End User Experience Catch With Load/Stress Tests
Common Database Issues n n n n Structure Problems Tuning “Opportunities” Inefficient Data Access Code Coding Standards Non-Compliance Failure To Use Caching Options Inadequate Maintenance Catch With Load/Stress Tests
Test Methodology n n n n Test Driven Development (NUnit) Regular Code/Design Review (XP) Unit Testing (NUnit, custom harness) Functional Tests (formal plan) User Acceptance Tests Integration Tests (QC Servers) Load Test (ACT, Load. Runner) Stress Test (ACT, Load. Runner)
Formal Load Tests n n n Performed On Calibrated, Production Class Servers Used To Judge Impact To Shared Web Environments Use To Gate Deployment To Protect Infrastructure From Performance And Stability Problems Usually Requires Operations Involvement, Special Infrastructure Also Helps Uncover Configuration And Infrastructure Issues
Desktop Load Testing n n Baseline Performance To Gauge Effectiveness Of Changes Uncover Performance and Stability Issues As Early As Possible Uncover Costly Design Flaws Early Cheap And Easy Insurance
ACT Demo
Application Center Test Can Determine n Load Induced Error n Memory Leaks n Poor Performance n Database Issues n End User Experience n Other Server Impact Cannot Determine n Missing Structured Error Handling n Adherence to Coding Standards n Application Architecture n Functional Issues
Load Test Pass/Fail Criteria Metric Goal RPS/% CPU 50 RPS / 70% CPU % Committed Bytes < 22% Residual Memory < 10 MB Total Socket Errors 0 Total HTTP Errors 0 Time Outs 0 WP Restarts 0 Memory Slope ~0
Memory Problems
Machine. Config Tuning n n n Reduce idle. Timeout from “Infinite” Adjust response. Deadlock. Interval for long running applications Use <location/> Node To Enforce Best Practices and Control DEV, QC and PROD Settings
Machine. Config Threading Configuration setting Default Recommendation maxconnection 2 12 * #CPUs max. Io. Threads 20 100 max. Worker. Threads 20 100 min. Free. Threads 8 88 * #CPUs min. Local. Request. Free 4 Threads 76 * #CPUs
More Information n MSDN. Microsoft. com • Knowledge Base Articles • Patterns & Practices n www. ASP. NET • Starter Kits • Tools n www. Gotdotnet. com • FXCop • Help & Samples n Bibliography as Web Links • Send email to Preston
Questions? prestonpage@charter. net
- Slides: 30