ASP.NET Stability
-
Upload
brady-white -
Category
Documents
-
view
38 -
download
0
description
Transcript of 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
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
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
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
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
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.
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
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
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
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
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
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
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
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)
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
FXCop DemoFXCop Demo
http://http://www.gotdotnet.com/team/fxcopwww.gotdotnet.com/team/fxcop//
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*
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
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
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)
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
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
ACT DemoACT Demo
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
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
Memory ProblemsMemory Problems
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
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
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
Questions?Questions?
[email protected]@charter.net