Finding the Performance Bottlenecks in Your Application Ian Jones and Roger Schrag Database Specialists, Inc. www.dbspecialists.com IOUG-A Live! 1999 Paper.

Slides:



Advertisements
Similar presentations
Performance Tuning Methods Author: Vladimir Andreev Semantec GmbH Lector: Stoyan Ivanov Semantec Bulgaria OOD Semantec GmbH Benzstr. 32 D Herrenberg,
Advertisements

Tuning Oracle SQL The Basics of Efficient SQLThe Basics of Efficient SQL Common Sense Indexing The Optimizer –Making SQL Efficient Finding Problem Queries.
1 Proven Process for SQL Tuning Dean Richards Senior DBA, Confio Software.
Introduction to SQL Tuning Brown Bag Three essential concepts.
Chapter 9. Performance Management Enterprise wide endeavor Research and ascertain all performance problems – not just DBMS Five factors influence DB performance.
13 Copyright © 2005, Oracle. All rights reserved. Monitoring and Improving Performance.
Overview of performance tuning strategies Oracle Performance Tuning Allan Young June 2008.
1.
What Happens when a SQL statement is issued?
1 Wait Event Enhancements in Oracle 10g Terry Sutton and Roger Schrag Database Specialists, Inc.
1 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.
© IBM Corporation Informix Chat with the Labs John F. Miller III Unlocking the Mysteries Behind Update Statistics STSM.
1 Tuning with Oracle’s SQL Trace David Kurtz Go-Faster Consultancy Ltd.
Copyright © 200\8 Quest Software High Performance PL/SQL Guy Harrison Chief Architect, Database Solutions.
INTRODUCTION TO ORACLE Lynnwood Brown System Managers LLC Performance And Tuning – Lecture 7 Copyright System Managers LLC 2007 all rights reserved.
Agenda Overview of the optimizer How SQL is executed Identifying statements that need tuning Explain Plan Modifying the plan.
1 - Oracle Server Architecture Overview
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 11 Database Performance Tuning and Query Optimization.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 11 Database Performance Tuning and Query Optimization.
1 Tuning PL/SQL procedures using DBMS_PROFILER 20-August 2009 Tim Gorman Evergreen Database Technologies, Inc. Northern California Oracle.
Oracle 11g Real Application Testing: Avoiding Performance Regressions with SQL Performance Analyzer Khaled Yagoub, Pete Belknap, Benoit Dageville, Karl.
Module 5: Data Access. Overview Introduce database components involved in data access Introduce concepts of Transact -SQL and Procedural SQL as tools.
ORACLE ONLINE TRAINING Contact our Support Team : SOFTNSOL India: Skype id : softnsoltrainings id:
6/1/2001 Supplementing Aleph Reports Using The Crystal Reports Web Component Server Presented by Bob Gerrity Head.
Introduction to Databases Chapter 8: Improving Data Access.
® Enterprise Manager/Management Packs Conference Call Phone Number: 1(888) Pass Code: CYBER.
Database Systems: Design, Implementation, and Management Tenth Edition Chapter 11 Database Performance Tuning and Query Optimization.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 10 Database Performance Tuning and Query Optimization.
Oracle Database Administration Lecture 6 Indexes, Optimizer, Hints.
1 Robert Wijnbelt Health Check your Database A Performance Tuning Methodology.
Improving Efficiency of I/O Bound Systems More Memory, Better Caching Newer and Faster Disk Drives Set Object Access (SETOBJACC) Reorganize (RGZPFM) w/
The Self-Managing Database: Guided Application and SQL Tuning Mohamed Ziauddin Consulting Member of Technical Staff Oracle Corporation Session id:
1 Optimizing Your ColdFusion Applications for Oracle Justin Fidler, CNA, CPS, CCFD Chief Technology Officer Bantu, Inc. 8 May 2001.
Oracle Tuning Considerations. Agenda Why Tune ? Why Tune ? Ways to Improve Performance Ways to Improve Performance Hardware Hardware Software Software.
Oracle Tuning Ashok Kapur Hawkeye Technology, Inc.
Chapter 2: SQL – The Basics Objectives: 1.The SQL execution environment 2.SELECT statement 3.SQL Developer & SQL*Plus.
11-1 Improve response time of interactive programs. Improve batch throughput. To ensure scalability of applications load vs. performance. Reduce system.
Learningcomputer.com SQL Server 2008 – Profiling and Monitoring Tools.
CERN - IT Department CH-1211 Genève 23 Switzerland t DB Development Tools Benthic SQL Developer Application Express WLCG Service Reliability.
By Shanna Epstein IS 257 September 16, Cnet.com Provides information, tools, and advice to help customers decide what to buy and how to get the.
Oracle tuning: a tutorial Saikat Chakraborty. Introduction In this session we will try to learn how to write optimized SQL statements in Oracle 8i We.
Module 4 Database SQL Tuning Section 3 Application Performance.
6/1/2001 Supplementing Aleph Reports Using The Crystal Reports Web Component Server Presented by Bob Gerrity Head.
© IBM Corporation 2005 Informix User Forum 2005 John F. Miller III Explaining SQLEXPLAIN ®
Troubleshooting 11i issues Adam Janbolat
1 Chapter 13 Parallel SQL. 2 Understanding Parallel SQL Enables a SQL statement to be: – Split into multiple threads – Each thread processed simultaneously.
Copyright 2007, Information Builders. Slide 1 Machine Sizing and Scalability Mark Nesson, Vashti Ragoonath June 2008.
Database Access Using JDBC BCIS 3680 Enterprise Programming.
Tracing Individual Users in Connection-pooled Environments with Oracle 10g Terry Sutton Database Specialists, Inc.
DB Tuning : Chapter 10. Optimizer Center for E-Business Technology Seoul National University Seoul, Korea 이상근 Intelligent Database Systems Lab School of.
Oracle9i Developer: PL/SQL Programming Chapter 11 Performance Tuning.
Scott Fallen Sales Engineer, SQL Sentry Blog: scottfallen.blogspot.com.
Execution Plans Detail From Zero to Hero İsmail Adar.
Same Plan Different Performance Mauro Pagano. Consultant/Developer/Analyst Oracle  Enkitec  Accenture DBPerf and SQL Tuning Training Tools (SQLT, SQLd360,
In this session, you will learn to: Create and manage views Implement a full-text search Implement batches Objectives.
SAP Tuning 실무 SK㈜ ERP TFT.
 Reviewing basic architecture concepts  Oracle 10g Architecture  Main features of 9i and 10g
Tuning Oracle SQL The Basics of Efficient SQL Common Sense Indexing
Planning a Migration.
1 DB2 Access Recording Services Auditing DB2 on z/OS with “DBARS” A product developed by Software Product Research.
SQL Trace and TKPROF.
Query Tuning without Production Data
SQL Server Monitoring Overview
Database Performance Tuning and Query Optimization
JULIE McLAIN-HARPER LINKEDIN: JM HARPER
Chapter 11 Database Performance Tuning and Query Optimization
Introduction to Execution Plans
Introduction to Execution Plans
Performance Tuning ETL Process
Presentation transcript:

Finding the Performance Bottlenecks in Your Application Ian Jones and Roger Schrag Database Specialists, Inc. IOUG-A Live! 1999 Paper #158

Finding the Bottleneck: Half the Battle in Tuning One bad SQL statement can spoil performance Too much code to take the “let’s tune every statement” approach DBA can’t be familiar with every line of code

Zero in on the Bottleneck Use the v$ views Use SQL Trace and timed statistics Use GUI tools

Today’s Presentation Half a dozen real-life examples –scenario –command-line efforts –resolution Demo of GUI tools –Enterprise Manager –freeware

The Terrifyingly Slow EDI Load A transportation company used EDI to exchange data with customers. They loaded EDI files into a temp table with SQL*Loader and then ran a 1500 line PL/SQL stored procedure to validate the data and update application tables. As more customers began sending EDI files, the PL/SQL stored procedure could no longer keep up. Data validation took as long as 24 hours for some EDI files. Where do we start tuning?

Start Load Process and Identify the Database Session SQL> SELECT sid, serial#, status, username, osuser, 2 module, action 3 FROM v$session; SID SERIAL# STATUS USERNAME OSUSER MODULE ACTION ACTIVE oracle 2 1 ACTIVE oracle 3 1 ACTIVE oracle 4 1 ACTIVE oracle 5 1 ACTIVE oracle 6 1 ACTIVE oracle ACTIVE BJENKINS bjenkins de INACTIVE RTHOMAS rthomas de INACTIVE EJOHNSON ejohnson de ACTIVE EDI_LOAD edi SQL*Plus validate

View the Statement Being Executed SQL> SELECT B.sql_text 2 FROM v$session A, v$sqlarea B 3 WHERE A.sid = 45 4 AND B.address = A.sql_address; SQL_TEXT SELECT ITEM_ID FROM ITEM_TRANSLATIONS WHERE SOURCE_ID = :b1 AND SUBSTR(SOURCE_SKU_CODE,1,6) = :b2 AND SYSDATE BETWEEN START_DATE_ACTIVE AND NVL (END_DATE_ACTIVE, SYSDATE)

We Found a Bottleneck! PROCEDURE edi_validate_and_load (p_cust_id IN NUMBER) IS CURSOR c_get_item_id (cp_cust_id IN NUMBER, cp_sku IN VARCHAR2) IS SELECT item_id FROM item_translations WHERE source_id = cp_cust_id AND source_sku_code LIKE cp_sku || '%' AND SYSDATE BETWEEN start_date_active AND NVL (end_date_active, SYSDATE);

Disk Array Far Too Busy One third of a financial institution’s loan processing department started using a new PowerBuilder application. Response time was acceptable, but disk utilization on the server was at 100%. What could be done to reduce I/O so that the response time will still be acceptable after the rest of the department starts using the new application?

Identify the SQL Statements Causing the Most Disk Reads SELECT sql_text, disk_reads, executions, disk_reads / DECODE (executions, 0, 1, executions) reads_per_exec FROM v$sqlarea ORDER BY reads_per_exec; SELECT sql_text, disk_reads, executions, disk_reads / DECODE (executions, 0, 1, executions) reads_per_exec FROM v$sqlarea ORDER BY disk_reads; SELECT sql_text, buffer_gets, executions, buffer_gets / DECODE (executions, 0, 1, executions) gets_per_exec FROM v$sqlarea ORDER BY buffer_gets;

Part of the Query Results… SQL_TEXT DISK_READS EXECUTIONS READS_PER_EXEC SELECT P.PRODUCT_DESC, CP.PRODUCT_ID, UPPER (:b1) CLIENT_ID FROM CLIENT_PRODUCT CP, PRODUCT P WHERE CP.PRODUCT_ID = P.PRODUCT_ID AND (UPPER (CP.CLIENT_ID), CP.VALID_CLIENT_LEVEL_ID) IN (SELECT UPPER (:b1), CA.VALID_CLIENT_LEVEL_ID FROM CLIENTS C, CLIENT_ADDRESS CA WHERE UPPER (C.CLIENT_ID) = UPPER(:b1) AND C.CLIENT_ID = CA.CLIENT_ID)

The Same Query Formatted for Readability SELECT P.product_desc, CP.product_id, UPPER (:b1) client_id FROM client_product CP, product P WHERE CP.product_id = P.product_id AND (UPPER (CP.client_id), CP.valid_client_level_id) IN (SELECT UPPER (:b1), CA.valid_client_level_id FROM clients C, client_address CA WHERE UPPER (C.client_id) = UPPER(:b1) AND C.client_id = CA.client_id) A case-insensitive query turns out to be very inefficient. Now we know what to tune.

The So-Called “Locking Problem” A developer coded a PL/SQL function called compute_irr for computing internal rate of return. Response times varied widely. The developer claimed there was a locking problem on the database. What caused the slow performance in compute_irr?

SQL> SELECT sid, serial#, status, username, osuser, 2 module, action 3 FROM v$session; SID SERIAL# STATUS USERNAME OSUSER MODULE ACTION ACTIVE oracle 2 1 ACTIVE oracle 3 1 ACTIVE oracle 4 1 ACTIVE oracle 5 1 ACTIVE oracle 6 1 ACTIVE oracle INACTIVE GL swatkins INACTIVE APPLSYS applmgr ACTIVE RSCHRAG rschrag SQL*Plus INACTIVE FA rschrag SQL*Plus Start SQL*Plus and Identify the Database Session

Check Session Statistics Before Calling compute_irr SQL> SELECT A.name, B.value 2 FROM v$statname A, v$sesstat B 3 WHERE B.statistic# IN (12, 37, 38, 39, 119, 123, 4 139, 140, 141) 5 AND B.sid = 63 6 AND A.statistic# = B.statistic#; NAME VALUE CPU used by this session 1292 db block gets consistent gets physical reads 346 table scans (long tables) 0 table scan rows gotten 1054 sorts (memory) 826 sorts (disk) 0 sorts (rows) 4693

Check Session Statistics Again While compute_irr Is Running SQL> SELECT A.name, B.value 2 FROM v$statname A, v$sesstat B 3 WHERE B.statistic# IN (12, 37, 38, 39, 119, 123, 4 139, 140, 141) 5 AND B.sid = 63 6 AND A.statistic# = B.statistic#; NAME VALUE CPU used by this session 7274 db block gets consistent gets physical reads 346 table scans (long tables) 0 table scan rows gotten 1054 sorts (memory) 826 sorts (disk) 0 sorts (rows) 4693

Compute the Deltas Look for an infinite loop that involves no SQL statements.

Where Is the I/O Coming From? An application that performed well in a demo database quickly became I/O-bound when a significant amount of data was loaded into the database. It seemed as if there was a huge amount of I/O even with no users logged on to the application. What could be causing so much I/O activity?

Look at Physical Reads Instance-Wide and Per Session SQL> SELECT name || ' (instance-wide)', value 2 FROM v$sysstat 3 WHERE statistic# = 39 4 UNION ALL 5 SELECT 'sid = ' || TO_CHAR (sid), value 6 FROM v$sesstat 7 WHERE statistic# = 39;

And the Results Are... NAME VALUE physical reads (instance-wide) sid = 1 0 sid = 2 0 sid = 3 0 sid = 4 0 sid = 5 0 sid = sid = sid = 8 0 sid = sid = sid = sid =

Investigate Suspicious Session 13 SQL> SELECT sid, serial#, status, username, osuser, 2 module, action 3 FROM v$session 4 WHERE sid = 13; SID SERIAL# STATUS USERNAME OSUSER MODULE ACTION ACTIVE APPSCHEMA daemon EXTRACT GET SQL> SELECT A.name, B.value 2 FROM v$statname A, v$sesstat B 3 WHERE B.statistic# IN (12, 37, 38, 39, 119, 123, 4 139, 140, 141) 5 AND B.sid = 13 6 AND A.statistic# = B.statistic#;

Suspicious Session 13 (continued) NAME VALUE CPU used by this session 0 db block gets consistent gets 293 physical reads table scans (long tables) 575 table scan rows gotten sorts (memory) 3 sorts (disk) 0 sorts (rows) 4210

What SQL Is Session 13 Executing? SQL> SELECT B.sql_text 2 FROM v$session A, v$sqlarea B 3 WHERE B.address = A.sql_address 4 AND A.sid = 13; SQL_TEXT SELECT * FROM TRANSACTIONS WHERE EXTRACTED = 'N’ Let me guess! The transactions table is about 10,000 blocks in size and the extracted column is not indexed.

“Fast” Reports That Were Too Slow A software vendor built an application using Oracle, Developer/2000, and a third-party reporting tool. A key report took about six seconds to complete, but consider that users will run the report in batches of several thousand. The report has thousands of lines of spaghetti code. How do you figure out what's slowing it down?

Build a Version of the Report That Enables SQL Trace DECLARE c INTEGER; i INTEGER; BEGIN c := dbms_sql.open_cursor; dbms_sql.parse (c, 'ALTER SESSION SET TIMED_STATISTICS=TRUE', dbms_sql.native); i := dbms_sql.execute (c); dbms_sql.close_cursor (c); dbms_session.set_sql_trace (TRUE); END; Trace only what you need to trace!

Run the Report, Fetch the Trace File, Run TKPROF On It OVERALL TOTALS FOR ALL NON-RECURSIVE STATEMENTS call count cpu elapsed disk query Parse Execute Fetch total Misses in library cache during parse: 30 Look into using bind variables to reduce parsing.

The Chameleon Application An application ran well on a test database loaded with a full set of production data. But when the application was deployed in production, queries took over a minute to complete. In the test environment these same queries completed in under ten seconds. Policies forbid modifying code in production. What could be causing the application to run slower in production?

Find a Power User to Reproduce the Slow Behavior Identify the database session: SQL> SELECT sid, serial#, status, username, osuser, 2 module, action 3 FROM v$session 4 WHERE username = 'MARYD'; SID SERIAL# STATUS USERNAME OSUSER MODULE ACTION INACTIVE MARYD mbd frontend query

Enable Timed Statistics Temporarily SQL> ALTER SYSTEM SET TIMED_STATISTICS = TRUE; System altered. SQL>

Enable SQl Trace Just Before the Query Is Launched SQL> BEGIN 2 dbms_system.set_sql_trace_in_session (17, 9172, TRUE); 3 END; 4 / PL/SQL procedure successfully completed. SQL>

Disable SQL Trace When the Query Is Finished SQL> BEGIN 2 dbms_system.set_sql_trace_in_session (17, 9172, FALSE); 3 END; 4 / PL/SQL procedure successfully completed. SQL> SQL> ALTER SYSTEM SET TIMED_STATISTICS = FALSE; System altered. SQL>

Fetch the Trace File and Run TKPROF call count cpu elapsed disk query current rows Parse Execute Fetch total Misses in library cache during parse: 1 Optimizer goal: RULE Parsing user id: 142 (BUILD4P2) Rows Execution Plan SELECT STATEMENT GOAL: RULE 0 MERGE JOIN (OUTER) 254 SORT (JOIN) 115 NESTED LOOPS (OUTER) 253 NESTED LOOPS (OUTER) 254 TABLE ACCESS GOAL: ANALYZED (BY ROWID) OF 'MNME' INDEX GOAL: ANALYZED (FULL SCAN) OF 'MNME_I1' (UNIQUE) 253 TABLE ACCESS GOAL: ANALYZED (BY ROWID) OF 'LCONTYPE' 254 INDEX GOAL: ANALYZED (UNIQUE SCAN) OF 'LCONTYPE_PK' (UNIQUE) 115 TABLE ACCESS GOAL: ANALYZED (BY ROWID) OF 'MTAX' 254 INDEX GOAL: ANALYZED (UNIQUE SCAN) OF 'MTAX_I1' (UNIQUE) 129 SORT (JOIN) 129 TABLE ACCESS GOAL: ANALYZED (FULL) OF 'LPOST’ The optimizer can behave differently from one Oracle version to the next.

GUI Tools Demo

To Find the Bottlenecks in Your Applications: Monitor v$sqlarea Monitor v$sysstat and v$sesstat Use SQL Trace judiciously Consider using GUI tools

Resources Oracle Server Tuning - Overview of the tuning process - How to use SQL Trace and TKPROF Oracle Server Reference - Descriptions of all v$ views High Performance SQL Tuning by Guy Harrison - Lots of tuning tips - Discussion of GUI tools available on the Internet Download this presentation - Download a companion white paper

Contact Information Ian Jones: Roger Schrag: Database Specialists, Inc. 388 Market Street, Suite 400 San Francisco, CA /