<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
<channel>
    <title>PHP and Oracle: Christopher Jones</title>
  <link>https://blogs.oracle.com/opal/</link>
      
    <description>Notes on the Oracle PHP Apache Linux ("OPAL") stack, with bits of Python, Perl and Ruby for good luck</description>
  <language>en-us</language>
  <copyright>Copyright 2013</copyright>
  <lastBuildDate>Fri, 31 May 2013 18:08:16 +0000</lastBuildDate>
    <generator>Apache Roller BLOGS401ORA4 (20120329084749)</generator>
        <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/ChristopherJonesOnPython" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="christopherjonesonpython" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
    <guid isPermaLink="true">https://blogs.oracle.com/opal/entry/python_cx_oracle_and_oracle</guid>
    <title>Python cx_Oracle and Oracle 11g DRCP Connection Pooling</title>
    <dc:creator>cj</dc:creator>
    <link>https://blogs.oracle.com/opal/entry/python_cx_oracle_and_oracle</link>
        <pubDate>Thu, 21 Mar 2013 23:18:48 +0000</pubDate>
    <category>python</category>
    <category>connection</category>
    <category>database</category>
    <category>mod_python</category>
    <category>performance</category>
    <category>pool</category>
    <category>python</category>
            <description>&lt;p&gt;The topic of Oracle 11&lt;i&gt;g&lt;/i&gt; DRCP connection pooling in Python
cx_Oracle came up twice this week for me.  DRCP is a database tier
connection pooling solution which is great for applications run in
multiple processes.  There is a &lt;a
href="http://www.oracle.com/technetwork/topics/php/php-scalability-ha-twp-128842.pdf"
&gt;whitepaper on DRCP&lt;/a&gt; that covers a lot of background and talks
about configuration.  This whitepaper is ostensibly about PHP but is
good reading for all DRCP users.&lt;/p&gt;

&lt;p&gt;The first DRCP and cx_Oracle scenario I dealt with was a question
about mod_python.&lt;/p&gt;

&lt;p&gt;To cut a long story short, I created a handler and requested it
1000 times via Apache's 'ab' tool.  In my first script, and despite
having increased the default pool parameters, there were a high number
of NUM_WAITS.  Also NUM_AUTHENTICATIONS was high.  Performance wasn't
the best.  Querying V$CPOOL_CC_STATS showed:&lt;/p&gt;

&lt;pre&gt;
CCLASS_NAME  NUM_REQUESTS   NUM_HITS NUM_MISSES  NUM_WAITS NUM_AUTHENTICATIONS
------------ ------------ ---------- ---------- ---------- -------------------
HR.CJDEMO1           1000        992          8        478                1000
&lt;/pre&gt;

&lt;p&gt;At least the session information in each DRCP server was reused
(shown via a high NUM_HITS).&lt;/p&gt;

&lt;p&gt;Results were better after fixing the script to look like:&lt;/p&gt;

&lt;pre&gt;from mod_python import apache
import cx_Oracle
import datetime

# Example: Oracle 11g DRCP with cx_Oracle and mod_python

# These pool params are suitable for Apache Pre-fork MPM
mypool = cx_Oracle.SessionPool(user='hr', password='welcome',
         dsn='localhost/orcl:pooled', min=1, max=2, increment=1)

def handler(req):
    global mypool

    req.content_type = 'text/html'
    n = datetime.datetime.now()
    req.write (str(n) + "&amp;lt;br&amp;gt;");

    db = cx_Oracle.connect(user='hr', password='welcome',
            dsn='localhost/orcl:pooled', pool=mypool, cclass="CJDEMO1",
            purity=cx_Oracle.ATTR_PURITY_SELF)

    cur = db.cursor()
    cur.execute('select * from locations')
    resultset = cur.fetchall()
    for result in resultset:
        for item in result:
            req.write (str(item) + " ")
        req.write ("&amp;lt;br&amp;gt;")
    cur.close()
    mypool.release(db)

    return apache.OK
&lt;/pre&gt;

&lt;p&gt;The 'ab' benchmark on this script ran much faster and the stats
from V$CPOOL_CC_STATS looked much better. The number of
authentications was right down about to about 1 per Apache
(ie. mod_python) process:&lt;/p&gt;

&lt;pre&gt;
CCLASS_NAME  NUM_REQUESTS   NUM_HITS NUM_MISSES  NUM_WAITS NUM_AUTHENTICATIONS
------------ ------------ ---------- ---------- ---------- -------------------
HR.CJDEMO1           1000        977         23         13                  26
&lt;/pre&gt;

&lt;p&gt;The NUM_HITS was high again, because the DRCP purity was
ATTR_PURITY_SELF.  If I hadn't wanted session information to be reused
each time the handler was executed, I could have set the purity to
ATTR_PURITY_NEW.  If I'd done this then NUM_HITS would have been low
and NUM_MISSES would have been high.&lt;/p&gt;

&lt;p&gt;If you're testing this yourself, before restarting the DRCP pool
don't forget to shutdown Apache to close all DB connections. Otherwise
restarting the pool will block.  Also, if you're interpreting your
own V$CPOOL_CC_STATS stats don't forget to account for the DRCP
"dedicated optimization" that retains an association between clients
(mod_python processes) and the DB. The whitepaper previously mentioned
discusses this.&lt;/p&gt;

&lt;p&gt;The second place where DRCP and python came up this week was on
the cx_Oracle mail list. David Stanek &lt;a
href=http://sourceforge.net/mailarchive/message.php?msg_id=30629284"&gt;posed
a question&lt;/a&gt;. He was seeing application processes blocking while
waiting for a DRCP pooled server to execute a query.  My variant of
David's script is:&lt;/p&gt;

&lt;pre&gt;
import os
import time
import cx_Oracle

# Example: Sub-optimal connection pooling with Oracle 11g DRCP and cx_Oracle

def do_connection():
    print 'Starting do_connection ' + str(os.getpid())
    con = cx_Oracle.connect(user=user, password=pw, dsn=dsn, cclass="CJDEMO2",
           purity=cx_Oracle.ATTR_PURITY_SELF)
    cur = con.cursor()
    print 'Querying ' + str(os.getpid())
    cur.execute("select to_char(systimestamp) from dual")
    print cur.fetchall()
    cur.close()
    con.close()
    print 'Sleeping ' + str(os.getpid())
    time.sleep(30)
    print 'Finishing do_connection ' + str(os.getpid())
 
user = 'hr'
pw = 'welcome'
dsn = 'localhost/orcl:pooled'
for x in range(100):
    pid = os.fork()
    if not pid:
        do_connection()
        os._exit(0)
&lt;/pre&gt;

&lt;p&gt;This script forks off a bunch of processes - more than the number
of pooled DRCP servers (see MAXSIZE in the DBA_CPOOL_INFO view).  The
first few processes grab a DRCP server from the pool and do their
query.  But they don't release the DRCP server back to the DRCP pool
until after the sleep() when the process ends.  The other forked
processes are blocked waiting for those DRCP servers to become
available. This isn't optimal pool sharing.&lt;/p&gt;

&lt;p&gt;My suggestion was to use an explicit cx_Oracle session pool
like this:&lt;/p&gt;

&lt;pre&gt;
import os
import time
import cx_Oracle

# Example: Connection pooling with Oracle 11g DRCP and cx_Oracle
 
def do_connection():
    print 'Starting do_connection ' + str(os.getpid())
    mypool = cx_Oracle.SessionPool(user=user,password=pw,dsn=dsn,min=1,max=2,increment=1)
    con = cx_Oracle.connect(user=user, password=pw,
          dsn=dsn, pool = mypool, cclass="CJDEMO3", purity=cx_Oracle.ATTR_PURITY_SELF)
    cur = con.cursor()
    print 'Querying ' + str(os.getpid())
    cur.execute("select to_char(systimestamp) from dual")
    print cur.fetchall()
    cur.close()
    mypool.release(con)
    print 'Sleeping ' + str(os.getpid())
    time.sleep(30)
    print 'Finishing do_connection ' + str(os.getpid())

user = 'hr'
pw = 'welcome'
dsn = 'localhost/orcl:pooled'
for x in range(100):
    pid = os.fork()
    if not pid:
        do_connection()
        os._exit(0)
&lt;/pre&gt;

&lt;p&gt;The &lt;code&gt;mypool.release(con)&lt;/code&gt; call releases the DRCP server
back to the DRCP pool prior to the sleep. When this second script is
run, there is a smoothness to the output. The queries happen
sequentially without noticeably being blocked.&lt;/p&gt;

&lt;p&gt;Like with any shared resource, it is recommended to release DRCP
pooled servers back to the pool when they are no longer needed by the
application.&lt;/p&gt;</description>          </item>
    <item>
    <guid isPermaLink="true">https://blogs.oracle.com/opal/entry/cx_oracle_51_for_python_is_ava</guid>
    <title>cx_Oracle 5.1 for Python is Available</title>
    <dc:creator>cj</dc:creator>
    <link>https://blogs.oracle.com/opal/entry/cx_oracle_51_for_python_is_ava</link>
        <pubDate>Tue, 29 Mar 2011 19:21:52 +0000</pubDate>
    <category>python</category>
    <category>cx_oracle</category>
    <category>python</category>
    <category>release</category>
    <atom:summary type="html"> </atom:summary>        <description>Anthony Tuininga has released  the cx_Oracle 5.1 extension for Python.  His announcement email has the details: &lt;a href="http://mail.python.org/pipermail/python-announce-list/2011-March/008876.html"&gt;http://mail.python.org/pipermail/python-announce-list/2011-March/008876.html&lt;/a&gt;.</description>          </item>
    <item>
    <guid isPermaLink="true">https://blogs.oracle.com/opal/entry/fast_in-memory_caching_with_jr</guid>
    <title>Fast In-Memory Caching with JRuby &amp; Jython Using Oracle Coherence</title>
    <dc:creator>cj</dc:creator>
    <link>https://blogs.oracle.com/opal/entry/fast_in-memory_caching_with_jr</link>
        <pubDate>Mon, 6 Dec 2010 10:27:24 +0000</pubDate>
    <category>python</category>
    <category>cache</category>
    <category>coherence</category>
    <category>jruby</category>
    <category>jython</category>
    <atom:summary type="html"> </atom:summary>        <description>My Aussie colleage Pas Apicella has been evaluating JRuby &amp; Jython.
One test was using them to access &lt;a
href="http://www.oracle.com/technetwork/middleware/coherence/overview/index.html"&gt;Oracle
Coherence&lt;/a&gt;, a "replicated and distributed (partitioned) data
management and caching services on top of a reliable, highly scalable
peer-to-peer clustering protocol.". He blogged and shows code samples
&lt;a
href="http://theblasfrompas.blogspot.com/2010/12/access-coherence-cache-from-jythonjruby.html"
&gt;here&lt;/a&gt;.

</description>          </item>
    <item>
    <guid isPermaLink="true">https://blogs.oracle.com/opal/entry/cx_oracle_504_python_driver_fo</guid>
    <title>cx_Oracle 5.0.4 Python driver for Oracle Database Released</title>
    <dc:creator>cj</dc:creator>
    <link>https://blogs.oracle.com/opal/entry/cx_oracle_504_python_driver_fo</link>
        <pubDate>Wed, 28 Jul 2010 08:24:05 +0000</pubDate>
    <category>python</category>
    <category>announcement</category>
    <category>cx_oracle</category>
    <category>python</category>
    <atom:summary type="html"> </atom:summary>        <description>&lt;p&gt;Anthony Tuininga has released the cx_Oracle 5.0.4 Python driver for Oracle Database.&lt;/p&gt;&lt;p&gt;Details are in his &lt;a href="http://sourceforge.net/mailarchive/message.php?msg_name=AANLkTimUv_7XJ0lul-PC1r4wPyuXFlm28_SUb5-YaaJE%40mail.gmail.com"&gt;Sourceforge mail announcement&lt;/a&gt;.&lt;/p&gt;</description>          </item>
    <item>
    <guid isPermaLink="true">https://blogs.oracle.com/opal/entry/python_and_ruby_in_oracle_tuxe</guid>
    <title>Python and Ruby in Oracle Tuxedo</title>
    <dc:creator>cj</dc:creator>
    <link>https://blogs.oracle.com/opal/entry/python_and_ruby_in_oracle_tuxe</link>
        <pubDate>Tue, 18 May 2010 21:53:29 +0000</pubDate>
    <category>python</category>
    <category>python</category>
    <category>ruby</category>
    <category>tuxedo</category>
    <atom:summary type="html"> </atom:summary>        <description>&lt;p&gt;Did you know you can now develop services and applications in
Python or Ruby with Oracle Tuxedo?  The Tuxedo team have a blog post
about it at &lt;a
href="https://blogs.oracle.com/Tuxedo/entry/python_and_ruby_in_tuxedo"
&gt;Python and Ruby in Tuxedo&lt;/a&gt;.  I used to think of Tuxedo as a
Transaction Processing Monitor but it has evolved into much more.&lt;/p&gt;</description>          </item>
    <item>
    <guid isPermaLink="true">https://blogs.oracle.com/opal/entry/pyohio_python_in_ohio_25_26_ju_1</guid>
    <title>PyOhio - Python in Ohio, 25 &amp;amp; 26 July 2009</title>
    <dc:creator>cj</dc:creator>
    <link>https://blogs.oracle.com/opal/entry/pyohio_python_in_ohio_25_26_ju_1</link>
        <pubDate>Tue, 14 Jul 2009 09:29:41 +0000</pubDate>
    <category>python</category>
    <category>python</category>
    <atom:summary type="html"> </atom:summary>        <description>&lt;p&gt;&lt;a href="http://www.pyohio.org/Home"&gt;PyOhio&lt;/a&gt; "The Free Ohio-based Python Miniconference" is on Saturday &amp; Sunday July 25-26 at Ohio State University.  On Sunday &lt;a href="http://catherinedevlin.blogspot.com/"&gt;Catherine Devlin&lt;/a&gt; and Oracle Technology Network's Todd Trichler will have an Oracle/Python/Linux Tutorial.  This will have something interesting for everyone.  Even if you don't want to attend the tutorial fulltime, you can jump in for the bits important to you.&lt;/p&gt;&lt;p&gt;Want to learn more about Python and Oracle, or ask questions about best Python practices - then attend Catherine's Python section and ask questions.  Want to know what Oracle database is about to understand its possibilities - then attend the installation part.  Want to learn more about Linux and Virtualization - Todd is great on this.&lt;/p&gt;&lt;p&gt;Wish I was going. Send me a postcard!&lt;br/&gt;
&lt;/p&gt;</description>          </item>
    <item>
    <guid isPermaLink="true">https://blogs.oracle.com/opal/entry/python_cx_oracle_gets_database</guid>
    <title>Python cx_Oracle gets Database Change Notification Support</title>
    <dc:creator>cj</dc:creator>
    <link>https://blogs.oracle.com/opal/entry/python_cx_oracle_gets_database</link>
        <pubDate>Thu, 8 Jan 2009 14:58:03 +0000</pubDate>
    <category>python</category>
    <category>python</category>
    <atom:summary type="html"> </atom:summary>        <description>&lt;p&gt;Python's cx_Oracle gets &lt;a href="http://sourceforge.net/mailarchive/message.php?msg_name=703ae56b0901080742h703d0bf8g5a3db73868ccedba%40mail.gmail.com"&gt;Database Change Notification Support&lt;/a&gt;.&lt;/p&gt;</description>          </item>
    <item>
    <guid isPermaLink="true">https://blogs.oracle.com/opal/entry/new_python_cx_oracle_50</guid>
    <title>New Python cx_Oracle 5.0 </title>
    <dc:creator>cj</dc:creator>
    <link>https://blogs.oracle.com/opal/entry/new_python_cx_oracle_50</link>
        <pubDate>Wed, 17 Dec 2008 23:45:53 +0000</pubDate>
    <category>python</category>
    <category>python</category>
    <atom:summary type="html"> </atom:summary>        <description>&lt;p&gt;Now that &lt;a href="http://www.python.org/download/releases/3.0/"&gt;Python 3000&lt;/a&gt; has been released, Anthony Tuininga has announced cx_Oracle 5.0, the latest version of the extension for Oracle Database access.  His &lt;a href="http://sourceforge.net/mailarchive/forum.php?thread_name=703ae56b0812132016x7a8704bege82f323ea589bc14%40mail.gmail.com&amp;forum_name=cx-oracle-users"&gt;announcement email&lt;/a&gt; contains all the details. &lt;/p&gt;&lt;p&gt;Among the new features, it support Oracle 11g Connection Pooling (DRCP) fully now and allows the connection class to be set.  This enables maximum reuse of the Oracle pooled server processes by applications.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;</description>          </item>
    <item>
    <guid isPermaLink="true">https://blogs.oracle.com/opal/entry/python_cx_oracle_441_released</guid>
    <title>Python cx_Oracle 4.4.1 Released</title>
    <dc:creator>cj</dc:creator>
    <link>https://blogs.oracle.com/opal/entry/python_cx_oracle_441_released</link>
        <pubDate>Wed, 29 Oct 2008 10:42:12 +0000</pubDate>
    <category>python</category>
    <category>python</category>
    <atom:summary type="html"> </atom:summary>        <description>&lt;p&gt;Anthony Tuinga's released cx_Oracle 4.4.1 yesterday: &lt;a href="http://cx-oracle.sourceforge.net/"&gt;http://cx-oracle.sourceforge.net/&lt;/a&gt;.  Changes are &lt;a href="http://cx-oracle.sourceforge.net/HISTORY.txt"&gt;here&lt;/a&gt;.&lt;/p&gt;</description>          </item>
    <item>
    <guid isPermaLink="true">https://blogs.oracle.com/opal/entry/orapig_oracle_python_interface</guid>
    <title>OraPIG - Oracle Python Interface Generator Announced</title>
    <dc:creator>cj</dc:creator>
    <link>https://blogs.oracle.com/opal/entry/orapig_oracle_python_interface</link>
        <pubDate>Mon, 9 Jun 2008 17:52:57 +0000</pubDate>
    <category>python</category>
    <category>python</category>
    <atom:summary type="html"> </atom:summary>        <description>&lt;p&gt;Mark Harrison, from Pixar Animation Studios, recently announced the first release of "OraPig", which creates Python interfaces for PL/SQL packages.  The documentation is a good place to get an overview: http://www.markharrison.net/orapig/&lt;/p&gt;&lt;p&gt;The project itself is hosted at http://code.google.com/p/orapig/&lt;/p&gt;</description>          </item>
    <item>
    <guid isPermaLink="true">https://blogs.oracle.com/opal/entry/cx_oracle_433_for_python_is_ou</guid>
    <title>cx_Oracle 4.3.3 for Python is out</title>
    <dc:creator>cj</dc:creator>
    <link>https://blogs.oracle.com/opal/entry/cx_oracle_433_for_python_is_ou</link>
        <pubDate>Thu, 4 Oct 2007 16:02:32 +0000</pubDate>
    <category>python</category>
    <category>python</category>
    <atom:summary type="html"> </atom:summary>        <description>&lt;p&gt;The cx_Oracle 4.3.3 extension module for Python was released on Tuesday.&amp;nbsp; It is available on &lt;a href="http://cx-oracle.sourceforge.net/"&gt;Sourceforge&lt;/a&gt;. Source and RPMs for various versions of Python and Oracle are available. This is the first release that is available with 11&lt;span style="font-style: italic;"&gt;g&lt;/span&gt; support (though, of course, Oracle clients and databases of different releases can connect to each other).&lt;br&gt;&lt;/p&gt;</description>          </item>
    <item>
    <guid isPermaLink="true">https://blogs.oracle.com/opal/entry/scripting_for_documentation</guid>
    <title>Scripting for Documentation</title>
    <dc:creator>cj</dc:creator>
    <link>https://blogs.oracle.com/opal/entry/scripting_for_documentation</link>
        <pubDate>Thu, 26 Apr 2007 12:26:55 +0000</pubDate>
    <category>python</category>
    <category>python</category>
    <atom:summary type="html"> </atom:summary>        <description>&lt;p&gt;On his blog &lt;a href="http://tahitiviews.blogspot.com/"&gt;tahitiviews.blogspot.com&lt;/a&gt;, John Russell has posted a couple of exploratory articles on Python and Perl comparing them with PL/SQL. The observant person might recall that &lt;a href="http://tahiti.oracle.com/"&gt;tahiti.oracle.com&lt;/a&gt; is a front page to Oracle's Database, Application Server and Collaboration Suite documentation.&amp;nbsp; John does a lot of scripting magic with an ever changing set of manuals to build up an excellent online documentation system.&lt;/p&gt;</description>          </item>
  </channel>
</rss>
