66
提提提提提提提提提 提提提提提提提提提 Improving Performance and Improving Performance and Scalability Scalability Microsoft .NET 技技技技 技技技

提昇應用程式的效能 Improving Performance and Scalability

Embed Size (px)

DESCRIPTION

提昇應用程式的效能 Improving Performance and Scalability. Microsoft .NET 技術代言人 林耀珍. 林耀珍. 經歷 第三波資訊 技術總監 育碁數位科技 總經理 專業認證與專長 微軟 .NET 技術 軟體開發流程,資訊系統規劃 Microsoft MCSD/MCSE/MCDBA 物件導向技術, Rational OOAD 認證講師 Lotus Notes principle CLP/CLI J2EE. 目標與對象. 對象 技術平台的決策人員 軟體建構師 系統分析師 專案經理 應用程式開發人員 - PowerPoint PPT Presentation

Citation preview

提昇應用程式的效能提昇應用程式的效能Improving Performance and ScalabilityImproving Performance and Scalability

Microsoft .NET 技術代言人林耀珍

.NET技術代言人 林耀珍 2004/03/24 2

林耀珍林耀珍經歷第三波資訊 技術總監育碁數位科技 總經理專業認證與專長微軟 .NET 技術軟體開發流程,資訊系統規劃Microsoft MCSD/MCSE/MCDBA物件導向技術, Rational OOAD 認證講師Lotus Notes principle CLP/CLIJ2EE

.NET技術代言人 林耀珍 2004/03/24 3

目標與對象目標與對象對象技術平台的決策人員軟體建構師系統分析師專案經理應用程式開發人員目標開發高效能的應用程式

.NET技術代言人 林耀珍 2004/03/24 4

AgendaAgenda

OverviewFramework for improving PerformancePerformance ModelingTesting ProcessDesign GuidelinesImproving ASP.NET Performance

.NET技術代言人 林耀珍 2004/03/24 5

Performance Categories Performance Categories

Speed Does the application respond quickly enough for the intended users?

Scalability Will the application handle the expected user load and beyond?

Stability Is the application stable under expected and unexpected user loads?

.NET技術代言人 林耀珍 2004/03/24 6

Tough ChallengesTough ChallengesSimple -> High Performance

Monolithic program runs on a huge machine

Life is not so simpleMore demandsSecurity issuesInternet makes things more complexScalable to support more users

Less resources / time / manpower to do these works

Architectures & Components & Designs are used to increase developers’ productivities, but add challenges for us to build high performance system.

.NET技術代言人 林耀珍 2004/03/24 7

Common Pitfall - Optimize LaterCommon Pitfall - Optimize Later

Performance is typically ignored until there is a problem. There are several problems with this approach:

Performance problems are often introduced early in the design Design issues can’t always be fixed through tuning or more efficient codingFixing an architecture or design issue later in the cycle is inefficient and often very expensive.

.NET技術代言人 林耀珍 2004/03/24 8

Common Pitfall - Common Pitfall - Make it perfect earlyMake it perfect early

Developers work on optimizing everything up front. This results in:

“Gold Plated” codeHighly optimized code that is rarely executedMissed schedules

.NET技術代言人 林耀珍 2004/03/24 9

Need a better wayNeed a better way

Defining performance targetsMeasuring performanceTroubleshooting performance problems

80/20 Rule: 80% of performance problems are caused by 20% of the issues

Tune systemRegularly monitor performance trendsArchitecting systems that have the right balance of security, performance, manageability and scalability

.NET技術代言人 林耀珍 2004/03/24 10

Framework for improving Framework for improving PerformancePerformance

.NET技術代言人 林耀珍 2004/03/24 11

#1 Principle#1 Principle

Hardware Tuning

Product Tuning

Code Tuning

Design

Requirements

Greater Impact

Less I

mpact

.NET技術代言人 林耀珍 2004/03/24 12

Plan & Design with Perf & ScalePlan & Design with Perf & Scale

Common issues

.NET技術代言人 林耀珍 2004/03/24 13

Development LifecycleDevelopment Lifecycle

.NET技術代言人 林耀珍 2004/03/24 14

Measure, don’t PredictMeasure, don’t PredictGet Familiar with MetricsSet SMART Goals

"run fast" vs. 25 transactions per second“load quickly“ vs. "3 second response time"

Get Familiar with Test typesGet Familiar with Tools

Metric Definition Measured By Impacts

Throughput How Many? # Request/Sec App / Server

Response Time How Fast? TTFB or TTLB Customer Sat

Resource Util. How Much? % of resource Upgrade/Add

.NET技術代言人 林耀珍 2004/03/24 15

Tune IterativelyTune Iteratively

Test, Collect, Analyze and Fix

Collecting

Testing

Analyzing

FixingPre-Requisites

.NET技術代言人 林耀珍 2004/03/24 16

Equip with Tools & Skills

Custom-Made Testing programMicrosoft Application Center TestProfessional Performance & Scalability ToolsSystem Monitor: Counters; Understand thresholds CLRProfiler: Allocations; Survivors; LeakingWINDBG: Dumps; Hangs, Crashes, Blocks, Memory, etcVADUMP: Working set; Memory, etc NETMON: Data on Wire; Bandwidth and Latency

… And Good Team Members

.NET技術代言人 林耀珍 2004/03/24 17

Framework Framework

.NET技術代言人 林耀珍 2004/03/24 18

Performance Modeling Approach Performance Modeling Approach

Structured approach to modeling the performance of your applicationGoal: Focus efforts where they matter the mostBenefits:

Performance becomes part of your designEvaluate trade-offs before you build the solutionAvoid performance surprises in productionDocument itemized scenarios

what to test where to instrument …

.NET技術代言人 林耀珍 2004/03/24 19

Performance ModelingPerformance Modeling

Two parts of Performance modelAn information structure

Performance objectivesBudgetsWorkloadsItemized scenarios with goalsTest cases with goals

A process

.NET技術代言人 林耀珍 2004/03/24 20

Information Category in the Information Category in the performance model performance model

Application DescriptionScenariosPerformance ObjectivesBudgetsMeasurementsWorkload GoalsBaseline HardwareQuality of Service Requirements

security, maintainability, and interoperability Workload Requirements

Total # of users, concurrent users, data volumes, expected usages

.NET技術代言人 林耀珍 2004/03/24 21

Performance Modeling ProcessPerformance Modeling Process

1. Identify Use Cases2. Identify workload3. Identify Performance Objectives4. Identify Budget5. Identify Steps of User Activities6. Allocate Budget7. Evaluate8. Validate

.NET技術代言人 林耀珍 2004/03/24 22

1. Identify Use Cases1. Identify Use Cases

Critical use casesUse cases with performance expectations or requirements, such as service level agreements

Submit an order Process a message

Significant use casesUse cases that represent the majority of interaction or activity

Search for products Browse catalog

.NET技術代言人 林耀珍 2004/03/24 23

2. Identify workload2. Identify workload

Total usersConcurrently active usersData volumesTransaction volumes and transaction mix

Ex:100 concurrent users browsing10 concurrent users placing orders

.NET技術代言人 林耀珍 2004/03/24 24

3. Identify Performance Objectives3. Identify Performance Objectives

Response timeTime to first byte no longer than 3 seconds, time to last byte no longer than 7 seconds

Throughput 10 million read requests/sec 10K write requests/sec 100 transactions per second

Resource utilization 80% CPU T1 Network

.NET技術代言人 林耀珍 2004/03/24 25

Speed Requirements Speed Requirements

normal pages — typical to fast reports — under a minute exception activities (list) — fast to very fast query execution — under 30 seconds nightly backup batch process — under an hour

Activity type Requirement GoalNormal pages 5 sec 3 sec

Reports 60 sec 30 sec

Exception activities (listed elsewhere) 3 sec 2 sec

Query execution 30 sec 15 sec

Nightly backup 1 hour 45 min

.NET技術代言人 林耀珍 2004/03/24 26

Scalability Requirements Scalability Requirements

peak expected hourly usage — 500 users peak expected sustained usage — 300 users maximum percentage of users expected to execute reports in any one hour — 75% maximum percentage of users expected to execute queries in any one hour — 75% maximum number of rows to be replicated during nightly backup — 150,000

.NET技術代言人 林耀珍 2004/03/24 27

4. Identify Budget 4. Identify Budget

Cost (manpower, tool, time, …)Execution timeResource utilization – how much you can use

Network: Bandwidth.Hardware: Servers, memory, CPUs …

etc.Resource dependencies: Number of

available database connections, Web service connections, … etc.

.NET技術代言人 林耀珍 2004/03/24 28

5. Identify Steps of User Activities5. Identify Steps of User Activities

Users have different activities and steps.

Steps of User Activity1. Order submitted by client2. Client authentication token is validated3. Order input is validated4. Business rules validate order5. Order is sent to database server6. Order is processed7. Response is sent to the client

.NET技術代言人 林耀珍 2004/03/24 29

6. Allocate Budget 6. Allocate Budget

Assigning Execution Time Assigning Resources

.NET技術代言人 林耀珍 2004/03/24 30

7. Evaluate7. EvaluateDoes the budget meet the objectives? Is the budget realistic? Does the model identify a resource hotspot?Are there more efficient alternatives? Can the design or features be reduced or modified to meet the objectives? Can you improve efficiency in terms of resource consumption or time? Would an alternative pattern, design, or deployment topology provide a better solution? What are you trading off?

productivity, scalability, maintainability or security

.NET技術代言人 林耀珍 2004/03/24 31

8. Validate 8. Validate

Continue to create prototypes and measure the performance of the use cases by capturing metrics.

.NET技術代言人 林耀珍 2004/03/24 32

Testing Process Testing Process

.NET技術代言人 林耀珍 2004/03/24 33

Load Testing Process Load Testing Process

1. Identify key scenarios 2. Identify workload 3. Identify metrics 4. Create test cases 5. Process test 6. Analyze the results7. Report

.NET技術代言人 林耀珍 2004/03/24 34

Identify Key Scenarios Identify Key Scenarios

Log on to the application.Browse a product catalog.Search for a specific product.Add items to the shopping cart.Validate credit card details and place an order.

.NET技術代言人 林耀珍 2004/03/24 35

Identify Workload Identify Workload

Numbers of usersThe total number of concurrent users accessing the application in a given time frame

Rate of requests Patterns of requests

.NET技術代言人 林耀珍 2004/03/24 36

Identify Metrics Identify Metrics

Network specific metrics System related metrics Platform specific metrics Application specific metrics Service level metrics

System Metric Accepted level

% CPU Usage Must not exceed 60%

Requests / second 100 or more

Response time < 2 seconds

Service Level Metric

Value

Orders per second 70

Unique browses per second

130

.NET技術代言人 林耀珍 2004/03/24 37

Create Test Cases Create Test Cases

Sample E-Commerce Application Expected Results under the load profile below

Throughput: 100 Requests/secRequests Executing: 45 Requests executingResponse Time: 2.5 sec Response time Resource utilization thresholds:Processor\% Processor Time: 75 %Memory\ Available MBytes: 25 % of total physical RAM

User scenarios Percentage of users UsersBrowse 50 250

Search 30 150

Place order 20 100

Total 100 500

.NET技術代言人 林耀珍 2004/03/24 38

Process testProcess testCreate scriptsModify Scripts or configure scripts

User delaysUser patterns: different pathsGroups of users: customer, sales, adminsDistribution of Activities: ex. start timeAbandon ratio

Avoid script failuresDataNavigationData CorrelationSecurity issues: Authorization/Authentication

Load DataRun the tests and Collect Data

.NET技術代言人 林耀珍 2004/03/24 39

Analyze the Results Analyze the Results

Analyze the captured data and compare the results against the metric's accepted level. The data you collect helps you analyze your application with respect to your application's performance objectives:

Throughput vs. user load.Response time vs. user load.Resource utilization vs. user load.

.NET技術代言人 林耀珍 2004/03/24 40

AnalysisAnalysis

Potential Bottlenecks Throughput Vs User load

0

50

100

150

200

250

300

350

0 100 200 300 400 500 600 700 800 900 1000 1100 1200 1300 1400 1500 1600

Number of Simultaneous Users

Thro

ughp

ut (R

eque

sts/

Sec)

Throughput Peak

SLA Failure

Response Time Vs User load

0

500

1000

1500

2000

2500

0 100 200 300 400 500 600 700 800 900 1000 1100 1200 1300 1400 1500 1600

Number of Simultaneous Users

Resp

onse

Tim

e (m

S)

Service Level Violation

% Processor Time Vs User load

0

20

40

60

80

100

120

0 100 200 300 400 500 600 700 800 900 1000 1100 1200 1300 1400 1500 1600

Number of Simultaneous Users

Proc

esso

r Tim

e(%

)

Your threshold limit

.NET技術代言人 林耀珍 2004/03/24 41

Analyze ResultsAnalyze Results

Proper design and execution of tests as well as proper measurement of system and/or component activities make the analysis easier

.NET技術代言人 林耀珍 2004/03/24 42

Investigate root causesInvestigate root causes

Multiple Performance Index

.NET技術代言人 林耀珍 2004/03/24 43

ReportingReporting

Hardware Details Software detailsConfiguration DetailsWorkload Profile Performance ObjectivesMetrics

System MetricsWeb Server MetricsSQL Server Metrics

Analysis

.NET技術代言人 林耀珍 2004/03/24 44

Load TrendLoad Trend

Good for high level presentation

.NET技術代言人 林耀珍 2004/03/24 45

Design Guidelines Design Guidelines

.NET技術代言人 林耀珍 2004/03/24 46

Improve Components PerformanceImprove Components Performance

Managed CodeData Access ComponentASP.NETWeb Services.NET Remoting ComponentEnterprise Services ComponentInterop Component

.NET技術代言人 林耀珍 2004/03/24 47

Common CategoriesCommon CategoriesData Structures and AlgorithmsCommunicationConcurrencyResource ManagementCoupling and CohesionCaching State ManagementSecurityDeployment

.NET技術代言人 林耀珍 2004/03/24 48

Design PrinciplesDesign Principles

Design coarse-grained services Minimize roundtrips and batch work Acquire late and release earlyEvaluate affinity with processing resources Put the processing closer to the resourcesPool shared resources Avoid unnecessary work Reduce contention Use smart recalculation Concurrently process independent tasks

.NET技術代言人 林耀珍 2004/03/24 49

Improving ASP.NET PerformanceImproving ASP.NET Performance

Architecture

.NET技術代言人 林耀珍 2004/03/24 50

Performance and Scalability Performance and Scalability Issues Issues

Resource affinity Failure to share expensive resources Blocking operations Misusing threadsMaking late bound callsMisusing COM Interop Large pages Improper data caching Failure to use output caching properly Inefficient rendering

.NET技術代言人 林耀珍 2004/03/24 51

Design GuidelinesDesign GuidelinesPartition your application logicallysecurityReduce roundtripsAvoid blocking on long-running taskscachingExceptionsResource ManagementDeployment Considerations----------------------------------------------------------------Pages GuidelinesServer Controls GuidelinesData BindingState ManagementData Access

.NET技術代言人 林耀珍 2004/03/24 52

SecuritySecurity

Constrain unwanted Web server trafficTurn off authentication for anonymous accessValidate user input on the clientAvoid per-request impersonationAvoid caching sensitive dataSegregate secure and non-secure contentOnly use SSL for pages that require itUse absolute URLs for navigation between HTTP & HTTPS pagesConsider using SSL hardware to offload SSL processingTune SSL timeout to avoid SSL session expiration

.NET技術代言人 林耀珍 2004/03/24 53

Reduce RoundtripsReduce Roundtrips

HttpResponse.ClientIsConnectedConsider using this to check if the client is still connected before processing a request and performing expensive server side operations

Output caching Output buffering – not for a slow comm.use Server.Transfer instead of Response.Redirect.

.NET技術代言人 林耀珍 2004/03/24 54

Avoid Blocking on Long-Running Avoid Blocking on Long-Running Tasks Tasks

Use asynchronous calls to invoke Web services or remote objects Consider using the OneWay attribute on Web methods or remote object methods if you do not need a response Queue work and poll for completion from the client

.NET技術代言人 林耀珍 2004/03/24 55

CachingCaching

Separate dynamic data from static data in your pagesConfigure the memory limitCache the right dataRefresh your cache appropriatelyCache the appropriate form of dataUse output caching to cache relatively static pagesChoose the right cache locationUse VaryBy attributes for selective cachingUse kernel caching on Windows Server 2003

.NET技術代言人 林耀珍 2004/03/24 56

ExceptionException

Implement a Global.asax error handlerMonitor application exceptionsUse Try/Finally on disposible ResourcesWrite code that avoids exceptionsSet timeouts aggressively

.NET技術代言人 林耀珍 2004/03/24 57

Resource ManagementResource Management

Pool resourcesExplicitly Close/Dispose resources you openDo not cache or block on pooled resourcesKnow your application allocation patternObtain resources late and release them earlyAvoid per-request impersonation

.NET技術代言人 林耀珍 2004/03/24 58

Pages GuidelinesPages Guidelines

Trim your page sizeEnable bufferingUse Page.IsPostBack to minimize redundant processingPartition page content to improve caching efficiency and reduce renderingEnsure pages are batch compiledEnsure debug is set to falseOptimize expensive loopsConsider using Server.Transfer instead of Response.RedirectUse client side validationAvoid calling Server.MapPath on a per-request basis

.NET技術代言人 林耀珍 2004/03/24 59

Server Controls GuidelinesServer Controls Guidelines

Identify your server control's use of view stateUse server controls where appropriateAvoid creating deep hierarchies of controls

.NET技術代言人 林耀珍 2004/03/24 60

Data BindingData Binding

Avoid using Page.DataBindWhen you call DataBind, this invokes the page level method that in turn calls the DataBind method of every control on the page that supports data binding. Rather than calling the page level DataBind, call DataBind on specific controls.

Minimize calls to DataBinder.EvalDataBinder.Eval uses reflection to evaluate the arguments passed in and return the results. If you have a table that has 100 rows and 10 columns, you end up calling DataBinder.Eval 1000 times if you used DataBinder.Eval on each column

.NET技術代言人 林耀珍 2004/03/24 61

State ManagementState Management

Do not maintain complex types between requestsStore simple state on the client where possibleConsider serialization costs

.NET技術代言人 林耀珍 2004/03/24 62

Data AccessData Access

Data access is typically a focal point for improving performance

Use paging for large ResultsetsUse a DataReader for fast and efficient data bindingPrevent users from requesting too much dataConsider caching data

.NET技術代言人 林耀珍 2004/03/24 63

Deployment ConsiderationsDeployment Considerations

Understand the performance implications of a remote middle tierShort-circuit the ASP.NET pipelineConfigure the memory limitDisable tracing and debuggingEnsure content updates do not cause additional assemblies to be loadedAvoid XCOPY under heavy loadConsider pre-compiling pagesConsider Web garden configurationAvoid unnecessary process hopsConsider using HTTP compressionConsider using perimeter caching

.NET技術代言人 林耀珍 2004/03/24 64

ResourcesResources

Improving .NET Application Performance & Scalability In http://www.gotdotnet.com/Community/Workspaces/Directory.aspx

.NET技術代言人 林耀珍 2004/03/24 65

SummarySummary

Must have a structured approachFollow principles, practices, and guidelinesTo have a good team is the key

Allocate Budget !!!

.NET Architecture

Patterns & Practices

Questions…Questions…

Microsoft .NET 技術代言人林耀珍