ASP.NET Stability

30
ASP.NET Stability ASP.NET Stability St. Louis .NET Users St. Louis .NET Users Group Group April 25, 2005 April 25, 2005 Preston Page Preston Page

description

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. - PowerPoint PPT Presentation

Transcript of ASP.NET Stability

Page 1: ASP.NET Stability

ASP.NET StabilityASP.NET Stability

St. Louis .NET Users GroupSt. Louis .NET Users Group

April 25, 2005April 25, 2005

Preston PagePreston Page

Page 2: ASP.NET Stability

What’s Great About .NETWhat’s Great About .NET

Advanced Language OptionsAdvanced Language Options Extensive Framework for Windows, Extensive Framework for Windows,

Web and Device ProgrammingWeb and Device Programming Greatly Improved ProductivityGreatly Improved Productivity Enhanced PerformanceEnhanced Performance Simplified DeploymentSimplified Deployment Best Stability YetBest Stability Yet

Page 3: ASP.NET Stability

When Stability Fails…When Stability Fails…

End User Experience SuffersEnd User Experience Suffers Poor First Impression Poor First Impression Lost CredibilityLost Credibility Lost OpportunityLost Opportunity Lost Revenue Lost Revenue Increased Support CostsIncreased Support Costs Increased Operations CostsIncreased Operations Costs Panic Mode, EscalationsPanic Mode, Escalations Costly RewriteCostly Rewrite

Page 4: ASP.NET Stability

Six Stability ThreatsSix Stability Threats

1.1. Improperly Structured Error Improperly Structured Error HandlingHandling

2.2. ““Hidden” Memory LeaksHidden” Memory Leaks

3.3. Non-Compliance with Coding Non-Compliance with Coding StandardsStandards

4.4. Poor PerformancePoor Performance

5.5. Database IssuesDatabase Issues

6.6. Inadequate TestingInadequate Testing

Page 5: ASP.NET Stability

Improper Error HandlingImproper Error Handling

Cause of 80 – 90 % of Stability ProblemsCause of 80 – 90 % of Stability Problems Missing Altogether?Missing Altogether? Empty Catch StatementEmpty Catch Statement Too Much Faith in Garbage CollectionToo Much Faith in Garbage Collection No Finally StatementNo Finally Statement Objects Out of Scope for FinallyObjects Out of Scope for Finally Inadequate Object CleanupInadequate Object Cleanup Missing Logging/AlertingMissing Logging/Alerting Recursion from Catch StatementRecursion from Catch Statement Style ProblemsStyle Problems

Page 6: ASP.NET Stability

Anatomy of Try…CatchAnatomy of Try…CatchTry ' 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.

Page 7: ASP.NET Stability

MSDN Help SampleMSDN Help SampleFunction 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

Page 8: ASP.NET Stability

Subtle Problems…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 CalledEnd Function

Page 9: ASP.NET Stability

ImprovementsImprovementsFunction GetStrings(ByVal FileName As String) As CollectionDim Strings As New CollectionDim 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 TryEnd Function

Page 10: ASP.NET Stability

Hidden Memory LeaksHidden Memory Leaks

Do Not Immediately Cause ErrorsDo Not Immediately Cause Errors Usually Pass Code Scans/ReviewsUsually Pass Code Scans/Reviews Many Are Not Well DocumentedMany Are Not Well Documented Luckily, Existence Can Be Luckily, Existence Can Be

Determined by Load TestingDetermined by Load Testing

Page 11: ASP.NET Stability

Ten Ways To Leak MemoryTen Ways To Leak Memory

1.1. Improper Structured Error HandlingImproper Structured Error Handling

2.2. Implicit ADO/ADO.NET Connections Implicit ADO/ADO.NET Connections Never Close Under Load Never Close Under Load

3.3. Failure to call Server.Clear when Failure to call Server.Clear when trapping errors in trapping errors in Application_OnError causes a Application_OnError causes a memory leak and WP resetsmemory leak and WP resets

Page 12: ASP.NET Stability

Ten Ways To Leak MemoryTen Ways To Leak Memory

4.4. Calling a delegate function with Calling a delegate function with BeginInvoke() without calling a BeginInvoke() without calling a matching EndInvoke()matching EndInvoke()

5.5. Failure to Set Objects to Null Or Failure to Set Objects to Null Or NothingNothing

6.6. Passing or setting an open ADO Passing or setting an open ADO Connection object to a Property Connection object to a Property

Page 13: ASP.NET Stability

Ten Ways To Leak MemoryTen Ways To Leak Memory

7.7. Use of Response.Redirect in a Catch Use of Response.Redirect in a Catch Statement leaves threads open, Statement leaves threads open, severely limits performanceseverely limits performance

8.8. Calling Transactional COM+ Calling Transactional COM+ Components from ASP.NETComponents from ASP.NET

9.9. Failure to Close Database or Stream Failure to Close Database or Stream ObjectsObjects

Page 14: ASP.NET Stability

Ten Ways To Leak MemoryTen Ways To Leak Memory

10.10. Failure to Properly Dispose of COM Failure to Properly Dispose of COM Interop and .NET COM Wrapper Interop and .NET COM Wrapper Objects Like: Objects Like: System.EnterpriseServices (COM+) System.EnterpriseServices (COM+) System.DirectoryServices (ADSI)System.DirectoryServices (ADSI)

Page 15: ASP.NET Stability

Coding Standards ComplianceCoding Standards Compliance

Standards Embody Time Tested Best Standards Embody Time Tested Best Practices To Keep You Out Of TroublePractices To Keep You Out Of Trouble

Compliance Reduces Support and Compliance Reduces Support and Maintenance CostsMaintenance Costs

Avoid Common Structural DefectsAvoid Common Structural Defects Use FXCop To Scan CodeUse FXCop To Scan Code Adapt Rules To Particular NeedsAdapt Rules To Particular Needs

Page 16: ASP.NET Stability

FXCop DemoFXCop Demo

http://http://www.gotdotnet.com/team/fxcopwww.gotdotnet.com/team/fxcop//

Page 17: ASP.NET Stability

FXCop Stability Rules*FXCop Stability Rules*

Library design* Library design* Localization Localization Interoperability*Interoperability* MobilityMobility PortabilityPortability Naming conventions Naming conventions Performance* Performance* Security* Security* Usage* Usage*

Page 18: ASP.NET Stability

Performance ProblemsPerformance Problems

Cause Error Conditions Under LoadCause Error Conditions Under Load Reduce ScalabilityReduce Scalability Increase Hosting CostsIncrease Hosting Costs Increase Support CostsIncrease Support Costs Poor End User ExperiencePoor End User Experience Catch With Load/Stress TestsCatch With Load/Stress Tests

Page 19: ASP.NET Stability

Common Database IssuesCommon Database Issues

Structure ProblemsStructure Problems Tuning “Opportunities”Tuning “Opportunities” Inefficient Data Access CodeInefficient Data Access Code Coding Standards Non-ComplianceCoding Standards Non-Compliance Failure To Use Caching OptionsFailure To Use Caching Options Inadequate MaintenanceInadequate Maintenance Catch With Load/Stress TestsCatch With Load/Stress Tests

Page 20: ASP.NET Stability

Test MethodologyTest Methodology

Test Driven Development (NUnit)Test Driven Development (NUnit) Regular Code/Design Review (XP)Regular Code/Design Review (XP) Unit Testing (NUnit, custom harness)Unit Testing (NUnit, custom harness) Functional Tests (formal plan)Functional Tests (formal plan) User Acceptance Tests User Acceptance Tests Integration Tests (QC Servers)Integration Tests (QC Servers) Load Test (ACT, LoadRunner)Load Test (ACT, LoadRunner) Stress Test (ACT, LoadRunner)Stress Test (ACT, LoadRunner)

Page 21: ASP.NET Stability

Formal Load TestsFormal Load Tests Performed On Calibrated, Production Performed On Calibrated, Production

Class ServersClass Servers Used To Judge Impact To Shared Web Used To Judge Impact To Shared Web

EnvironmentsEnvironments Use To Gate Deployment To Protect Use To Gate Deployment To Protect

Infrastructure From Performance And Infrastructure From Performance And Stability ProblemsStability Problems

Usually Requires Operations Usually Requires Operations Involvement, Special InfrastructureInvolvement, Special Infrastructure

Also Helps Uncover Configuration Also Helps Uncover Configuration And Infrastructure IssuesAnd Infrastructure Issues

Page 22: ASP.NET Stability

Desktop Load TestingDesktop Load Testing

Baseline Performance To Gauge Baseline Performance To Gauge Effectiveness Of ChangesEffectiveness Of Changes

Uncover Performance and Stability Uncover Performance and Stability Issues As Early As PossibleIssues As Early As Possible

Uncover Costly Design Flaws EarlyUncover Costly Design Flaws Early Cheap And Easy InsuranceCheap And Easy Insurance

Page 23: ASP.NET Stability

ACT DemoACT Demo

Page 24: ASP.NET Stability

Application Center TestApplication Center Test

Can DetermineCan Determine Load Induced ErrorLoad Induced Error Memory LeaksMemory Leaks Poor PerformancePoor Performance Database IssuesDatabase Issues End User End User

ExperienceExperience Other Server Other Server

Impact Impact

Cannot DetermineCannot Determine Missing Structured Missing Structured

Error HandlingError Handling Adherence to Adherence to

Coding StandardsCoding Standards Application Application

ArchitectureArchitecture Functional Issues Functional Issues

Page 25: ASP.NET Stability

Load Test Pass/Fail CriteriaLoad Test Pass/Fail CriteriaMetricMetric GoalGoal

RPS/% CPURPS/% CPU 50 RPS / 70% CPU50 RPS / 70% CPU

% Committed Bytes% Committed Bytes < 22%< 22%

Residual MemoryResidual Memory < 10 MB< 10 MB

Total Socket ErrorsTotal Socket Errors 00

Total HTTP ErrorsTotal HTTP Errors 00

Time OutsTime Outs 00

WP RestartsWP Restarts 00

Memory SlopeMemory Slope ~ 0~ 0

Page 26: ASP.NET Stability

Memory ProblemsMemory Problems

Page 27: ASP.NET Stability

Machine.Config TuningMachine.Config Tuning

Reduce idleTimeout from “Infinite”Reduce idleTimeout from “Infinite” Adjust responseDeadlockInterval for Adjust responseDeadlockInterval for

long running applicationslong running applications Use <location/> Node To Enforce Use <location/> Node To Enforce

Best Practices and Control DEV, QC Best Practices and Control DEV, QC and PROD Settingsand PROD Settings

Page 28: ASP.NET Stability

Machine.Config ThreadingMachine.Config Threading

Configuration setting Default Recommendation

maxconnection 2 12 * #CPUs

maxIoThreads 20 100

maxWorkerThreads 20 100

minFreeThreads 8 88 * #CPUs

minLocalRequestFreeThreads

4 76 * #CPUs

Page 29: ASP.NET Stability

More InformationMore Information MSDN.Microsoft.comMSDN.Microsoft.com

• Knowledge Base ArticlesKnowledge Base Articles• Patterns & PracticesPatterns & Practices

www.ASP.NETwww.ASP.NET• Starter KitsStarter Kits• ToolsTools

www.Gotdotnet.comwww.Gotdotnet.com• FXCopFXCop• Help & SamplesHelp & Samples

Bibliography as Web LinksBibliography as Web Links• Send email to PrestonSend email to Preston

Page 30: ASP.NET Stability

Questions?Questions?

[email protected]@charter.net