100% found this document useful (1 vote)
1K views81 pages

Performance Tuning Apex Applications

Performance Tuning Oracle APEX Applications

Uploaded by

Yasir Ali Shah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
1K views81 pages

Performance Tuning Apex Applications

Performance Tuning Oracle APEX Applications

Uploaded by

Yasir Ali Shah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 81

Performance Tuning

Apex Applications
Doug Gault
MY BACKGROUND
Doug Gault
[email protected]

Using Oracle since 1988


Versions 5.1b, 6, 7, 8, 9, 10, 11

Focused on Web Technologies

OWA, PSP, Web DB, HTML-DB, APEX

Ex-Hotsos Employee of 5 years


Product Development Director - APEX Applications

2004 through 2008

Commercial Applications written in APEX

Joined Sumner Technologies January 2009


Co-Founded Sumneva January 2010

2 Copyright 2010 Sumneva - All Rights Reserved - http://sumneva.com - [email protected]


AGENDA
Introduction - Knowledge is Power
Coding Best Practices ... Get Started Right
Monitoring the Performance of Your Application
Tools Available for Diagnosis

3 Copyright 2010 Sumneva - All Rights Reserved - http://sumneva.com - [email protected]


Introduction:
Knowledge is Power

4 Copyright 2010 Sumneva - All Rights Reserved - http://sumneva.com - [email protected]


WHEN DEALING WITH PERFORMANCE, KNOWLEDGE IS POWER...

Know the Architecture


Know the Intended End User
Know the Expectations
Know the Applications Purpose

5 Copyright 2010 Sumneva - All Rights Reserved - http://sumneva.com - [email protected]


Know Your Architecture

6 Copyright 2010 Sumneva - All Rights Reserved - http://sumneva.com - [email protected]


LOGICAL ARCHITECTURE
APEX is a metadata-based environment
No need to write code to instantiate an APEX component
Rather you specify options with Wizards or the Application Builder

Metadata-based does not imply limitations on


complexity
APEXs development environment is quite extensible
Can add calls to PL/SQL almost everywhere

Which can in turn, call other languages

APEX is built in APEX

7 Copyright 2010 Sumneva - All Rights Reserved - http://sumneva.com - [email protected]


LOGICAL ARCHITECTURE
Some benefits of a metadata-based framework:
No code is generated
Impossible to tune

Not extensible

Easy to transfer from one environment to another


Done without leaving the browser

Application Builder masks all complexity


User just sees screens and provides values

You can incorporate APEX metadata in your applications

8 Copyright 2010 Sumneva - All Rights Reserved - http://sumneva.com - [email protected]


APEX SCHEMAS
APEX is comprised of three schemas:

All APEX metadata is


APEX_030200 stored here

Any uploaded files end


FLOWS_FILES up here initially

All APEX page views


APEX_PUBLIC_USER* connect as this schema
* When the EPG is used, ANONYMOUS will be the public APEX schema

9 Copyright 2010 Sumneva - All Rights Reserved - http://sumneva.com - [email protected]


PHYSICAL ARCHITECTURE
Despite its simplicity, the physical architecture of APEX
can be configured a number of different ways
Simple for development & testing
Everything on a single box

Sophisticated for production


Multiple HTTP Servers with a Load Balancer

SSL & ASO for end-to-end secure transactions

RAC at the Database tier for performance boosts

Data Guard for fault tolerance

10 Copyright 2010 Sumneva - All Rights Reserved - http://sumneva.com - [email protected]


APPLICATION EXPRESS ARCHITECTURE

9i & 10g
Access via HTTP Server (Apache)
MOD_PLSQL

11 Copyright 2010 Sumneva - All Rights Reserved - http://sumneva.com - [email protected]


APPLICATION EXPRESS ARCHITECTURE

11g +
Can replace Oracle HTTP server with Embedded PL/SQL Gateway (EPG)
Provides Oracle database with Web Server capability
Runs in XML-DB HTTP SERVER
Oracle 10g XE also uses a version of EPG

12 Copyright 2010 Sumneva - All Rights Reserved - http://sumneva.com - [email protected]


DATABASE SESSION

Similar to a Phone Call


Both parties have to invest resources to carry on a
conversation
Even if no one is talking

Each additional conversation puts some additional strain on


the host party

Oracle Forms Client Oracle Application Server Oracle Database

13 Copyright 2010 Sumneva - All Rights Reserved - http://sumneva.com - [email protected]


APEX SESSION
smlr 2 a txt msg :)
Both parties need few resources to carry on a conversation
Regardless of whether someone is taking or not

Each additional conversation puts little additional strain on


the host party

Web Browser Oracle HTTP Server Oracle Database


with APEX

14 Copyright 2010 Sumneva - All Rights Reserved - http://sumneva.com - [email protected]


SESSION STATE
APEX sessions are logically and physically distinct from
underlying database sessions
mod_plsql on the Middle Tier will connect to the database
via the APEX_PUBLIC_USER
Multiple APEX users can share the same database connection
Thus, there is a one-to-many relationship between
APEX users and database sessions
Main reason APEX can scale as well as it does

15 Copyright 2010 Sumneva - All Rights Reserved - http://sumneva.com - [email protected]


APPLICATION EXPRESS ARCHITECTURE
Important Things to Take Away Regarding Performance
Your code is stored as metadata (Not Pre-Compiled Objects)

Rendered on demand (for EACH demand)

Application session state is maintained by APEX

Once the HTTP request is satisfied, the Oracle session is released

16 Copyright 2010 Sumneva - All Rights Reserved - http://sumneva.com - [email protected]


Know Your Users and Their
Expectations

17 Copyright 2010 Sumneva - All Rights Reserved - http://sumneva.com - [email protected]


USERS AND EXPECTATIONS
Your users dictate what is acceptable
Different target audiences will have different acceptability criteria
Users of a PUBLIC site
Expect sub-second response time

Will bail out early if performance is bad

Often wont give you a second chance

Users of CORPORATE Window on Data systems


Tend to know more about the data they are working with

Are more forgiving of poor response time

May have no other choice as to where they get their data

Still have their limits!

18 Copyright 2010 Sumneva - All Rights Reserved - http://sumneva.com - [email protected]


AND REMEMBER...

Performance = User Experience

19 Copyright 2010 Sumneva - All Rights Reserved - http://sumneva.com - [email protected]


THE PERFORMANCE FORMULA

i
P= ( R

E
)* N

P = Performance
R = Real Response Time
E = Expected Response Time
i = Importance of the Task
N = Number of Times the User Must Perform the Task

20 Copyright 2010 Sumneva - All Rights Reserved - http://sumneva.com - [email protected]


Know The Intended Purpose
of the Application

21 Copyright 2010 Sumneva - All Rights Reserved - http://sumneva.com - [email protected]


INTENDED PURPOSE
Application Type
Transactional (Data Entry, E-Commerce, ...)

End User Reporting (Dynamic Reports, D/W Reporting, ...)

Administrative (User Admin, Time Sheet Systems, ...)

Application Volume
Number of users accessing the system

Size of data in the database

Volume of data being returned by the average query

Utilization Profile
Even usage throughout the day

A few peak usage times

22 Copyright 2010 Sumneva - All Rights Reserved - http://sumneva.com - [email protected]


KNOWLEDGE IS POWER
Chances are if youve been involved in the
development of an APEX application, you have
a good understanding of these factors for your
specific application.

If not...

FIND OUT!

23 Copyright 2010 Sumneva - All Rights Reserved - http://sumneva.com - [email protected]


Performance Best Practices
Things you can do to help insure good performance, and make poor
performance easier to diagnose.

24 Copyright 2010 Sumneva - All Rights Reserved - http://sumneva.com - [email protected]


FIRST OF ALL...

25 Copyright 2010 Sumneva - All Rights Reserved - http://sumneva.com - [email protected]


ITS PRETTY SIMPLE REALLY!
It all starts with the install
Understand how APEX works
Be Smart about how you build your applications
Take advantage of what APEX gives you

26 Copyright 2010 Sumneva - All Rights Reserved - http://sumneva.com - [email protected]


It All Starts With
The Install

27 Copyright 2010 Sumneva - All Rights Reserved - http://sumneva.com - [email protected]


PAY ATTENTION TO THE REQUIREMENTS
shared_pool_size >= 100MB
Disk Space
APEX Tablespace
125 MB for standard install

34 MB for each additional language install

System Tablespace
85MB Free

28 Copyright 2010 Sumneva - All Rights Reserved - http://sumneva.com - [email protected]


THIS BRINGS UP THE TOPIC OF TABLESPACES
DONT
Install APEX into SYSAUX
The example in the documentation is just that

Other things use SYSAUX

Limited Control over Sizing and Growth

DO
Create specific tablespaces for both APEX_XXXXXX and
FLOWS_FILES
Ability to correctly size and control growth of APEX tablespaces

Easier for DBA to manage tablespace placement

Lessens opportunity for contention in the SYSAUX tablespace


* Apologies to John Scott for my blatant plagiarism.

29 Copyright 2010 Sumneva - All Rights Reserved - http://sumneva.com - [email protected]


Understand How APEX
Works

30 Copyright 2010 Sumneva - All Rights Reserved - http://sumneva.com - [email protected]


MORE KNOWLEDGE, MORE POWER
RENDER - Presenting the page to the user
Computations

Processes
Rendering the Page Items

PROCESS - Processing the users input


Computations

Validations
Processes
Branching

31 Copyright 2010 Sumneva - All Rights Reserved - http://sumneva.com - [email protected]


MULTIPLE VIEWS OF YOUR PAGE

In the VIEW drop-down select Events


Shows both Page Rendering and Page processing events

Shows in order of execution


Links to definition of items for direct editing

Show All
Shows every possible item/action even if they are not used

Show Used
Shows only those items/actions that are used by the page

32 Copyright 2010 Sumneva - All Rights Reserved - http://sumneva.com - [email protected]


EVENTS VIEW IN THE PAGE BUILDER

33 Copyright 2010 Sumneva - All Rights Reserved - http://sumneva.com - [email protected]


Be Smart About How You
Build Your Applications

34 Copyright 2010 Sumneva - All Rights Reserved - http://sumneva.com - [email protected]


MVC - SEPARATE UI FROM LOGIC
Try not to use HTML in your SQL Queries
Hinders re-use
Forces you to edit SQL to change the presentation

Potentially forces oracle to Hard Parse when it shouldnt


Impacts scalability

Instead move display logic to APEX


Templates
CSS
Item Formatting
Report Columns

Form Items

35 Copyright 2010 Sumneva - All Rights Reserved - http://sumneva.com - [email protected]


MOVE ANONYMOUS PL/SQL INTO THE DATABASE

Stored code is compiles (P-Code)


Doesnt need to be compiled for every run

Easier to test individually


Easier to isolate problem code
Enables re-use of code
Enables use of Interactive Debugging with SQL-Developer
Enables PL/SQL Profiling*

* More on this later

36 Copyright 2010 Sumneva - All Rights Reserved - http://sumneva.com - [email protected]


AVOID USE OF APEX SPECIFIC VARIABLES IN STORED PL/SQL

In any procedure that does a significant amount of


work, and may become a performance bottleneck,
avoid use of:
v(VARIABLE)
:APP_USER, :APP_ID, :SESSION_ID

Pass values into PL/SQL as parameters


Helps with performance & security implications
Only incur overhead of obtaining the value once
Ability to run/test/debug PL/SQL outside of APEX

37 Copyright 2010 Sumneva - All Rights Reserved - http://sumneva.com - [email protected]


INSTRUMENT YOUR CODE
A large part of easy diagnosis is knowing what is going on in
your code
Where it IS slow
Where it is NOT slow

Many ways to implement Instrumentation


DBMS_OUTPUT
Insert into a table
Client identifier & Module/Action
Hotsos ILO
Log4PLSQL

38 Copyright 2010 Sumneva - All Rights Reserved - http://sumneva.com - [email protected]


INSTRUMENT YOUR CODE
Instrumentation Guidelines
Instrumentation should exist in DEV & PROD
Must be easy to perform
Must be light weight
Always on - Shouldnt need to re-compiled code to access
Take advantage of built-in functionality
Set CLIENT_IDENTIFIER & CLIENT INFO
set MODULE & ACTION

39 Copyright 2010 Sumneva - All Rights Reserved - http://sumneva.com - [email protected]


GATHER STATISTICS

Your application is made up of PL/SQL & SQL
Your application runs in the database
The cost-based optimizer will use more accurate
query plans if you have up to date statistics
Your applications performance will benefit

Gather Statistics for


your application schemas!

40 Copyright 2010 Sumneva - All Rights Reserved - http://sumneva.com - [email protected]


GATHER STATISTICS
APEX is made up of PL/SQL & SQL
APEX runs in the database
The cost-based optimizer will use more accurate
query plans if you have up to date statistics
APEX performance will benefit

Gather Statistics for


your APEX schemas!

41 Copyright 2010 Sumneva - All Rights Reserved - http://sumneva.com - [email protected]


Take Advantage
of What APEX

42 Copyright 2010 Sumneva - All Rights Reserved - http://sumneva.com - [email protected]


USE DECLARATIVE LOGIC WHERE APPROPRIATE

APEX gives you many places where you can code logic
Conditional Rendering of items, regions, etc.

Conditional Processes

Validation Logic

Make use of built-in logic where possible


ITEM = VALUE will be faster than PL/SQL condition :ITEM =
VALUE

Is Numeric validation will be faster than hand coded PL/SQL

43 Copyright 2010 Sumneva - All Rights Reserved - http://sumneva.com - [email protected]


BE SMART ABOUT PAGINATION
In a data-set of 5,000 rows
Any pagination scheme using X to Y
Only needs to fetch Y+1 records

Any pagination scheme using X to Y of Z


Must retrieve all rows to determine the value of Z

Row Ranges X to Y (with next & previous


links) is recommended for large datasets
Also, set Maximum Row Count to 1000 or less

44 Copyright 2010 Sumneva - All Rights Reserved - http://sumneva.com - [email protected]


BE SMART ABOUT USING PAGE ZERO
Items on Page Zero get rendered for every page
Even if they are not rendered the conditional logic
must be executed
Make sure youre using Page Zero for truly global
purposes
Dont forget to optimize Page Zero process logic

45 Copyright 2010 Sumneva - All Rights Reserved - http://sumneva.com - [email protected]


BE SMART ABOUT PAGE AND APPLICATION PROCESSES

Page and Application level processes can be set to run


for each page or once per session
Very important to tune PER-PAGE-VIEW processes
Page level processes effect performance of only their page
Application level processes potentially effect performance for
every page

46 Copyright 2010 Sumneva - All Rights Reserved - http://sumneva.com - [email protected]


BE SMART ABOUT PAGE & REGION

Page and Region Caching


Exist in 3.0+
NOT browser base - APEX caches the HTML rendered by the region in a cache table and
serves up the Cached HTML from the table
Developer Specifies
whether or not to cache

Timeout

Condition for whether content is pulled from cache

Pages can be cached Per User

Best used for pages or regions that dont change often.

47 Copyright 2010 Sumneva - All Rights Reserved - http://sumneva.com - [email protected]


BE SMART ABOUT USING IMAGES
Where to store Images:
Template Images belong in the Filesystem
Images that appear on every or almost every page
Logos, tabs, etc.
Transactional Images can be stored in the
database or the filesystem
Images which are part of a row of data
For Example: Image of a Product
File System based images used on every page will be
cached by the browser, making for less queries
executed per page view

48 Copyright 2010 Sumneva - All Rights Reserved - http://sumneva.com - [email protected]


Monitoring the
Performance of Your

49 Copyright 2010 Sumneva - All Rights Reserved - http://sumneva.com - [email protected]


MONITORING PERFORMANCE
Dont wait for users to call and tell you its slow
Make it part of your daily routine to review the facts
Remember
Users dictate what constitutes acceptable
Know your target audience

Know your applications purpose

Help your users understand when their expectations arent realistic

50 Copyright 2010 Sumneva - All Rights Reserved - http://sumneva.com - [email protected]


MONITORING PERFORMANCE
In APEX
In SQL-DEVELOPER
Using Firefox & FireBug
Actually better suited to diagnosis than monitoring

51 Copyright 2010 Sumneva - All Rights Reserved - http://sumneva.com - [email protected]


IN APEX - APEX REPORTS

Home > Administration > Monitor Activity


Many different & interesting reports
4 most significant in terms of performance
Recent Page Views

Pave Views by Application

Application Errors

By Weighted Page Performance *

* Probably the most important

52 Copyright 2010 Sumneva - All Rights Reserved - http://sumneva.com - [email protected]


APEX
Performance Reports
D E M O N S T R A T I O N

53 Copyright 2010 Sumneva - All Rights Reserved - http://sumneva.com - [email protected]


SQL-DEVELOPER REPORTS
Many built-in reports
Applications

Pages

Schemas
Workspaces
Applications

Access Log

Activity Log

Activity Summary

User Summary

Schema

Files

54 Copyright 2010 Sumneva - All Rights Reserved - http://sumneva.com - [email protected]


SQL-DEVELOPER REPORTS

Only work with APEX 3.0+


Only Activity Log really gives any useful diagnostic
information
Doesnt give weighted report like APEX reports do.

Custom Reports to solve the problems


Works with APEX 2+
Versions for all versions of SQL-DEV 1.2, 1.5, 2.x +
Custom Reports Now Included in SQL-DEV 2.1

55 Copyright 2010 Sumneva - All Rights Reserved - http://sumneva.com - [email protected]


SQL-Developer
Performance Reports
D E M O N S T R A T I O N

56 Copyright 2010 Sumneva - All Rights Reserved - http://sumneva.com - [email protected]


Tools Available for Diagnosis

57 Copyright 2010 Sumneva - All Rights Reserved - http://sumneva.com - [email protected]


TOOLS AVAILABLE FOR DIAGNOSIS

Debug Mode
#TIMING# Substitution Variable
FireBug - Network Stats
Isolating Page Items (Condition set to NEVER)
&P_TRACE=YES
MODULE & ACTION Reporting

58 Copyright 2010 Sumneva - All Rights Reserved - http://sumneva.com - [email protected]


DEBUG MODE
0.00:
0.00: S H O W: application="500201" page="21000" workspace="" request="" session="2200174147850707"
0.00: Language derived from: FLOW_PRIMARY_LANGUAGE, current browser language: en-us
0.00: alter session set nls_language="AMERICAN"
0.00: alter session set nls_territory="AMERICA"
0.00: NLS: CSV charset=WE8MSWIN1252
0.00: ...NLS: Set Decimal separator="."
0.00: ...NLS: Set NLS Group separator=","
0.00: ...NLS: Set date format="DD-MON-RR"
0.00: ...Setting session time_zone to dbtimezone
0.00: NLS: Language=en-us
0.00: Application 500201, Authentication: CUSTOM2, Page Template: 46930526449365850
0.01: ...Supplied session ID can be used
0.01: ...Application session: 2200174147850707, user=ADMIN
0.01: Session: Fetch session header information
0.01: ...Metadata: Fetch page attributes for application 500201, page 21000

Great example of instrumented code!

Activation
Development Mode - Select DEBUG from Developer Toolbar

From URL - Place YES in DEBUG position

f?p=App:Page:Session:Request:Debug:ClearCache:ItemNames:ItemValues

Shows Step-by-Step execution and time accounting

Shows Session Values as they are set/saved

Show calling page processing as well as current page rendering

59 Copyright 2010 Sumneva - All Rights Reserved - http://sumneva.com - [email protected]


DEBUG MODE
You can issue DEBUG information too
Using the v(DEBUG) = YES function
Most often used in a condition to hide/display debug regions

Can be used in PL/SQL for conditional debug logic

Using wwv_flow.debug(Foo) procedure


Programmer doesnt have to worry about when debug is on

Works in PL/SQL anonymous blocks and in PL/SQL Stored


Objects

60 Copyright 2010 Sumneva - All Rights Reserved - http://sumneva.com - [email protected]


DEBUG MODE - CAUTION

There are situations where DEBUG can lie to you


Specifically when using AJAX

Example
Single page with 4 HTML regions
Using AJAX to Screen Scrape report regions from other pages
Full Screen takes over 2 minutes to render all data
DEBUG mode reports about 0.14 seconds
Where did the time go?

61 Copyright 2010 Sumneva - All Rights Reserved - http://sumneva.com - [email protected]


DEBUG MODE - CAUTION

62 Copyright 2010 Sumneva - All Rights Reserved - http://sumneva.com - [email protected]


#TIMING# SUBSTITUTION VARIABLE

Allows you to include CPU time in the footer of a region


Must be in the footer
Doesnt work in the header

63 Copyright 2010 Sumneva - All Rights Reserved - http://sumneva.com - [email protected]


#TIMING# SUBSTITUTION VARIABLE

64 Copyright 2010 Sumneva - All Rights Reserved - http://sumneva.com - [email protected]


FIREBUG - NET TIMINGS
Plug-in to FireFox
Most people use it to
Debug JavaScript
Troubleshoot CSS
View generated HTML code

NET TAB
Shows HTTP calls the browser makes to retrieve data
Initial HTML call (f?p...)

Images (wwv_flow_file_mgr.get_file or /i/ )

Javascript AJAX CALLS (wwv_flow.show)

65 Copyright 2010 Sumneva - All Rights Reserved - http://sumneva.com - [email protected]


FIREBUG - NET TIMINGS

66 Copyright 2010 Sumneva - All Rights Reserved - http://sumneva.com - [email protected]


FIREBUG - NET TIMINGS
CAUTION (again...)
FireBug is not perfect either.
It can report files took longer than they did if their display is gated
on something that is actually slow.

FireBug does not report calls made back to the server from within a
FLASH component.

Great walkthrough of Firebugs NET panel


http://www.softwareishard.com/blog/firebug/introduction-to-
firebug-net-panel/

67 Copyright 2010 Sumneva - All Rights Reserved - http://sumneva.com - [email protected]


ISOLATING PAGE ITEMS
Once you believe you have the culprit
Adjust its conditional rendering to NEVER
Rerun the page
Validate that the page runs more quickly
Tune the slow element

68 Copyright 2010 Sumneva - All Rights Reserved - http://sumneva.com - [email protected]


ISOLATING PAGE ITEMS

69 Copyright 2010 Sumneva - All Rights Reserved - http://sumneva.com - [email protected]


&P_TRACE=YES
Add to end of URL
f?p=App:Page:Session:Request:Debug:ClearCach:ItemNames:ItemValues&P_TRACE=YES

Allows developers to generate 10046 level trace


Trace file goes to databases UDUMP directory
Full accounting of time for the SQL Session used to render the page
Another great example of instrumented code

Other ways of obtaining Trace Data


alter session set events 10046 trace name context forever, level 12
dbms_support.start_trace(waits=>true, binds=>true)
dbms_session.session_trace_enable(waits=>true, binds=>true)

70 Copyright 2010 Sumneva - All Rights Reserved - http://sumneva.com - [email protected]


WHAT TO DO WITH THE TRACE FILE
TKPROF / SQL-DEVELOPER 1.5+ Trace Analyzer
Looks at trace data by SQL statement

Dubious attribution of time (Inclusive vs. Exclusive)


Forces you into detail before giving you the overall picture

Hotsos / Method-R Profiler


Full Profile of where the time went

Accounts for ALL time (including so called NULL events)


Starts with an overview of the situation
3 clicks to the heart of the problem

71 Copyright 2010 Sumneva - All Rights Reserved - http://sumneva.com - [email protected]


Trace File Analysis Tools
D E M O N S T R A T I O N

72 Copyright 2010 Sumneva - All Rights Reserved - http://sumneva.com - [email protected]


PL/SQL PROFILING
If your logic has been moved into the database you
can take advantage of PL/SQL Profiling tools
DBMS_PROFILER
DBMS_HPROF
DBMS_TRACE

73 Copyright 2010 Sumneva - All Rights Reserved - http://sumneva.com - [email protected]


DBMS_PROFILER

Available since 8.1.7


Computes the time that your PL/SQL program spends at
each line in each subprogram
You must have CREATE privileges on the units being profiled
Saves statistics in database tables
set serverout on enabled

declare
run_id number;
begin
run_id :=
dbms_profiler.start_profiler(comment => to_char(sysdate,'DD-MM-YYYY HH24:MI:SS'));
..
call pl/sql to be profiled
..

/* Clear data from memory and store it in profiler tables.*/


dbms_profiler.flush_data;
dbms_profiler.stop_profiler;
end;

74 Copyright 2010 Sumneva - All Rights Reserved - http://sumneva.com - [email protected]


DBMS_HPROF

New to 11g
Reports PL/SQL execution profile, organized by subprogram call
Accounts for PL/SQL and SQL execution time separately
Do NOT need CREATE privileges on the units being profiled
Save statistics in database tables, generates HTML, .trc files
BEGIN
/* Start profiling.
Write raw profiler output to file test.trc in a directorythat is mapped to directory
object PLSHPROF_DIR */

DBMS_HPROF.START_PROFILING('PLSHPROF_DIR', 'test.trc');
END;
/
-- Execute procedure to be profiled
BEGIN
test;
END;
/
BEGIN
-- Stop profiling
DBMS_HPROF.STOP_PROFILING;
END;
/

75 Copyright 2010 Sumneva - All Rights Reserved - http://sumneva.com - [email protected]


DBMS_TRACE

Available 8.1.7+
Traces the order in which subprograms are called
Can specify subprograms to trace and to what level
Compile subprograms with DEBUG to enable tracing
Saves statistics in database tables

DBMS_TRACE.SET_PLSQL_TRACE(trace_level INTEGER);


PL/SQL TO TRACE

DBMS_TRACE.CLEAR_PLSQL_TRACE;

76 Copyright 2010 Sumneva - All Rights Reserved - http://sumneva.com - [email protected]


WATCHING LONG RUNNING PAGES

APEX is instrumented to set


MODULE = APEX:APPLICATION AppID

ACTION = PAGE PageID


CLIENT INFO = User
CLIENT IDENTIFIER = User:SessionID:

You can query against V$ tables to see long running queries


Custom SQL-Developer Report

77 Copyright 2010 Sumneva - All Rights Reserved - http://sumneva.com - [email protected]


V$ QUERY

78 Copyright 2010 Sumneva - All Rights Reserved - http://sumneva.com - [email protected]


WHAT WEVE COVERED
Knowlege is Power
Coding Best Practices ... Get Started Right
Monitoring the Performance of Your Applications
Tools Available for Diagnosis

79 Copyright 2010 Sumneva - All Rights Reserved - http://sumneva.com - [email protected]


PERFORMANCE RELATED READING
Chapter 14 of Pro Oracle Application Express John Scott & Scott Spendolini
Sizing Up Performance Mike Hichwa
http://www.oracle.com/technology/oramag/oracle/07-jan/o17browser.html

Managing Oracle Application Express Joel Kallman


http://www.oracle.com/technology/products/database/application_express/ppt/
ODTUG2007_Managing_APEX.ppt

Designing Application for Performance and Scalability - Bjrn Engsig


http://www.oracle.com/technology/deploy/performance/pdf/
designing_applications_for_performance_and_scalability.pdf

Hotsos Webinars: http://portal.hotsos.com/events/webinars


Simple Strategies for Writing and Maintaining More Efficient SQL

Oracle Code Instrumentation or How I Learned to Stop Worrying and Love Properly Scoped Trace
Files
Using Oracle's PL/SQL Profiler Tool DBMS_PROFILER
How to tune SQL with Extended Trace Data

80 Copyright 2010 Sumneva - All Rights Reserved - http://sumneva.com - [email protected]


http://sumneva.com

81 Copyright 2010 Sumneva - All Rights Reserved - http://sumneva.com - [email protected]

You might also like