Zendcon Performance Oci8
Zendcon Performance Oci8
Apache
PHP
OCI8 Extension
Oracle Client
Libraries
• OCI8
• Stable and fast
• Has support for Oracle 11g DB Resident Connection
Pooling*
• PDO
• Time is coming rapidly, but perhaps not just yet
• Bugs for PDO and PDO_xxx (for various database
drivers) are outstanding
• PDO_OCI doesn't support all features of OCI8
• php.net
• Source code, Windows Binaries
• PECL - PHP Extension Community Library
• Useful for updating PHP4 with new OCI8
• oss.oracle.com/projects/php
• RPMs for Linux
• Zend Core for Oracle
• Linux, Solaris, Windows, AIX
Top DB Performance Mistakes
oc i_ con ne ct ()
oc i_ new _c on nec t()
oc i_ pco nn ec t()
Standard Connections
$c = oci _c on nec t($ use rn am e, $p ass wo rd, $ db nam e);
user:db:charset:privilege
hr:XE:ALU32UTF8:normal
system:XE:ALU32UTF8:sysdba
Round Trip
• Use oci_pconnect()
• Doesn't need to create new physical DB connection
Pass the Character Set
$c = oci _p co nne ct( $un , $p w, $d b, 'j a16 eu c' );
Could be improved
Environment Setting: Process
Environment
• Set NLS_DATE_FORMAT in environment
• All users get same format
• Application deployment now has dependency
on environment
• In Shell:
nl s_d at e_f or mat ='Y YY YM M DD HH 24 :MI :S S'
• PHP code:
fun cti on my _c onn ect ($ un, $ pw, $ db )
{
$c = o ci_ pc onn ect ($ un, $ pw, $ db );
retu rn $c ;
}
Environment Setting: Trigger
• PHP Code is
fun cti on my _c onn ect ($ un, $ pw, $ db )
{
$c = o ci_ pc onn ect ($ un, $ pw, $ db );
retu rn $c ;
}
LOGON Trigger
PHP Database
OCI8 Extension Oracle Client
Libraries
Beijing Beijing
Bern
Bombay
...
• php.ini
oci 8. de fau lt _pr efe tc h = 1 0
• Maximum number of rows in each DB "round trip"
• Memory limit also set: 1024 * oci8.default_prefetch
• Value can also be set inline
oc i_s et _p ref et ch( $s, 1 00) ;
• Improves query performance by reducing
“round trips”
• Rows are cached internally by Oracle
• no need to change application
OCI8 Prefetch Rows
$s = oci _p ars e( $c, 's el ect * fr om e mpl oy ees ') ;
oci _e xec ut e($ s) ;
oci _s et_ pr efe tc h($ s, 10 0);
whi le ($row = oc i_ fet ch_ ar ray ($ s) )
fore ac h ( $r ow as $i tem )
pr in t $ it em;
Statement Caching: No Bind
Variables
select col
from tab
where v = 1
select col
from tab
select col where v = 2
from tab
where v = 1
select col
from tab
select col where v = :bv
from tab
where v = :bv
• php.ini
oc i8. st ate me nt_ cac he _si ze = 20
• Unit is number of statements
• Client side cache of statements
• Moves cache management load from DB to PHP
side
• Reduces net traffic and context switches
• Uses memory on PHP side for cached statement
handles
• Uses memory on DB for per-session cursors
Oracle Database 11g Also Has . . .
• Saves a round-trip
• But can make code correctness harder
• oci_execute() for queries will commit
• Any DDL will commit
Non Transactional
• SQL_TRACE
• Log SQL statement execution
• TIMED_STATISTICS
• Gather timing information
• TKPROF
• Trace file formatter produces text report
Looking at TKPROF Output
• STATSPACK
• SQL scripts taking snapshot of DB performance
• Reports parsing, caching, IO, latches, . . .
New Skool Tuning
New Skool Tools
…
FINDING 1: 100% impact (494 seconds)
Significant virtual memory paging was detected on the host operating system.
RECOMMENDATION 1: Host Configuration, 100% benefit (494 seconds)
ACTION: Host operating system was experiencing significant paging but
no particular root cause could be detected. Investigate processes that
do not belong to this instance running on the host that are consuming
significant amount of virtual memory. Also consider adding more
physical memory to the host.
FINDING 2: 75% impact (369 seconds)
SQL statements consuming significant database time were found.
RECOMMENDATION 1: SQL Tuning, 21% benefit (101 seconds)
ACTION: Investigate the SQL statement with SQL_ID "cfz686a6qp0kg" for
possible performance improvements.
RELEVANT OBJECT: SQL statement with SQL_ID cfz686a6qp0kg and
PLAN_HASH 3679656590
select o.obj#, u.name, o.name, t.spare1,
Benchmark During Development