Your SlideShare is downloading. ×
0
© 2008 Oracle Corporation
<Insert Picture Here>




Solving the C20K Problem:
Raising the Bar in PHP Scalability
Luxi Chidambaran, Consulting Member...
The following is intended to outline our general
            product direction. It is intended for information
           ...
Overview



       •    The C20K Requirement for the Database
       •    Oracle 11g Database Resident Connection Pool
   ...
The C20K Requirement for
            the Database




© 2008 Oracle Corporation
circa 2003: The C10K Problem

       • http://www.kegel.com/c10k.html
       • The web is a big place. Can web servers han...
circa 2005: Enter AJAX

       • High performance AJAX applications start pushing
         web server limits on persistent...
circa 2005: Shifting Tiers:
                             PHP and Database Connections
       • PHP likes the process model...
Running out of Ideas?

       •    Use Non Persistent Connections?
              • High connect times
              • Burn...
circa 2005: The C20K Requirement
                             on the Database
       • Can a database handle 20K connectio...
2007: Enter
            Oracle 11g Database
            Resident Connection Pooling
            (DRCP)




© 2008 Oracle C...
DRCP Overview

       •    Oracle Database 11g Feature
              • Not just for PHP
       •    Pool of dedicated serv...
Basic Functionality

       •    Pooling is optionally enabled by DBA on server
              • Min, Max, Timeout etc. for...
Dedicated Servers vs DRCP




                    No Connection Pooling   11g Database Resident Connection Pooling




© 2...
Sample Sizing for 5000 Clients
                                            Dedicated        Shared           DRCP
        ...
When to Use DRCP

       •    DRCP can be useful when any of the following apply:
              • Large number of connecti...
Starting and Configuring DRCP

       •        Start the pool:
              SQL> execute dbms_connection_pool.start_pool(...
DRCP: System Components

       •    Connection Broker
              •   New in Oracle Database 11g
              •   Orac...
DRCP: Connecting




© 2008 Oracle Corporation
DRCP: Doing Work




© 2008 Oracle Corporation
DRCP: After Disconnecting




© 2008 Oracle Corporation
DRCP: Pool Sharing

       • There is one physical pool in Oracle 11g
       • Connections are never shared across differe...
DRCP: Pool Sharing




© 2008 Oracle Corporation
Configuring DRCP for a Very
                             Large #Connections
       •    Bump up O/S file descriptor limits...
DRCP: Key Optimizations




© 2008 Oracle Corporation
DRCP: Key Optimizations

       •    No extra round-trips or hops
              • Connection request bundled with first wo...
2008:
            Connecting PHP to DRCP:
            The Enhanced OCI8
            Extension




© 2008 Oracle Corporation
What is OCI8?

        • Main Oracle Database extension for PHP
        • Open source and part of PHP

         <?php
    ...
Three Tier Web Model


                            Apache

                            PHP

                            OC...
Get the Latest OCI8

       •    php.net
              • Source code, Windows binaries
       •    PECL - PHP Extension Co...
Installation Steps for DRCP with PHP

       •        Install Oracle Database 11.1.0.6 (with one patch for
               ...
Using DRCP with PHP

       •    No application code change required
              • Unchanged PHP API
              • Dep...
Some DRCP Best Practices for PHP

       •    Close connections when doing non-DB processing
              • Allows DRCP t...
DRCP Demo




© 2008 Oracle Corporation
Non DRCP Performance




© 2008 Oracle Corporation
DRCP Performance




© 2008 Oracle Corporation
DRCP Benchmark




© 2008 Oracle Corporation
A DRCP Benchmark

       •    PHP script
              • connect, query, disconnect, sleep 1 second
       •    Server
   ...
PHP DRCP Benchmark - Throughput




                            (Throughput is executes per second)‫‏‬



© 2008 Oracle Co...
PHP DRCP Benchmark - Memory




© 2008 Oracle Corporation
Other OCI8 1.3 Changes

       • Fixed PHP OCI8 connection ref-counting edge cases
       • Better detection of dead sessi...
Horizontal Scalability with
            Oracle Database 11g Real
            Application Clusters (RAC)




© 2008 Oracle ...
RAC Architecture




© 2008 Oracle Corporation
DRCP on RAC

       • Horizontal scaling as your database load increases
       • N*C20K with N RAC nodes!!
       • DRCP ...
What about High Availability?

       •    Fast Application Notification (FAN)
       •    When DB node or network fails
 ...
Fast Application Notification

       • High Availability feature for PHP with RAC or Data
         Guard with physical st...
FAN Configuration

      •     Tell DB to broadcast FAN Events
            SQL> execute
             dbms_service.modify_s...
Oracle Resources

         •     Free Oracle Techology Network (OTN)‫‏‬
               PHP Developer Center
              ...
PHP Scalability and High
                             Availability Whitepaper
       •    Excellent introduction to PHP wi...
Oracle Technology Network
          PHP Developer Center
 •    Free
 •    Articles
 •    Install guides
 •    Underground ...
The preceding is intended to outline our general
            product direction. It is intended for information
           ...
© 2008 Oracle Corporation
Upcoming SlideShare
Loading in...5
×

Solving the C20K problem: Raising the bar in PHP Performance and Scalability

6,560

Published on

How do you configure and tune your PHP applications to handle 20,000
or more concurrent connections to your database on your desktop? This technical session describes how to implement and tune PHP's OCI8 extension with Oracle's Database Resident Connection Pool (DRCP).

Published in: Business, Technology
0 Comments
5 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
6,560
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
109
Comments
0
Likes
5
Embeds 0
No embeds

No notes for slide

Transcript of "Solving the C20K problem: Raising the bar in PHP Performance and Scalability"

  1. 1. © 2008 Oracle Corporation
  2. 2. <Insert Picture Here> Solving the C20K Problem: Raising the Bar in PHP Scalability Luxi Chidambaran, Consulting Member of Technical Staff, Oracle ZendCon, Sept 2008
  3. 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 remain at the sole discretion of Oracle. © 2008 Oracle Corporation
  4. 4. Overview • The C20K Requirement for the Database • Oracle 11g Database Resident Connection Pool • Connecting PHP to DRCP: Enhanced oci8 extension • DRCP Demo • Horizontal Scalability © 2008 Oracle Corporation
  5. 5. The C20K Requirement for the Database © 2008 Oracle Corporation
  6. 6. circa 2003: The C10K Problem • http://www.kegel.com/c10k.html • The web is a big place. Can web servers handle 20k connections on a commodity box? • 1GHz, 2GB RAM, 1Gb/s Ethernet • At 20,000 clients, that is: • [50KHz, 100KB RAM, and 50Kb/sec] per client • Postulation: More than enough to shove 4KB page/sec to each client © 2008 Oracle Corporation
  7. 7. circa 2005: Enter AJAX • High performance AJAX applications start pushing web server limits on persistent connections • Spurs thinking on newer web server architectures to support tens of thousands of connections © 2008 Oracle Corporation
  8. 8. circa 2005: Shifting Tiers: PHP and Database Connections • PHP likes the process model: single threaded • The web is a bigger place • There are more mid tier boxes • There are more and more PHP processes • There are more and more database connections • And it’s growing! • Mid-tier Connection pooling difficult in PHP • PHP processes can repeatedly connect/close OR • PHP processes can hold onto private connection © 2008 Oracle Corporation
  9. 9. Running out of Ideas? • Use Non Persistent Connections? • High connect times • Burns CPU • Throughput hits a wall on a commodity database box soon • Use Persistent Connections? • Majority idle • Excessive swapping, eventually exhausts RAM • Both strategies run into problems as we get into thousands of database connections • Of course, you could throw more hardware at it • Poor utilization of system resources • Poor utilization of $$ © 2008 Oracle Corporation
  10. 10. circa 2005: The C20K Requirement on the Database • Can a database handle 20K connections on a commodity box? • Challenging issue for database in terms of • Connection Management • Thread Management • Network I/O • State Management • Performance and Scalability © 2008 Oracle Corporation
  11. 11. 2007: Enter Oracle 11g Database Resident Connection Pooling (DRCP) © 2008 Oracle Corporation
  12. 12. DRCP Overview • Oracle Database 11g Feature • Not just for PHP • Pool of dedicated servers on database machine • Pool shared across mid-tier processes and middle-tier nodes • Scales to tens of thousands of persistent connections • Greatly speeds up non-persistent connections • Co-exists in all database server configurations • Single instance, RAC © 2008 Oracle Corporation
  13. 13. Basic Functionality • Pooling is optionally enabled by DBA on server • Min, Max, Timeout etc. for Pool • Client connect string: • hostname/service:POOLED • (SERVER=POOLED) • Client directed to Database Resident Pool • Pooled Server “locked” when connection requested by client • Pooled Server “released” back to pool when client disconnects © 2008 Oracle Corporation
  14. 14. Dedicated Servers vs DRCP No Connection Pooling 11g Database Resident Connection Pooling © 2008 Oracle Corporation
  15. 15. Sample Sizing for 5000 Clients Dedicated Shared DRCP Servers Servers Servers Database Servers 5000 * 4 MB 100 * 4 MB 100 * 4 MB Session Memory 5000 * 400 KB 5000 * 400 KB 100 * 400 KB DRCP Connection 5000 * 35 KB Broker Overhead Total Memory 21 GB 2.3 GB 610 MB © 2008 Oracle Corporation
  16. 16. When to Use DRCP • DRCP can be useful when any of the following apply: • Large number of connections need to be supported with minimum memory usage on database host • Applications mostly use same database credentials for all connections • Applications acquire a database connection, work on it for a relatively short duration, and then release it • Multiple web server hosts • Connections look identical in terms of session settings, for example date format settings and PL/SQL package state • Generally true for majority of web applications © 2008 Oracle Corporation
  17. 17. Starting and Configuring DRCP • Start the pool: SQL> execute dbms_connection_pool.start_pool(); • Optionally Configure the Pool: SQL> execute dbms_connection_pool.configure_pool( pool_name => 'SYS_DEFAULT_CONNECTION_POOL', minsize => 4, maxsize => 40, incrsize => 2, session_cached_cursors => 20, inactivity_timeout => 300, max_think_time => 600, max_use_session => 500000, max_lifetime_session => 86400); © 2008 Oracle Corporation
  18. 18. DRCP: System Components • Connection Broker • New in Oracle Database 11g • Oracle instance background daemon • Handles initial authentication • Handles subsequent connect/disconnect requests • Pooled Servers • New in Oracle Database 11g • Oracle instance background slave processes • Oracle 11g OCI Client library • DRCP aware © 2008 Oracle Corporation
  19. 19. DRCP: Connecting © 2008 Oracle Corporation
  20. 20. DRCP: Doing Work © 2008 Oracle Corporation
  21. 21. DRCP: After Disconnecting © 2008 Oracle Corporation
  22. 22. DRCP: Pool Sharing • There is one physical pool in Oracle 11g • Connections are never shared across different database usernames for security • CONNECTION_CLASS • Allows for multiple logical sub pools per user • Allows clients to identify the “type” of connection required • Only clients with same “username.connection_class” share connections © 2008 Oracle Corporation
  23. 23. DRCP: Pool Sharing © 2008 Oracle Corporation
  24. 24. Configuring DRCP for a Very Large #Connections • Bump up O/S file descriptor limits • E.g on Linux: /etc/security/limits.conf • oracle HARD NOFILE 40000 • Configuring additional brokers • Helps if O/S has a small per process file descriptor limit • dbms_connection_pool_alter_param • NUM_CBROK (default=1) • Configure the max number of connections per broker • Helps distribute connections across multiple brokers • dbms_connection_pool_alter_param • MAXCONN_CBROK (default=40,000) © 2008 Oracle Corporation
  25. 25. DRCP: Key Optimizations © 2008 Oracle Corporation
  26. 26. DRCP: Key Optimizations • No extra round-trips or hops • Connection request bundled with first work request • Broker not involved in processing work requests • Connection close request is asynchronous • Connection to Broker • Kept alive even after PHP “closes” the connection • Allows for faster re-connection • Optimization for low end (#clients < #pooled servers) • Behaves like dedicated servers at low end • Switches to pooled automatically at high end © 2008 Oracle Corporation
  27. 27. 2008: Connecting PHP to DRCP: The Enhanced OCI8 Extension © 2008 Oracle Corporation
  28. 28. What is OCI8? • Main Oracle Database extension for PHP • Open source and part of PHP <?php $c = oci_connect('un', 'pw', '//localhost/XE'); $s = oci_parse($c, 'select * from employees'); oci_execute($s); while ($row = oci_fetch_array($s))‫‏‬ foreach ($row as $item)‫‏‬ print $item; ?> © 2008 Oracle Corporation
  29. 29. Three Tier Web Model Apache PHP OCI8 Extension Oracle Client Libraries Web User Mid Tier Oracle Database 9iR2, 10g, 11g 8i, 9i, 10g, 11g Oracle Client Any platform Any platform © 2008 Oracle Corporation
  30. 30. Get the Latest OCI8 • php.net • Source code, Windows binaries • PECL - PHP Extension Community Library • Useful for updating PHP 4 with new OCI8 • oss.oracle.com/projects/php • RPMs for Linux with OCI8 and PDO_OCI © 2008 Oracle Corporation
  31. 31. Installation Steps for DRCP with PHP • Install Oracle Database 11.1.0.6 (with one patch for bug 6474441) • Download • PHP 5.3 (has OCI8 1.3) OR • PHP 4.3.9 – 5.2 and OCI8 1.3.4 from Pecl • Build PHP using Oracle 11g client libraries from ORACLE_HOME or Instant Client © 2008 Oracle Corporation
  32. 32. Using DRCP with PHP • No application code change required • Unchanged PHP API • Deployment decision to use DRCP • Application can still talk to other Oracle versions • Configure and start DRCP on Oracle Database 11g • Setup O/S file descriptor limits • Configure pool limits, timeouts, #brokers etc as required dbms_connection_pool.start_pool • Set php.ini parameters oci8.connection_class = MYAPP oci8.old_oci_close_semantics = Off (which is default) © 2008 Oracle Corporation
  33. 33. Some DRCP Best Practices for PHP • Close connections when doing non-DB processing • Allows DRCP to serve more clients with the same pool size • Explicitly control commits and rollbacks • Provides deterministic transaction behavior that is portable to older OCI8 versions • Setting oci8.connection_class • Ensure that applications under a connection_class have uniform session state expectations • Use the same oci8.connection_class value across machines hosting the same app to maximize DRCP sharing • With DRCP: LOGON triggers can fire multiple times • Still useful for setting session values like date formats • Monitor DRCP performance with V$CPOOL_STATS © 2008 Oracle Corporation
  34. 34. DRCP Demo © 2008 Oracle Corporation
  35. 35. Non DRCP Performance © 2008 Oracle Corporation
  36. 36. DRCP Performance © 2008 Oracle Corporation
  37. 37. DRCP Benchmark © 2008 Oracle Corporation
  38. 38. A DRCP Benchmark • PHP script • connect, query, disconnect, sleep 1 second • Server • Dual CPU Intel P4/Xeon 3.00GHz • 2GB RAM • 32bit Red Hat Enterprise Linux 4 • DRCP • 100 pooled servers, one connection broker • Clients • 3 similar machines • Apache • See PHP DRCP Whitepaper for details © 2008 Oracle Corporation
  39. 39. PHP DRCP Benchmark - Throughput (Throughput is executes per second)‫‏‬ © 2008 Oracle Corporation
  40. 40. PHP DRCP Benchmark - Memory © 2008 Oracle Corporation
  41. 41. Other OCI8 1.3 Changes • Fixed PHP OCI8 connection ref-counting edge cases • Better detection of dead sessions and bounced DBs • Automatic cleanup of dead, idle connections • Closing persistent connections can now rollback © 2008 Oracle Corporation
  42. 42. Horizontal Scalability with Oracle Database 11g Real Application Clusters (RAC) © 2008 Oracle Corporation
  43. 43. RAC Architecture © 2008 Oracle Corporation
  44. 44. DRCP on RAC • Horizontal scaling as your database load increases • N*C20K with N RAC nodes!! • DRCP starts on all RAC instances • Same pool limits apply to each individual RAC instance • min, max • number of brokers • max connections per broker • DRCP connections benefit from TNS Listener connection load balancing across RAC instances © 2008 Oracle Corporation
  45. 45. What about High Availability? • Fast Application Notification (FAN) • When DB node or network fails • Database generates FAN events • Oracle error returned without TCP timeout delay • PHP application is not blocked for TCP timeout – it can immediately reconnect to surviving DB instance $conn = doConnect(); $err = doSomeWork($conn); if (isConnectionError($err)) { // reconnect, find what was committed, and retry $conn = doConnect(); $err = checkApplicationStateAndContinueWork($conn); } if ($err) handleError($err); © 2008 Oracle Corporation
  46. 46. Fast Application Notification • High Availability feature for PHP with RAC or Data Guard with physical standby • Usable with or without DRCP • Available from Oracle 10gR2 • OCI8 1.3 supports FAN © 2008 Oracle Corporation
  47. 47. FAN Configuration • Tell DB to broadcast FAN Events SQL> execute dbms_service.modify_service(service_name =>'SALES', aq_ha_notifications =>TRUE); • Configure PHP's php.ini so OCI8 listens for FAN events oci8.events = On • Optionally add re-connection code to PHP application © 2008 Oracle Corporation
  48. 48. Oracle Resources • Free Oracle Techology Network (OTN)‫‏‬ PHP Developer Center otn.oracle.com/php • Underground PHP and Oracle Manual • Whitepapers, Articles, FAQs, links to blogs, Jdeveloper PHP Extension, PHP RPMs • Information christopher.jones@oracle.com blogs.oracle.com/opal • SQL and PL/SQL Questions asktom.oracle.com • ISVs and hardware vendors oraclepartnernetwork.oracle.com © 2008 Oracle Corporation
  49. 49. PHP Scalability and High Availability Whitepaper • Excellent introduction to PHP with DRCP and FAN • www.oracle.com/technology/tech/php/pdf/php-scalability-ha-twp.pdf © 2008 Oracle Corporation
  50. 50. Oracle Technology Network PHP Developer Center • Free • Articles • Install guides • Underground PHP and Oracle Manual • Online forum • PHP RPMs • Oracle JDeveloper 10g PHP extension otn.oracle.com/php © 2008 Oracle Corporation
  51. 51. 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 remain at the sole discretion of Oracle. © 2008 Oracle Corporation
  52. 52. © 2008 Oracle Corporation
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×