Presentation is loading. Please wait.

Presentation is loading. Please wait.

DEV351 ADO.NET Performance Pablo Castro Program Manager – ADO.NET Team Microsoft Corporation.

Similar presentations


Presentation on theme: "DEV351 ADO.NET Performance Pablo Castro Program Manager – ADO.NET Team Microsoft Corporation."— Presentation transcript:

1 DEV351 ADO.NET Performance Pablo Castro Program Manager – ADO.NET Team Microsoft Corporation

2 Agenda What Impacts Data Access Performance? ADO.NET Performance Characteristics Why Connections are Expensive? Query Execution and Data Retrieval Disconnected Scenarios

3 What Impacts Performance? Round-trips Enlist DTC transaction Open connection Execute statement Result fetching (De)Serialization Provider processing Allocations/Boxing High Impact Low Impact Network I/O

4 ADO.NET Performance Connected stack Thin layer, minimum overhead Mixed managed/native providers have may have additional overhead in native code Network is usually the bottleneck Disconnected stack – DataSet Basically a data structure Compact in memory, but not on the wire Allocation-intensive during creation

5 Open() Takes Time Open a communications channel i.e. a socket or a pipe Warm-up time, i.e. TCP slow-start Initial handshake (negotiation, login, …) One or more round-trips (SqlClient does 2) To optimize Connection pooling is critical If pooling is not an option, minimize Opens Choose TCP over Pipes for remote servers

6 Integrated Security Extra steps for integrated security Obtain current thread user’s credentials Do challenge-response (NTLM) Connection pooling helps Pooled connections don’t need an extra authentication step Worth the overhead in most cases Much more secure than SQL authentication

7 Distributed Transactions There is an “enlist” step for connections Automatic if within a COM+ transaction May require several round-trips Can be avoided if not needed “enlist=false” in the connection string Conditional enlistment may help Only enlist if conditions require it Use conn.EnlistDistributedTransaction() New in ADO.NET 1.1

8 Conditional Distributed Transactions demo demo

9 Statement Execution Every execution is a round-trip Try to batch many statements in a single command Use NextResult() to fetch several result-sets Minimize the result-set size Perform all the filtering operations in the server Bring only the columns you need Specially in large result-sets

10 Batching Send several SQL statements in one round-trip Syntax is database-specific Always use parameters for user input Concatenation leads to SQL injection attacks Concatenating using “+” or “&” is slow StringBuilder makes a big difference

11 Statement Batching demo demo

12 DataSet Use them when you won’t use the data right away Never keep a DataReader for a long time Filling up a DataSet implies an overhead The DataAdapter uses a reader internally Minimize round-trips using mappings Loading from XML Avoid inferring the schema if you know it

13 DataSet Serialization Serialization Representation is not compact Use XML attributes instead of elements ColumnMapping=MappingType.Attribute Avoid verbose column names They are repeated many times in the XML doc Deserialization Parsing cost Allocation-intensive

14 Updating DataSets DataSets creates and maintains indexes For primary keys, data views, etc. Maintenance makes updates expensive Minimize updates, or… Minimize indexes i.e. primary keys are not always needed if data comes from a database

15 DataSet Optimizations demo demo

16 Summary Opening connections is very expensive Pooling is critical Round-trips must be minimized Batching helps to reduce them ADO.NET enables high-perf applications Connected stack: thin layer, minimum overhead DataSet: scalability of the disconnected model

17 Community Resources http://www.microsoft.com/communities/default.mspx Most Valuable Professional (MVP) http://www.mvp.support.microsoft.com/ Newsgroups Converse online with Microsoft Newsgroups, including Worldwide http://www.microsoft.com/communities/newsgroups/default.mspx User Groups Meet and learn with your peers http://www.microsoft.com/communities/usergroups/default.mspx

18 evaluations evaluations

19 © 2003 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EXPRESS OR IMPLIED, IN THIS SUMMARY.


Download ppt "DEV351 ADO.NET Performance Pablo Castro Program Manager – ADO.NET Team Microsoft Corporation."

Similar presentations


Ads by Google