1 / 30

ASP.NET Stability

ASP.NET Stability. St. Louis .NET Users Group April 25, 2005 Preston Page. What’s Great About .NET. Advanced Language Options Extensive Framework for Windows, Web and Device Programming Greatly Improved Productivity Enhanced Performance Simplified Deployment Best Stability Yet.

brady-white
Download Presentation

ASP.NET Stability

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. ASP.NET Stability St. Louis .NET Users Group April 25, 2005 Preston Page

  2. What’s Great About .NET • Advanced Language Options • Extensive Framework for Windows, Web and Device Programming • Greatly Improved Productivity • Enhanced Performance • Simplified Deployment • Best Stability Yet

  3. When Stability Fails… • End User Experience Suffers • Poor First Impression • Lost Credibility • Lost Opportunity • Lost Revenue • Increased Support Costs • Increased Operations Costs • Panic Mode, Escalations • Costly Rewrite

  4. Six Stability Threats • Improperly Structured Error Handling • “Hidden” Memory Leaks • Non-Compliance with Coding Standards • Poor Performance • Database Issues • Inadequate Testing

  5. Improper Error Handling • 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

  6. 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.

  7. MSDN Help Sample Function GetStrings (ByVal FileName As String) As Collection Dim Strings As New Collection Dim Stream As System.IO.StreamReader Stream = System.IO.File.OpenText(FileName) Try While True Strings.Add(Stream.ReadLine()) End While Catch eos As System.IO.EndOfStreamException ' No action is necessary; end of stream Catch IOExcep As System.IO.IOException ‘ Unexpected IO Error Strings = Nothing ' Caller must test Null Finally Stream.Close End Try Return Strings End Function

  8. Subtle Problems… Function GetStrings (ByVal FileName As String) As Collection Dim Strings As New Collection Dim Stream As System.IO.StreamReader Stream = System.IO.File.OpenText(FileName) (1) ‘ Scope Try While True (2) ‘ Deliberate Infinite Loop Strings.Add(Stream.ReadLine()) End While Catch eos As System.IO.EndOfStreamException (3) ‘ Empty ' No action is necessary; end of stream Catch IOExcep As System.IO.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

  9. Improvements Function GetStrings(ByVal FileName As String) As Collection Dim Strings As New Collection Dim Stream As System.IO.StreamReader Try Stream = System.IO.File.OpenText(FileName) (1) Do While Stream.Peek() >= 0 (2) Strings.Add(Stream.ReadLine()) Loop Catch e As System.Exception (3) LogException(e) Strings = Nothing ' Caller must test Null Finally (4) Stream.Close() GetStrings = Strings (5) Stream = Nothing Strings = Nothing End Try End Function

  10. Hidden Memory Leaks • Do Not Immediately Cause Errors • Usually Pass Code Scans/Reviews • Many Are Not Well Documented • Luckily, Existence Can Be Determined by Load Testing

  11. Ten Ways To Leak Memory • Improper Structured Error Handling • Implicit ADO/ADO.NET Connections Never Close Under Load • Failure to call Server.Clear when trapping errors in Application_OnError causes a memory leak and WP resets

  12. Ten Ways To Leak Memory • Calling a delegate function with BeginInvoke() without calling a matching EndInvoke() • Failure to Set Objects to Null Or Nothing • Passing or setting an open ADO Connection object to a Property

  13. Ten Ways To Leak Memory • 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

  14. Ten Ways To Leak Memory • Failure to Properly Dispose of COM Interop and .NET COM Wrapper Objects Like: System.EnterpriseServices (COM+) System.DirectoryServices (ADSI)

  15. Coding Standards Compliance • 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

  16. FXCop Demo http://www.gotdotnet.com/team/fxcop/

  17. FXCop Stability Rules* • Library design* • Localization • Interoperability* • Mobility • Portability • Naming conventions • Performance* • Security* • Usage*

  18. Performance Problems • Cause Error Conditions Under Load • Reduce Scalability • Increase Hosting Costs • Increase Support Costs • Poor End User Experience • Catch With Load/Stress Tests

  19. Common Database Issues • Structure Problems • Tuning “Opportunities” • Inefficient Data Access Code • Coding Standards Non-Compliance • Failure To Use Caching Options • Inadequate Maintenance • Catch With Load/Stress Tests

  20. Test Methodology • 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, LoadRunner) • Stress Test (ACT, LoadRunner)

  21. Formal Load Tests • 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

  22. Desktop Load Testing • 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

  23. ACT Demo

  24. Can Determine Load Induced Error Memory Leaks Poor Performance Database Issues End User Experience Other Server Impact Cannot Determine Missing Structured Error Handling Adherence to Coding Standards Application Architecture Functional Issues Application Center Test

  25. Load Test Pass/Fail Criteria

  26. Memory Problems

  27. Machine.Config Tuning • Reduce idleTimeout from “Infinite” • Adjust responseDeadlockInterval for long running applications • Use <location/> Node To Enforce Best Practices and Control DEV, QC and PROD Settings

  28. Machine.Config Threading

  29. More Information • MSDN.Microsoft.com • Knowledge Base Articles • Patterns & Practices • www.ASP.NET • Starter Kits • Tools • www.Gotdotnet.com • FXCop • Help & Samples • Bibliography as Web Links • Send email to Preston

  30. Questions? prestonpage@charter.net

More Related