ODP.NET Data Types

55
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 1

Transcript of ODP.NET Data Types

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.1

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.2

Oracle and .NET: Best Practices for Performance and Deployment

Alex Keh, Christian Shay

Principal Product Managers, Oracle

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.3

Program Agenda

Optimization Process

Optimizing ODP.NET Performance

– Connections

– Data Retrieval and Updates

– ODP.NET Data Types

– Caching

ODP.NET Deployment

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.4

Program Agenda

Optimizing Oracle DB Performance from Visual Studio

– SQL Tuning Advisor

– Oracle Performance Analyzer

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.5

Optimization Process

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.6

Oracle .NET Application Performance –Optimization Steps

.NET data access tuning

– Use ODP.NET best practices

SQL tuning

– Use SQL Tuning Advisor in Visual Studio

Database tuning under real world conditions

– Oracle Performance Analyzer in Visual Studio detects issues

you have missed

– May need to modify application based on findings

– Can be used during testing phase or production

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.7

Optimizing ODP.NET Performance

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.8

Connections

Connection pooling (CP)

– OracleConnection by default includes a connection pool

– Monitor and tune them using Windows Performance Monitor

Close/Dispose connections (and all objects) explicitly

– Do not necessarily rely on the garbage collector

– Recommendation applies to all ODP.NET objects

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.9

Connection Management – Clusters and Standbys

RAC automatic connection load balancing

– Load Balancing = true

RAC and Data Guard automatic “bad” connection removal

– HA Events = true

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.10

Commands – Bind Variables

Prevents re-parsing of frequently executed statements

– Works with SQL and PL/SQL statements

Improves subsequent command executions

– Literal value changes forces a re-parse and re-optimization

– Literal values should become bind variables

Executed statements stored in Oracle shared pool

– Re-parsing and re-optimization uses CPU and requires shared

pool locks

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.11

Commands – Statement Caching

Retains previously parsed statement in shared pool

– Cursor stays open on the client side for faster re-use

No additional lookup needed on server

– Metadata remains on the client

Caches most recently used statements

– Works with SQL and PL/SQL statements

– Best with bind variables

Self-tuned cache size – on by default

– No code changes needed

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.12

Commands – Data Retrieval

Control how much data is retrieved per DB roundtrip

– Too much data retrieved – excessive client-side memory used

– Too little data retrieved – additional round trips

Use OracleCommand.RowSize and

OracleDataReader.FetchSize to control result size

– RowSize populated after statement execution

Set dynamically at run-time

– FetchSize can be set as multiple of RowSize

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.13

D E M O N S T R A T I O N

Fetch Size and Row Size

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.14

Commands – Statement Batching

Use OracleDataAdapter.UpdateBatchSize to batch

updates from DataSet

Execute multiple commands in one DB roundtrip

– Use anonymous PL/SQL

Useful for disparate or similar statements

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.15

Commands – Mass Data Movement with Arrays

PL/SQL associative arrays

– Pass large amounts of data between .NET and DB of the same

data type

Use parameter array binding

– Useful if executing the same statement multiple times

– Bind variables are the same, variable values can be different

– One execution for each element in the bound array

Remember: PL/SQL associative arrays and parameter

array binding are two different concepts

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.16

Promotable Transactions

Promote local transactions to distributed at run time

– Better application performance

– Lower resource usage

On by default

Requirements

– First connection to Oracle Database 11g (11.1) or higher

– Subsequent connections to any other version or database

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.17

ODP.NET Data Types

Avoid unnecessary data type conversions

.NET vs. ODP.NET Types

– OracleDataReader Type Accessors

– OracleParameter.DbType vs. OracleParameter.OracleDbType

Option to store Oracle data types in DataSet

– OracleDataAdapter.ReturnProviderSpecificTypes = true

– Available in ADO.NET 2.0

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.18

REF Cursors

Retrieve data as needed

– Control data retrieved via FetchSize

– Fill a DataSet with just a portion of the REF Cursor result

– Explicit control over what REF Cursor data is retrieved and how

Defers result set retrieval until needed

Pass REF Cursors back as input stored procedure

parameters

OracleRefCursor class

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.19

SecureFiles and LOBs

Data retrieval options

– Defer retrieval (default) with LOB locator

– Retrieve data immediately with

OracleCommand.InitialLOBFetchSize

– Retrieve a chunk using Read method

Use Search method to find data to be retrieved

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.20

SecureFiles and LOBs

Update/Insert/Delete

– Modify LOB without retrieving the data to the client side

Uses LOB locator

Use SecureFile data type in Oracle Database 11g

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.21

Oracle .NET Caching Solutions

Oracle .NET database caches

– Client Result Cache

– Continuous Query Notification (CQN)

– TimesTen In-Memory Database

Automatically updates/alerts client cache upon server

changes

Each serves separate caching requirements

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.22

Oracle Client Result Cache

Automatically updating cache of query result sets

Benefits

– Easy to use

No code changes required

– Snapshot consistent

Cache refreshes without user intervention

– More scalability and performance

Data retrieval from client, rather than server

No additional round trips

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.23

Oracle Client Result Cache Updates

1. Upon data change, client receives change notification

on subsequent round trip (or max lag)

– Invalidation notifications piggyback on existing client round trips

– No changes to the cache results yet

2. Cache waits for next execution to refresh results

– Does not initiate an independent round trip

No unnecessary DB traffic

Cache entries do not timeout

– Uses Least Recent Used algorithm

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.24

D E M O N S T R A T I O N

Client Result Cache

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.25

Oracle Continuous Query Notification (CQN)

Easy to use automated cache with more programmatic

control

Also known as Database Change Notification

Benefits over Client Result Cache

– More control over how cache behavior

What if multiple users access the same results?

What if only a subset of the cached data is required?

How long should a query be cached?

Do I want additional logic executed when the cache is refreshed?

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.26

Notification

Queue

Application

Listener

OracleCommand

OracleDependency

Data Dictionary

OnChange

Add Dependency

Execute()

Notification Request

TABLE

Data Change

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.27

Oracle TimesTen In-Memory Database

Fully featured relational database

Oracle compatible SQL and PL/SQL with ODP.NET

Persistent and durable

– Transactions with ACID properties

– Flexible options for durability

Exceptional performance

– Instantaneous response time, high throughput, embeddable

Memory-Optimized Relational Database

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.28

ODP.NET (Unmanaged Driver) Deployment

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.29

.NET Deployment Platform Target

Select either “x86” or “x64”

– Depends on platform target

– Ensure ODP.NET version supports that platform

Do not use “AnyCPU” (default)

– “AnyCPU” instructs assembly to run natively on current CPU

x86 or x64

– May not be intended ODP.NET platform version installed

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.30

Deployment: Instant Client (IC) Benefits

Control over install process

– Xcopy

Fine grain control over installation process

Great for large scale deployments or ISV packaging

– OUI – great for small scale deployments

Smaller install size compared to standard install

– Xcopy install – smallest footprint

– OUI install – small footprint

Fastest client deployment – Xcopy install

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.31

Managing Multiple Oracle Homes in .NET

Solution for ODP.NET 10.2.0.4 and higher

– ODP.NET reads .NET config files for location of unmanaged

Oracle DLLs

– Each app can use different Oracle client DLLs even if same

ODP.NET managed version is used

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.32

Managing Multiple Oracle Homes in .NET

DLL search order

– 1. Current application directory

– 2. Application config or web.config

– 3. Machine.config

– 4. Windows Registry

HKLM\Software\Oracle\ODP.NET\<version>\DllPath

– 5. Windows System Path setting

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.33

Optimizing Oracle DB Performance from Visual Studio

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.34

Performance Tuning in Visual Studio –SQL Tuning Advisor

• Use when designing new SQL statements

• Tune ad-hoc SQL statements in Query Window

• Tune bad SQL found by Oracle Performance Analyzer

• Use if SQL is performing poorly under load

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.35

SQL Tuning Advisor

• Requirements

– ADVISOR privilege

– Oracle Database license for Oracle Diagnostic Pack

– Oracle Database license for the Oracle Tuning Pack

• How to run:

– Oracle Query Window “Tune SQL” button

– Oracle Performance Monitor – Tune SQL button

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.36

SQL Tuning Advisor

• Implement Findings Button

– Automatically fix the problem for certain finding types

• View Report Button

– View more details about how to fix a problem

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.37

D E M O N S T R A T I O N

SQL Tuning Advisor

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.38

Performance Tuning in Visual Studio –Oracle Performance Analyzer

• Detects performance issues in an application’s use of

the database under load

• Requirements

– SYSDBA

– Oracle Database license for Oracle Diagnostic Pack

• Can be use during testing

• Can be also used on production applications

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.39

Oracle Performance Analyzer

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.40

Oracle Performance Analyzer

• Simple to use

– Run your application

– Enter amount of time to analyze

– Press Start to start timer

– Sufficient “database time” required to get results

– View findings and actions

– Implement recommended actions

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.41

AWR and ADDM

• Built into the Oracle Database 10g

• Automatic Workload Repository (AWR)

– Evolution of statspack

– Built-in repository

– Captures performance statistics at regular intervals

• Automatic Database Diagnostic Monitor (ADDM)

– Methodically analyses captured AWR stats

– Generates recommendations

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.42

AWR and ADDM

• AWR Snapshots

– A collection of database statistics and performance metrics

gathered at a single point in time.

– Two snapshots make up one analysis time period

– Oracle Database automatically takes periodic snapshots

• ADDM Tasks

– An analysis of Oracle database performance over a period of

time

– Requires two AWR Snapshots to define that time period

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.43

AWR and ADDM in Visual Studio

• AWR Snapshots

– New AWR Snapshot Dialog

– AWR Snapshots Node in Server Explorer

• ADDM Tasks

– New ADDM Task Dialog

– ADDM Tasks Node in Server Explorer

– ADDM Task results are displayed in Oracle Performance

Analyzer

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.44

D E M O N S T R A T I O N

Performance Analyzer

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.45

Oracle Performance Analyzer

• “Manual” Method, instead of using Timer

– Run your application

– Create a Snapshot, via “New AWR Snapshot” dialog

– Wait desired time period

– Create second snapshot

– Create ADDM Task, via “New ADDM Task” dialog

– View Results. If insufficient database time, wait a while and

create one more snapshot and another ADDM task

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.46

Oracle Performance Analyzer

• Manual Method Pros

– Can close Visual Studio during time period

– If insufficient database time, you can extend the time period by

creating one more snapshot, without having to wait entire

duration again

– Can use database created AWR Snapshots if desired

– Can elect to monitor all statistics when creating the snapshots

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.47

Conclusion and Q & A

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.48

Upcoming .NET Sessions

Oracle and .NET: Best Practices for Performance and

Deployment

– 10:15 AM - 11:15 AM, Marriott Marquis - Golden Gate C1

PL/SQL Programming for .NET Developers: Tips, Tricks,

and Debugging

– 1:15 PM - 2:15 PM, Marriott Marquis - Golden Gate C1

Using Entity Framework with Oracle Database

– 5:00 PM - 6:00 PM, Marriott Marquis - Golden Gate C1

Wednesday Oct 3

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.49

Upcoming .NET Sessions

Hands-on Lab: Building .NET Applications with Oracle

– 12:45 PM - 3:15 PM, Marriott Marquis - Salon 10/11

Thursday Oct 4

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.50

Visit .NET Experts at the Demogrounds

.NET Development for Oracle Database

Moscone South, Left - S-068

Monday through Wednesday

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.51

Additional Oracle .NET Resources

OTN .NET Developer Center

– http://otn.oracle.com/dotnet

Twitter

– @OracleDOTNET

YouTube

– http://www.youtube.com/user/OracleDOTNETTeam

For more questions

[email protected] or [email protected]

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.52

Graphic Section Divider

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.53

The preceding is intended to outline our general product direction. It is intended

for information purposes only, and may not be incorporated into any contract.

It is not a commitment to deliver any material, code, or functionality, and should

not be relied upon in making purchasing decisions. The development, release,

and timing of any features or functionality described for Oracle’s products

remains at the sole discretion of Oracle.

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.54

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.55