26
It’s time to do ASH! It’s time to do ASH! Tuesday, Februrary 8 Tuesday, Februrary 8 th th 2005 2005 Gaja Krishna Vaidyanatha Principal, DBPerfMan LLC [email protected] http://www.dbperfman.com

It’s time to do ASH! Tuesday, Februrary 8 th 2005 Gaja Krishna Vaidyanatha Principal, DBPerfMan LLC [email protected] [email protected]

Embed Size (px)

Citation preview

It’s time to do ASH!It’s time to do ASH!

Tuesday, Februrary 8Tuesday, Februrary 8thth 2005 2005

Gaja Krishna VaidyanathaPrincipal, DBPerfMan [email protected]

http://www.dbperfman.com

I am not an expert…not by any I am not an expert…not by any stretch of the imagination.stretch of the imagination.

Confession#1Confession#1

I am an engineer not a scientist.I am an engineer not a scientist.

Confession#2Confession#2

Advanced Tuning, Turbo-charged Advanced Tuning, Turbo-charged Tuning, Push-Me-For-More-Power Tuning, Push-Me-For-More-Power Tuning…Lies…Just Plain Lies…Tuning…Lies…Just Plain Lies…

Or is it called Marketing these days!!!Or is it called Marketing these days!!!

Confession#3Confession#3

There is only one way to optimize There is only one way to optimize Oracle performance – The Right Oracle performance – The Right Way...Using the Wait InterfaceWay...Using the Wait Interface

Confession#4Confession#4

Plan of ActionPlan of Action

What is ASH?What is ASH?

Oracle 10Oracle 10gg ASH! ASH!

Why should you use ASH?Why should you use ASH?

Components of ASHComponents of ASH

ASH ArchitectureASH Architecture

ASH DetailsASH Details

Using ASH - Some Initial FindingsUsing ASH - Some Initial Findings

Future Ideas for ASHFuture Ideas for ASH

ConclusionConclusion

What is ASH?What is ASH?

Non-Oracle ASHNon-Oracle ASH Ashland Inc. (NYSE – ASH)Ashland Inc. (NYSE – ASH) Action on Smoking and HealthAction on Smoking and Health American Society of HypertensionAmerican Society of Hypertension ASH Karo!!! ASH Karo!!!

Means “Have FUN in Hindi”Means “Have FUN in Hindi”

ASH in Oracle 10ASH in Oracle 10gg Active Session HistoryActive Session History

“ “ASH KaroASH Karo Said in another way “Use Oracle 10g ASH”Said in another way “Use Oracle 10g ASH”

Oracle 10Oracle 10gg ASH! ASH!

New source of Oracle database performance data in 10New source of Oracle database performance data in 10ggAn An active sessionactive session is one which is in a user call is one which is in a user call

ParseParse ExecuteExecute FetchFetch On the CPUOn the CPU

Provides historical information about recently Provides historical information about recently sampledsampled “active” sessions“active” sessions

ASH = V$SESSION_WAIT++ with HistoryASH = V$SESSION_WAIT++ with History Note: In 10Note: In 10gg V$SESSION_WAIT is integrated with V$SESSION_WAIT is integrated with

V$SESSIONV$SESSION

It facilitates It facilitates spot analysisspot analysis of both foreground and of both foreground and background sessionsbackground sessions

Oracle 10Oracle 10gg ASH! ASH!

Why should you use ASH?Why should you use ASH?

Great for performance diagnosticsGreat for performance diagnostics Logs wait events along with SQL details and session-Logs wait events along with SQL details and session-

specific context in a circular buffer in memoryspecific context in a circular buffer in memory

Fixed session sampling algorithm uses < 0.1% of Fixed session sampling algorithm uses < 0.1% of 1 CPU1 CPU

Can be modified by the use of an _ parameterCan be modified by the use of an _ parameter

Primary data provider for the Automatic Database Primary data provider for the Automatic Database Diagnostic Monitor (ADDM)Diagnostic Monitor (ADDM)

ADDM supports proactive performance diagnostics ADDM supports proactive performance diagnostics within the Oracle Kernelwithin the Oracle Kernel

Components of ASHComponents of ASHMemory buffers in the fixed areasMemory buffers in the fixed areasNew Oracle Background ProcessNew Oracle Background Process

MMNL – MMON LiteMMNL – MMON Lite

V$ACTIVE_SESSION_HISTORYV$ACTIVE_SESSION_HISTORYX$ASHX$ASHDBA_HIST_ACTIVE_SESS_HISTORYDBA_HIST_ACTIVE_SESS_HISTORY

Based on WRH$_ACTIVE_SESSION_HISTORYBased on WRH$_ACTIVE_SESSION_HISTORY

ASH ArchitectureASH Architecture

Circular buffer

in SGA

V$ACTIVE_SESSION_HISTORY

X$ASH

AWR

WRH$_ACTIVE_SESSION_HISTORY

Every 30 mins

or when buffer is

full

Samples with variable size rows

Direct-path inserts

MMON Lite (MMNL)

Indexed on timeIndexed on time

ASH Details - GeneralASH Details - GeneralNo installation or setup requiredNo installation or setup requiredIntended 30-min circular buffer in the SGAIntended 30-min circular buffer in the SGAIn memory ASH contains as much history as it can In memory ASH contains as much history as it can store. store.

Circular buffer not cleared when written to diskCircular buffer not cleared when written to disk

ASH on Disk (1 of 10 in memory samples)ASH on Disk (1 of 10 in memory samples)Init.ora Init.ora

STATISTICS_LEVEL = TYPICAL (Default)STATISTICS_LEVEL = TYPICAL (Default)

Master SwitchMaster Switch _ACTIVE_SESSION_HISTORY = TRUE (Default)_ACTIVE_SESSION_HISTORY = TRUE (Default)

ASH Details - GeneralASH Details - General

30-minute circular buffer in the SGA - GOAL30-minute circular buffer in the SGA - GOAL May scale down to smaller duration on large systemsMay scale down to smaller duration on large systems

Circular Buffer Sizing Formula:Circular Buffer Sizing Formula:Max( Min (# of CPUs * 2MB, 5% of Max( Min (# of CPUs * 2MB, 5% of SHARED_POOL_SIZE, 30MB), 1MB)SHARED_POOL_SIZE, 30MB), 1MB)If SHARED_POOL_SIZE is not explicitly setIf SHARED_POOL_SIZE is not explicitly set

Formula changes to 2% of SGA targetFormula changes to 2% of SGA target

ASH Details - GeneralASH Details - General

Assumptions for MAX Size - 30MBAssumptions for MAX Size - 30MB 100 active sessions100 active sessions Sampled at once per second (60 samples in 1 minute)Sampled at once per second (60 samples in 1 minute) Assume 17 minutes of non-stop collectionAssume 17 minutes of non-stop collection Assume 300 bytes per sampleAssume 300 bytes per sample Size = 100*60*17*300 bytes ~ 29.18MBSize = 100*60*17*300 bytes ~ 29.18MB Fudge Factor of 0.82 MBFudge Factor of 0.82 MB

ASH Details - GeneralASH Details - General

History flushed to Automatic Workload Repository History flushed to Automatic Workload Repository (AWR) every 30 minutes(AWR) every 30 minutes

Part of the AWR snapshotPart of the AWR snapshot Database metricsDatabase metrics Session Wait InformationSession Wait Information Hot files and segmentsHot files and segments

ASH Details - GeneralASH Details - General

Sampling done every secondSampling done every second Can support sub-second samplingCan support sub-second sampling _ash_sampling_interval = 1000 (milliseconds by default)_ash_sampling_interval = 1000 (milliseconds by default)

Can dump to process trace (if required)Can dump to process trace (if required)Estimated 2500 CPU Instructions per active session per Estimated 2500 CPU Instructions per active session per samplesample

400 active sessions on a 1 Ghz processor consumes < 1 400 active sessions on a 1 Ghz processor consumes < 1 millisecondmillisecond

The sampler (MMNL) does not take any latchesThe sampler (MMNL) does not take any latchesIt supports dirty readsIt supports dirty readsCan write to the in-memory buffer without any issuesCan write to the in-memory buffer without any issues

ASH Details – View DescribeASH Details – View DescribeSQL> desc v$active_session_historySQL> desc v$active_session_history Name Name Null? Null? TypeType ------------------------------------------------------------------------------ -------------- ---------------------------- ---------------------------- SAMPLE_ID SAMPLE_ID NUMBERNUMBER SAMPLE_TIME SAMPLE_TIME TIMESTAMP(3)TIMESTAMP(3) SESSION_ID SESSION_ID NUMBERNUMBER SESSION_SERIAL# SESSION_SERIAL# NUMBERNUMBER USER_ID USER_ID NUMBERNUMBER SQL_ID SQL_ID VARCHAR2(13)VARCHAR2(13) SQL_CHILD_NUMBER SQL_CHILD_NUMBER NUMBERNUMBER SQL_PLAN_HASH_VALUE SQL_PLAN_HASH_VALUE NUMBERNUMBER SQL_OPCODE SQL_OPCODE NUMBERNUMBER SERVICE_HASH SERVICE_HASH NUMBERNUMBER SESSION_TYPE SESSION_TYPE VARCHAR2(10)VARCHAR2(10) SESSION_STATE SESSION_STATE VARCHAR2(7)VARCHAR2(7) QC_SESSION_ID QC_SESSION_ID NUMBERNUMBER QC_INSTANCE_ID QC_INSTANCE_ID NUMBERNUMBER EVENTEVENT VARCHAR2(64)VARCHAR2(64) EVENT_IDEVENT_ID NUMBERNUMBER EVENT_#EVENT_# NUMBERNUMBER SEQ#SEQ# NUMBERNUMBER P1 P1 NUMBERNUMBER P2 P2 NUMBERNUMBER P3 P3 NUMBERNUMBER WAIT_TIME WAIT_TIME NUMBERNUMBER TIME_WAITED TIME_WAITED NUMBERNUMBER CURRENT_OBJ# CURRENT_OBJ# NUMBERNUMBER CURRENT_FILE# CURRENT_FILE# NUMBERNUMBER CURRENT_BLOCK# CURRENT_BLOCK# NUMBERNUMBER PROGRAM PROGRAM VARCHAR2(64)VARCHAR2(64) MODULE MODULE VARCHAR2(48)VARCHAR2(48) ACTION ACTION VARCHAR2(32)VARCHAR2(32) CLIENT_ID CLIENT_ID VARCHAR2(64)VARCHAR2(64)

ASH Details – View DefinitionASH Details – View DefinitionSQL> select view_definition from v$fixed_view_definitionSQL> select view_definition from v$fixed_view_definition 2* where view_name = 'GV$ACTIVE_SESSION_HISTORY';2* where view_name = 'GV$ACTIVE_SESSION_HISTORY';

VIEW_DEFINITION VIEW_DEFINITION ----------------------------------------------------------------------------------------------------------------------------------------------------------------SELECT /*+ no_merge ordered use_nl(s,a) */ a.inst_id, s.sample_id, s.sample_time, SELECT /*+ no_merge ordered use_nl(s,a) */ a.inst_id, s.sample_id, s.sample_time, a.session_id, a.session_id,

a.session_serial#, a.user_id, a.sql_id, a.sql_child_number, a.session_serial#, a.user_id, a.sql_id, a.sql_child_number, a.sql_plan_hash_value, a.sql_plan_hash_value, a.sql_opcode, a.service_hash,a.sql_opcode, a.service_hash,

decode(a.session_type, 1,'FOREGROUND', 2,'BACKGROUND',decode(a.session_type, 1,'FOREGROUND', 2,'BACKGROUND','UNKNOWN'), 'UNKNOWN'),

decode(a.wait_time, 0, 'WAITING', 'ON CPU'), decode(a.wait_time, 0, 'WAITING', 'ON CPU'),

a.qc_session_id, a.qc_instance_id, a.event, a.event_id, a.event#, a.seq#, a.p1, a.p2, a.p3, a.wait_time, a.qc_session_id, a.qc_instance_id, a.event, a.event_id, a.event#, a.seq#, a.p1, a.p2, a.p3, a.wait_time, a.time_waited, a.current_obj#, a.current_file#, a.current_block#, a.program, a.module, a.action, a.client_id a.time_waited, a.current_obj#, a.current_file#, a.current_block#, a.program, a.module, a.action, a.client_id

FROM x$kewash s, x$ash a FROM x$kewash s, x$ash a

WHERE s.sample_addr = a.sample_addr and WHERE s.sample_addr = a.sample_addr and s.sample_id = a.sample_id and s.sample_id = a.sample_id and

s.sample_time = a.sample_time s.sample_time = a.sample_time

The New Oracle 10g Car Wash

ASH Details – WRH$_ASH View DescribeASH Details – WRH$_ASH View DescribeSQL> desc wrh$_active_session_historySQL> desc wrh$_active_session_history Name Null? Name Null? TypeType ------------------------------------ ------------------------------------ -------- -------- ------------------------------

SNAP_ID SNAP_ID NOT NULL NOT NULL NUMBERNUMBER

DBID DBID NOT NULL NOT NULL NUMBERNUMBER

INSTANCE_NUMBER INSTANCE_NUMBER NOT NULL NOT NULL NUMBERNUMBER

SAMPLE_ID SAMPLE_ID NOT NULL NOT NULL NUMBERNUMBER

SAMPLE_TIME SAMPLE_TIME NOT NULL NOT NULL TIMESTAMP(3)TIMESTAMP(3)

SESSION_ID SESSION_ID NOT NULL NOT NULL NUMBERNUMBER

SESSION_SERIAL# SESSION_SERIAL# NUMBERNUMBER

USER_ID USER_ID NUMBERNUMBER

SQL_ID SQL_ID VARCHAR2(13)VARCHAR2(13)

SQL_CHILD_NUMBER SQL_CHILD_NUMBER NUMBERNUMBER

SQL_PLAN_HASH_VALUESQL_PLAN_HASH_VALUE NUMBERNUMBER

SERVICE_HASH SERVICE_HASH NUMBERNUMBER

SESSION_TYPE SESSION_TYPE NUMBERNUMBER

SQL_OPCODE SQL_OPCODE NUMBERNUMBER

QC_SESSION_ID QC_SESSION_ID NUMBERNUMBER

QC_INSTANCE_ID QC_INSTANCE_ID NUMBERNUMBER

CURRENT_OBJ# CURRENT_OBJ# NUMBERNUMBER

CURRENT_FILE#CURRENT_FILE# NUMBERNUMBER

CURRENT_BLOCK#CURRENT_BLOCK# NUMBERNUMBER

SEQ# SEQ# NUMBERNUMBER

EVENT_ID EVENT_ID NUMBERNUMBER

P1 P1 NUMBERNUMBER

P2 P2 NUMBERNUMBER

P3 P3 NUMBERNUMBER

WAIT_TIME WAIT_TIME NUMBERNUMBER

TIME_WAITED TIME_WAITED NUMBERNUMBER

PROGRAM PROGRAM VARCHAR2(48)VARCHAR2(48)

MODULE MODULE VARCHAR2(48)VARCHAR2(48)

ACTION ACTION VARCHAR2(32)VARCHAR2(32)

CLIENT_ID CLIENT_ID VARCHAR2(64)VARCHAR2(64)

Using ASH – Some Initial FindingsUsing ASH – Some Initial Findings

Querying V$ACTIVE_SESSION_HISTORY Querying V$ACTIVE_SESSION_HISTORY needs a sessionneeds a session

New logins may be impossible on badly crippled New logins may be impossible on badly crippled systemssystems

Query V$ACTIVE_SESSION_HISTORY requires Query V$ACTIVE_SESSION_HISTORY requires all relevant latches in the SQL layerall relevant latches in the SQL layer

On systems crippled on On systems crippled on shared pool shared pool and and library library cache latches, queries to cache latches, queries to ASHASH will impose even will impose even more overhead on these latchesmore overhead on these latches

Proposed Workaround for LimitationsProposed Workaround for Limitations

1.1. Data in buffer is first dumped to a process trace file – Data in buffer is first dumped to a process trace file – Host 1Host 1

2.2. Transport the file (ftp) to another box – Host 2Transport the file (ftp) to another box – Host 2

3.3. Sanitize the file of its headers and other information on Sanitize the file of its headers and other information on Host 2Host 2

4.4. Build a SQL*Loader Control File for the load on Host 2Build a SQL*Loader Control File for the load on Host 2

5.5. Create a user-defined ASH table (with the same Create a user-defined ASH table (with the same structure) in a database in Host2structure) in a database in Host2

6.6. Load the data from #3 using #4 into #5Load the data from #3 using #4 into #5

Optional Demo!!!Optional Demo!!!

Future Ideas for ASHFuture Ideas for ASH

Keep a persistent and “reserved” sessionKeep a persistent and “reserved” session Eliminates the need to “logon”Eliminates the need to “logon”

Pre-compile some standard cursors on ASH, Pre-compile some standard cursors on ASH, Eliminates the need to Eliminates the need to soft parsesoft parse

Open a non-PL/SQL API so that data from the Open a non-PL/SQL API so that data from the collector can be directly readcollector can be directly read

Eliminates the need to SQL*Load trace data into Eliminates the need to SQL*Load trace data into another databaseanother database

ConclusionConclusion

Great performance diagnostic data sourceGreat performance diagnostic data source But it is only for 10But it is only for 10gg

Granular enough data for most problemsGranular enough data for most problemsMakes for a good performance management suite when Makes for a good performance management suite when combined with ADDM and AWRcombined with ADDM and AWRBrand new code – Maturity will come with timeBrand new code – Maturity will come with timeYet to replace 3Yet to replace 3rdrd-party direct-SGA-attached collectors-party direct-SGA-attached collectors

But it may be cheaper…;-)But it may be cheaper…;-)

Visit us at http://www.dbperfman.com

Gaja Krishna Vaidyanatha, Principal, DBPerfMan LLC, [email protected]

Thank You!Thank You!