What’s New in Oracle Database 12c for PHP
-
Upload
cjorcl -
Category
Technology
-
view
134 -
download
2
description
Transcript of What’s New in Oracle Database 12c for PHP
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 1
What’s New in Oracle Database 12c for Scripting Languages
Christopher Jones, Oracle
Shoaib Lari, Oracle
September 2013
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 3
The following 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 © 2013, Oracle and/or its affiliates. All rights reserved. 4
Program Agenda
Three-slide Introduction to PHP OCI8
Useful Oracle Database 12c Features
PHP DTrace for Dynamic Tracing
Oracle/MySQL PHP Applications
PHP Performance and Scalability
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 5
Three-slide Introduction to PHP OCI8
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 6
Traditional PHP Script Processing
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 7
One of Many Modern PHP Architectures
PHP
Update
Queue Cache
Apache
PHP
OCI8 Extension
Oracle Libraries
PHP Web Service
DB
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 8
What is PHP OCI8?
Recommended Oracle Database extension for PHP
Supports many Oracle features
Available in PHP C source and binary bundles
PHP OCI8 2.0 "Development" is on http://pecl.php.net
$c = oci_connect('scott', 'tiger', 'localhost/pdborcl');
$s = oci_parse($c, 'SELECT * FROM employees');
oci_execute($s);
while (($row = oci_fetch_row($s)) != false)
foreach ($row as $item)
print $item;
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 9
Program Agenda
Three-slide Introduction to PHP OCI8
Useful Oracle Database 12c Features
PHP DTrace for Dynamic Tracing
Oracle/MySQL PHP Applications
PHP Performance and Scalability
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 10
Useful Oracle Database 12c Features
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 11
32K VARCHARs in Oracle Database 12c
SQL
CREATE TABLE vctab (vcdata VARCHAR2(32767));
PHP OCI8 does insert and fetch in one piece
$s = oci_parse($c, "INSERT INTO vctab (vcdata) VALUES (:bv)");
$bv = str_repeat('x', 32767);
oci_bind_by_name($s, ":bv", $bv);
oci_execute($s);
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 12
32K VARCHARs in Oracle Database 12c
CLOB vs VARCHAR2
$s = oci_parse($c,
'SELECT clobdata FROM ctab');
oci_execute($s);
$row = oci_fetch_assoc($s);
$result = $row['CLOBDATA']->load();
32K fetch times (very dependent on LOB storage, network speeds etc)
CLOB: 0.574 seconds
VARCHAR2: 0.279 seconds
$s = oci_parse($c,
'SELECT vcdata FROM vctab');
oci_execute($s);
$row = oci_fetch_assoc($s);
$result = $row['VCDATA'];
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 13
Oracle DB 12c SQL Row Limiting Clause
$sql = "SELECT employee_id, last_name FROM employees ORDER BY employee_id";
if ($oracleversion >= 12) {
$sql = $sql . ' OFFSET :offset ROWS FETCH NEXT :maxnumrows ROWS ONLY';
} else {
$sql = "SELECT * FROM (SELECT A.*, ROWNUM AS MY_RNUM FROM ($sql) A
WHERE ROWNUM <= :maxnumrows + :offset)
WHERE MY_RNUM > :offset";
}
$offset = 5;
$maxnumrows = 5;
$s = oci_parse($c, $sql);
oci_bind_by_name($s, ":offset", $offset, -1, SQLT_INT);
oci_bind_by_name($s, ":maxnumrows", $maxnumrows, -1, SQLT_INT);
oci_execute($s);
oci_fetch_all($s, $res);
105 Austin
106 Pataballa
107 Lorentz
108 Greenberg
109 Faviet
Or use row_number()
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 14
Oracle DB 12c IDENTITY Columns
ANSI auto increment syntax: CREATE TABLE t1 (c1 NUMBER GENERATED BY DEFAULT ON NULL AS IDENTITY,
c2 VARCHAR2(20));
In PHP: $s = oci_parse($c, "INSERT INTO t1 (c2) VALUES ('Alison')");
oci_execute($s);
$s = oci_parse($c, "INSERT INTO t1 (c1, c2) VALUES (NULL, 'Chris')");
oci_execute($s);
Table now contains: 1 Chris
2 Alison
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 15
Oracle DB 12c OCI oraaccess.xml Deployment Settings
New $TNS_ADMIN/oraaccess.xml deployment settings file
Client (i.e. PHP) side file for configuring OCI-based driver settings
Global and per-connection string parameters
Don't need to modify application to improve performance
Restart application after editing
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 16
Row Prefetching Refresher Temporary buffer cache for query duration
// First Fetch
$r = oci_fetch_row(…);
var_dump($r);
// array('1000','Roma');
OCI8
Extension
Oracle
Libraries
1000, Roma
1100, Venice
1200, Tokyo
. . .
1000, Roma
// Second Fetch
$r = oci_fetch_row(…);
var_dump($r);
// array('1100','Venice');
OCI8
Extension
Oracle
Libraries
1000, Roma
1100, Venice
1200, Tokyo
. . .
1100, Venice
No DB access
for second fetch
X
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 17
oraaccess.xml Prefetch Tuning
PHP code needing tuning: $s = oci_parse($c, "SELECT ...");
oci_execute($s);
oci_set_prefetch($s, 1); // application sets prefetch
while (($row = oci_fetch_row($s)) != false)
var_dump($row);
$TNS_ADMIN/oraaccess.xml snippet:
<prefetch>
<rows>1000</rows>
</prefetch
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 18
oraaccess.xml Prefetch Tuning
Pre-12c: Fetching 20000 rows with application prefetch 1
Time is: 5.822 seconds
With Oracle Database 12c $TNS_ADMIN/oraaccess.xml:
Fetching 20000 rows with application prefetch 1
Time is: 0.863 seconds
(Very dependent on network speeds etc)
See exhibition booth demo
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 19
Statement Caching Refresher
oci8.statement_cache_size = 20
1. “select col from tab”, <metadata>
2.
…
20.
1. “select col from tab”
2.
…
statement 1
select col from tab
select col from tab
select col from tab
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 20
oraaccess.xml Auto-tuning Statement Cache
Statement cache size monitored & updated in a cycle
– Cache size increases/decreases gradually
ram_threshold is max percentage of installed RAM
memory_target is absolute max size
Lesser of these two is used as the limit.
<auto_tune>
<enable>true</enable>
<ram_threshold>0.1</ram_threshold>
<memory_target>2M</memory_target>
</auto_tune>
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 21
oraaccess.xml Auto-tuning Statement Cache
for ($j = 0; $j < 10; ++$j) {
echo "Running workload\n";
for ($i = 0; $i < 30; ++$i)
do_query($c1, "SELECT $i FROM dual"); // 30 distinct queries
echo "Number of new parses for this session: ",
print_new_parse_count(), "\n";
}
PHP OCI8 default: oci8.statement_cache_size = 20
– So 30 sequential statements are never effectively cached
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 22
oraaccess.xml Auto-tuning Statement Cache
Pre-12c ...
Running workload
Number of new parses for this session: 30
Running workload
Number of new parses for this session: 30
...
Tune by manually monitoring web server performance, AWR byte transfers, reset oci8.statement_cache_size
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 23
oraaccess.xml Auto-tuning Statement Cache
Auto-tuned with Oracle Database 12c $TNS_ADMIN/oraaccess.xml:
...
Running workload
Number of new parses for this session: 30
Running workload
Number of new parses for this session: 0
Running workload
Number of new parses for this session: 0
...
See exhibition booth demo
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 24
Implicit Result Sets in PHP
$sql =
"DECLARE
c1 SYS_REFCURSOR;
BEGIN
OPEN c1 FOR SELECT city, postal_code FROM locations;
DBMS_SQL.RETURN_RESULT(c1);
OPEN c1 FOR SELECT * FROM employees;
DBMS_SQL.RETURN_RESULT(c1);
END;";
Needs PHP OCI8 2.0-devel from PECL
From 10gR2
– With Oracle Database 12c client and 12c server now uses ONS
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 25
Implicit Result Sets in PHP
Use standard query code:
$s = oci_parse($c, $sql);
oci_execute($s);
while (($row = oci_fetch_row($s))
!= false) {
foreach ($row as $item)
echo $item . " ";
echo "\n";
}
Roma 00989
Venice 10934
...
Mexico City 11932
100 Steven King SKING
101 Neena Kochhar NKOCHHAR
...
BEGIN
OPEN c1 FOR SELECT city, postal_code
FROM locations;
DBMS_SQL.RETURN_RESULT(c1);
OPEN c1 FOR SELECT * FROM employees;
DBMS_SQL.RETURN_RESULT(c1);
END;
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 26
Implicit Result Sets in PHP Example #2
Use oci_get_implicit_resultset() function in PHP OCI8 2.0
$s = oci_parse($c, $sql);
oci_execute($s);
while (($s_2 = oci_get_implicit_resultset($s))) {
for ($i = 1; $i <= oci_num_fields($s_2); ++$i)
echo oci_field_name($s_2, $i) . " "; // Use column names for headings
echo "\n";
while (($row = oci_fetch_row($s_2)) != false) {
foreach ($row as $item)
echo $item . " ";
echo "\n";
}
}
CITY POSTAL_CODE
Roma 00989
Venice 10934
...
EMPLOYEE_ID FIRST_NAME LAST_NAME EMAIL
100 Steven King SKING
101 Neena Kochhar NKOCHHAR
...
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 27
Program Agenda
Three-slide Introduction to PHP OCI8
Useful Oracle Database 12c Features
PHP DTrace for Dynamic Tracing
Oracle/MySQL PHP Applications
PHP Performance and Scalability
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 28
PHP DTrace for Dynamic Tracing on Oracle Linux
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 29
Dynamic Tracing Overview
Dynamic Tracing from Solaris ported to Oracle Linux's UEK3 kernel
"DTrace is a facility for the dynamic instrumentation of
production systems, for the purpose of troubleshooting and
analysis."
DTrace User Space Dynamic Tracing (USDT) now available
PHP source code is instrumented with “probes” if (DTRACE_OCI8_ERROR_ENABLED()) {
DTRACE_OCI8_ERROR((int)errstatus, (long)errcode);
}
PHP 5.4.20 & 5.5.4 –-enable-dtrace linking stabilized
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 30
DTrace User Space Dynamic Tracing (USDT)
Install Oracle Linux with UEK3 kernel and dtrace-utils
http://public-yum.oracle.com/beta/
For PHP, enable DTrace User Space Dynamic Tracing (USDT) # modprobe fasttrap
# chmod 666 /dev/dtrace/helper
Build PHP 5.4.20 or PHP 5.5.4 and install PHP OCI8 2.0 as a shared
library from PECL # ./configure --enable-dtrace ...
# make && make install
# PHP_DTRACE=yes pecl install oci8-devel
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 31
DTrace User Space Dynamic Tracing (USDT)
Show probes available in PHP OCI8:
# dtrace -l -m oci8.so
...
18 php9559 oci8.so php_oci_do_connect oci8-connect-entry
23 php9559 oci8.so php_oci_do_connect oci8-connect-return
24 php9559 oci8.so php_oci_do_connect_ex oci8-connect-type
25 php9559 oci8.so php_oci_error oci8-error
26 php9559 oci8.so php_oci_statement_execute oci8-execute-mode
...
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 32
DTrace User Space Dynamic Tracing (USDT)
Write tracing scripts in D, e.g. trace.d: #!/usr/sbin/dtrace -Zqs
php*:::oci8-connect-entry
{ printf("%lld: PHP connect-entry\n", walltimestamp);
printf("\t credentials %s@%s\n“,arg0 ? copyinstr(arg0) : "",
arg1 ? copyinstr(arg1) : "");
printf("\t charset %s\n", arg2 ? copyinstr(arg2) : "");
printf("\t session_mode %ld : \n", (long)arg3);
printf("persistent %d : ", (int)arg4);
printf("exclusive %d\n", (int)arg5);
}
...
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 33
DTrace User Space Dynamic Tracing (USDT)
Run trace.d # ./trace.d
Run a PHP script $ php oci8.php
Beijing
Bern
Bombay
Geneva
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 34
DTrace User Space Dynamic Tracing (USDT)
# ./trace.d
1379702722173349580: PHP connect-entry
credentials cj@localhost/pdborcl
charset
session_mode 0 : persistent 0 : exclusive 1
1379702722258590635: PHP oci8-connect-return
connection 0x7fccdc1c2828
1379702722259141543: PHP oci8-sqltext
connection 0x7fccdc1c2828
sql select city from locations where rownum < 5 order by 1
1379702722259240438: PHP oci8-execute-mode
connection 0x7fccdc1c2828
mode 0x20
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 35
Program Agenda
Three-slide Introduction to PHP OCI8
Useful Oracle Database 12c Features
PHP DTrace for Dynamic Tracing
Oracle/MySQL PHP Applications
PHP Performance and Scalability
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 36
Oracle/MySQL PHP Applications
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 37
Oracle Database Driver for MySQL Applications
Deployment Process:
– Migrate Schema and Data
– Build Application with the
Driver
– Translate SQL
– Test and Tune to Leverage
Oracle Database Features
libmysqlclient
MySQL DB Oracle DB
liboramysql
OCI
Application using
MySQL’s C API
Application using
MySQL’s C API
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 38
Build Application with the Driver
One method of re-linking with the new 12c Driver:
– Build PHP mysql extension(s) with MySQL Connector/C
# ./configure --with-mysql=/usr ...
# make && make install
– Create a symlink to the Oracle driver library:
# ln –s $ORACLE_HOME/lib/liboramysql12.so $ORACLE_HOME/lib/libmysql.so
# export LD_LIBRARY_PATH=$ORACLE_HOME/lib
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 39
Build Application with the Driver
Another method of re-linking with the new 12c Driver:
– Use a Connector/C emulator:
# cd $HOME
# $INSTANTCLIENTDIR/sdk/demo/setuporamysql.sql
# ./configure --with-mysql=$HOME/oramysql ...
# make && make installs
(Other methods exist too)
Restart PHP # service httpd start
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 40
Translate SQL
Change connect string: mysql_connect("localhost/pdborcl", "scott", "tiger");
Change SQL manually or use an Oracle Database 12c SQL
Translation Profile:
– MySQL syntax:
$sql = "SELECT * FROM mytab LIMIT 5,10";
– Oracle ANSI syntax:
$sql = "SELECT * FROM mytab OFFSET 5 ROWS FETCH NEXT 10 ROWS ONLY";
Run the Application
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 41
Program Agenda
Three-slide Introduction to PHP OCI8
Useful Oracle Database 12c Features
PHP DTrace for Dynamic Tracing
Oracle/MySQL PHP Applications
PHP Performance and Scalability
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 42
PHP Performance and Scalability
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 43
Scaling up with DRCP Connection Pooling
5000 users, DRCP pool size of 100
Dedicated Server Processes
5000 x 4 MB +
5000 x 400 KB +
0 =
21 GB
DB Processes
Session Memory
DRCP Broker
Total
100 x 4 MB +
100 x 400 KB +
5000 x 35 KB =
610 MB PHP DB PHP DB
DRCP Server Processes
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 44
DRCP Connection Pooling
Use DRCP for short lived connections by same DB user
Using DRCP in PHP 5.3+ with Oracle 11g+:
– Start the Pool:
SQL> EXECUTE DBMS_CONNECTION_POOL.START_POOL();
– Set oci8.connection_class in php.ini
oci8.connection_class = MY_PHP_APP
– Add "POOLED" to the connect string:
$c = oci_pconnect('scott', 'tiger', 'myhost/sales:pooled');
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 45
DRCP Connection Pooling Benchmark
2GB RAM
1 connection broker
100 pooled servers
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 46
Client Identifiers for Auditing and Monitoring
Set client identifier in PHP after connection
session_start();
$c = oci_pconnect('phpuser', 'welcome', 'localhost/orcl');
if (authenticate_web_user()) {
oci_set_client_identifier($c, $_SESSION['app_user_name']); // e.g. 'Chris'
. . .
} else {
trigger_error(. . .);
}
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 47
Client Identifiers for Auditing
APP_USERNAME USERNAME EXTENDED_TIMESTAMP ACTION_NAME
------------- ----------- ----------------------------------- -----------
Chris PHPUSER 16-AUG-13 12.25.42.846153 PM -07:00 SELECT
Alison PHPUSER 16-AUG-13 12.25.50.870773 PM -07:00 SELECT
Details in an OTN article
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 49
Client Identifiers for Monitoring
Client Identifier is visible in views and in Enterprise Manager
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 53
Oracle Client and Server Result Caches
CREATE TABLE SALES (...) RESULT_CACHE;
Results of queries from small tables can be cached
Caches automatically invalidated by server data changes
– If no roundtrip within defined time, cache is assumed stale
Configure globally in DB or at client in sqlnet.ora
– CLIENT_RESULT_CACHE_SIZE or OCI_RESULT_CACHE_MAX_SIZE
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 54
Other Oracle DB Features for High Performance Applications
Bind Variables
Transactions – don’t auto commit unnecessarily
Advanced Queuing
– Move slower processing out of HTTP request/response cycle
Fast Application Notification
– Handle DB errors without timeouts
– Improves reconnection behavior
– Needs Oracle DB 12c client libraries for Oracle DB 12c
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 55
Other Oracle DB Features for High Performance Applications
Edition Based Redefinition
– Online PL/SQL Upgrades
– Useful for A/B testing
Continuous Query Notification
– Can use for cache invalidation
DBMS_XA
– Stop/restart transaction in different HTTP requests
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 56
Resources
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 57
Resources
http://blogs.oracle.com/opal: Blog, e.g. Implicit Result Sets, DTrace
http://www.oracle.com/technetwork/topics/php: OTN PHP Dev Center
http://tinyurl.com/phporacle: The Underground PHP & Oracle Manual
http://tinyurl.com/drcpphp: DRCP Connection Pooling Whitepaper
http://tinyurl.com/phpaudit: PHP Web Auditing, Authorization and
Monitoring with Oracle Database
Demo Pod SL-033 (back left of Moscone South)
“Application Performance, Scalability, and Availability with Oracle
Database 12c” (CON8855) 5:15pm Marriott Marquis - Golden Gate B
Email: [email protected] Twitter: @ghrd
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 58
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 59
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 60
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.