SlideShare una empresa de Scribd logo
1 de 40
Descargar para leer sin conexión
What’s new in the
                           PHP Driver (1.3.0)


                             Hannes Magnusson, 10gen
                                     bjori@10gen.com
                                               @bjori
                                 November 15th, 2012


Thursday, 15 November 12
About me


     • Hannes / @bjori
     • Icelandic
        – Oslo, Norway
        – London, England
        – San Francisco, USA
     • PHP Contributor
     • PHP Driver Engineer
              » @10gen
                                      3

Thursday, 15 November 12
Agenda



     • Removed not-so-cool stuff
     • New cool stuff



     • Connection handling / Replica Sets
           – Write Concerns
           – Read Preferences



Thursday, 15 November 12
Removed stuff




Thursday, 15 November 12
Pooling



     •   Bye bye!
     •   MongoPool::*()
     •   Mongo->poolDebug();
     •   Mongo->get/setPoolSize();

           – Replaced by one persistent connection per
                • host:port;replicaSetName;credentials;pid combo



                                                                   6

Thursday, 15 November 12
Deprecated



     •   Mongo->connectUtil()
     •   Mongo->get/setSlaveOkay()
     •   Mongo->last/prev/reset/forceError()
     •   Mongo->switchSlave()




                                               7

Thursday, 15 November 12
New stuff




Thursday, 15 November 12
MongoClient !!



     • Acknowledged writes by default! o/o/
     • No deprecated methods
       – Old Mongo class now extends MongoClient
         and adds back the old behaviour and
         methods




                                                   9

Thursday, 15 November 12
• $mongoCollection->aggregate()
     • $mongoCollection->findAndModify()
     • TTL Collections

                           $mongoCollection->ensureIndex(
                               array("dateField" => 1),
                               array("expireAfterSeconds" => 3600)
                           );




                                                                     10

Thursday, 15 November 12
Aggregation Framework




                $ops = array(
                    array(
                        '$project' => array(
                            "author" => 1,
                            "tags"   => 1,
                        )
                    ),
                    array('$unwind' => '$tags'),
                    array(
                        '$group' => array(
                            "_id" => array("tags" => '$tags'),
                            "authors" => array('$addToSet' => '$author'),
                        ),
                    ),
                );
                $results = $collection->aggregate($ops);




                                                                            11

Thursday, 15 November 12
New cool stuff



     • ReadPreferences
     • WriteConcerns
     • Connection handling




                                            12

Thursday, 15 November 12
What does the driver do?




                                           Its responsibilities
                                  Connection handling/failover




Thursday, 15 November 12
The Driver


     • Full C level client library, no external dependencies
        – Connection handling
        – Memory usage reported by PHP (almost)
        – Connection handling
        – MongoDB Wire protocol (OP_[CRUD], KILL_CURSOR)
        – Connection handling
        – Authentication
        – Connection handling
     • BSON serialization
     • Connection handling
     • Command wrappers/helpers
     • Connection handling
                                                               14

Thursday, 15 November 12
Replica Sets




                           Establishing connections




Thursday, 15 November 12
Replica Set – Configuration Options


      > conf = {
        _id : "mySet",
        members : [
           {_id : 0, host : "Node1”, tags : {"dc": "us"}},
           {_id : 1, host : "Node2", priority : 20, tags : {"dc": "is"}},
           {_id : 2, host : "Node3”, priority : 30, tags : {"dc": "is"}},
           {_id : 3, host : "Node4", hidden : true},
           {_id : 4, host : "Node5", hidden : true, slaveDelay : 3600}
         ]
      }

      > rs.initiate(conf)


Thursday, 15 November 12
Replica Set – Configuration Options


      > conf = {
        _id : "mySet",                                Primary DC

        members : [
           {_id : 0, host : "Node1”, tags : {"dc": "us"}},
           {_id : 1, host : "Node2", priority : 20, tags : {"dc": "is"}},
           {_id : 2, host : "Node3”, priority : 30, tags : {"dc": "is"}},
           {_id : 3, host : "Node4", hidden : true},
           {_id : 4, host : "Node5", hidden : true, slaveDelay : 3600}
         ]
      }

      > rs.initiate(conf)


Thursday, 15 November 12
Replica Set – Configuration Options


      > conf = {
                                                      Secondary DC
        _id : "mySet",
                                                      Default priority = 1
        members : [
           {_id : 0, host : "Node1”, tags : {"dc": "us"}},
           {_id : 1, host : "Node2", priority : 20, tags : {"dc": "is"}},
           {_id : 2, host : "Node3”, priority : 30, tags : {"dc": "is"}},
           {_id : 3, host : "Node4", hidden : true},
           {_id : 4, host : "Node5", hidden : true, slaveDelay : 3600}
         ]
      }

      > rs.initiate(conf)


Thursday, 15 November 12
Replica Set – Configuration Options


      > conf = {
        _id : "mySet",                                Analytics node
        members : [
           {_id : 0, host : "Node1”, tags : {"dc": "us"}},
           {_id : 1, host : "Node2", priority : 20, tags : {"dc": "is"}},
           {_id : 2, host : "Node3”, priority : 30, tags : {"dc": "is"}},
           {_id : 3, host : "Node4", hidden : true},
           {_id : 4, host : "Node5", hidden : true, slaveDelay : 3600}
         ]
      }

      > rs.initiate(conf)


Thursday, 15 November 12
Replica Set – Configuration Options


      > conf = {
        _id : "mySet",
        members : [
           {_id : 0, host : "Node1”, tags : {"dc": "us"}},
           {_id : 1, host : "Node2", priority : 20, tags : {"dc": "is"}},
           {_id : 2, host : "Node3”, priority : 30, tags : {"dc": "is"}},
           {_id : 3, host : "Node4", hidden : true},
           {_id : 4, host : "Node5", hidden : true, slaveDelay : 3600}
         ]
      }
                                                      Backup node

      > rs.initiate(conf)


Thursday, 15 November 12
Replica Set - Creation




                 Node 1                       Node 2




            Node 4               Node 3             Node 5




Thursday, 15 November 12
Replica Set - Initialize




                                   RS Init



                 Node 1                         Node 2




            Node 4                Node 3              Node 5




Thursday, 15 November 12
Replica Set - Initializing




                 Node 1                          Node 2
                                  Heartbeat
                                  Election



            Node 4                 Node 3               Node 5




Thursday, 15 November 12
Replica Set - Initialized




                Node 1                          Node 2
               Secondary                       Secondary



            Node 4                Node 3               Node 5
            (hidden)              Primary              (hidden)




Thursday, 15 November 12
Replica Set - Driver view



                                   Driver




                Node 1                          Node 2
               Secondary                       Secondary



                                   Node 3
                                   Primary




Thursday, 15 November 12
Connecting to Replica Set

             <?php
             $servers = "mongodb://Node1,Node3";
             $options = array(
                 "replicaSet" => "mySet",
             );
             $m = new MongoClient($servers, $options);
             ?>


               • Connect to Node1
                    – send `ismaster` then `ping`
               • Connect to Node3...
               • Topology discovery
                    – Match hostnames & Replica Set names
                    – Verify the seedlist
                    – Discover more nodes
                    – Connect to Node2...
                                                            26

Thursday, 15 November 12
Connections



     • Each unique connection string
                • host:port;replicaSetName;user/pass/db;pid
     • Once per process
     • Closed & Cleaned up during shutdown
           – Please don’t close connections manually :)




                                                              27

Thursday, 15 November 12
Read Preference




                                          Secondary reads
                           Prioritise servers / datacenters




Thursday, 15 November 12
Replica Set - Default only primary



                                    Driver




                Node 1                          Node 2
               Secondary                       Secondary



                                   Node 3
                                   Primary




Thursday, 15 November 12
Read Preferences


         • Only read from primary
         • Read from secondaries
         • Read from specific secondaries
         • Only read from secondaries when primary
           down
         • Don’t care, just the nearest one
         • Preferably node with a given tag


                                                     30

Thursday, 15 November 12
Read Preferences


         • Modes (readPreference)
             – primary, primaryPreferred
             – secondary, secondaryPreferred
             – nearest

         • Tag Sets (readPreferenceTags)
             – Uses Replica Set tags
             – Passed Tag is used to find matching members




                                                             31

Thursday, 15 November 12
Detecting failures / failovers



     • Runs `ping` every 5 seconds
         (mongo.ping_interval)

     • Runs `ismaster` every 60 seconds
         (mongo.is_master_interval)

     • Server/connection failure/force close
           –   rs.stepDown()
           –   service mongod stop
           –   Query failure
           –   ...

                                                            32

Thursday, 15 November 12
Read Preference
                                      +
                                  Failovers



                              No primary available




Thursday, 15 November 12
Replica Set - all well



                                 Driver




                Node 1                         Node 2
               Secondary                      Secondary



                                 Node 3
                                 Primary




Thursday, 15 November 12
Replica Set



                            Driver




                Node 1                    Node 2
               Secondary                 Secondary



                            Node 3
                            Primary




Thursday, 15 November 12
Read Preferences


          <?php
          $servers = "mongodb://Node1,Node2,Node3";
          $options = array(
              "replicaSet"         => "mySet",
              "readPreference"     => "primaryPreferred",
              "readPreferenceTagS" => "dc:is",
          );
          $m = new MongoClient($servers, $options);
          ?>


     • Read from Primary if available
         • Otherwise from a secondary in Iceland


                                                            36

Thursday, 15 November 12
WriteConcerns




                           How much do you love your data?
                             (not actually new, but still cool)




Thursday, 15 November 12
Write Preference



     • Unacknowledged (w=0)
     • Acknowledged (w=1)
     • Wait for replication (w=2+)
     • Wait for replication to tagset (w=string)
     • Wait for journal sync (j=1)




Thursday, 15 November 12
Write Preference



              <?php

              $examples = $mongo->test->example;
              $data = array("Hello" => "World");
              $examples->insert($data, array("w" => 2));
              $examples->insert($data, array("w" => "is"));

              ?>




       • w=majority
         • (replicate to the majority of the RS)


Thursday, 15 November 12
New Connection handling
                           Read Preferences
                Acknowledged writes by default

                            RC2 released last Monday...
                            RC3 this coming Monday...
                            Final .. 2weeks?




Thursday, 15 November 12
download at mongodb.org
                                   We’re Hiring !
                                 bjori@10gen.com   @bjori



                conferences, appearances, and meetups
                            http://www.10gen.com/events



            Facebook |                 Twitter       | LinkedIn
         http://bit.ly/mongofb        @mongodb      http://linkd.in/joinmongo




Thursday, 15 November 12

Más contenido relacionado

La actualidad más candente

Replication and Replica Sets
Replication and Replica SetsReplication and Replica Sets
Replication and Replica Sets
MongoDB
 
Morphia: Simplifying Persistence for Java and MongoDB
Morphia:  Simplifying Persistence for Java and MongoDBMorphia:  Simplifying Persistence for Java and MongoDB
Morphia: Simplifying Persistence for Java and MongoDB
Jeff Yemin
 
Kicking ass with redis
Kicking ass with redisKicking ass with redis
Kicking ass with redis
Dvir Volk
 
groovy rules
groovy rulesgroovy rules
groovy rules
Paul King
 

La actualidad más candente (20)

Redis in Practice: Scenarios, Performance and Practice with PHP
Redis in Practice: Scenarios, Performance and Practice with PHPRedis in Practice: Scenarios, Performance and Practice with PHP
Redis in Practice: Scenarios, Performance and Practice with PHP
 
Mongodb workshop
Mongodb workshopMongodb workshop
Mongodb workshop
 
Replication and Replica Sets
Replication and Replica SetsReplication and Replica Sets
Replication and Replica Sets
 
Caching and tuning fun for high scalability
Caching and tuning fun for high scalabilityCaching and tuning fun for high scalability
Caching and tuning fun for high scalability
 
MongoDB + Java - Everything you need to know
MongoDB + Java - Everything you need to know MongoDB + Java - Everything you need to know
MongoDB + Java - Everything you need to know
 
Django cryptography
Django cryptographyDjango cryptography
Django cryptography
 
Riak at The NYC Cloud Computing Meetup Group
Riak at The NYC Cloud Computing Meetup GroupRiak at The NYC Cloud Computing Meetup Group
Riak at The NYC Cloud Computing Meetup Group
 
Kickin' Ass with Cache-Fu (without notes)
Kickin' Ass with Cache-Fu (without notes)Kickin' Ass with Cache-Fu (without notes)
Kickin' Ass with Cache-Fu (without notes)
 
Morphia: Simplifying Persistence for Java and MongoDB
Morphia:  Simplifying Persistence for Java and MongoDBMorphia:  Simplifying Persistence for Java and MongoDB
Morphia: Simplifying Persistence for Java and MongoDB
 
Kickin' Ass with Cache-Fu (with notes)
Kickin' Ass with Cache-Fu (with notes)Kickin' Ass with Cache-Fu (with notes)
Kickin' Ass with Cache-Fu (with notes)
 
Beyond php - it's not (just) about the code
Beyond php - it's not (just) about the codeBeyond php - it's not (just) about the code
Beyond php - it's not (just) about the code
 
Kicking ass with redis
Kicking ass with redisKicking ass with redis
Kicking ass with redis
 
Redis SoCraTes 2014
Redis SoCraTes 2014Redis SoCraTes 2014
Redis SoCraTes 2014
 
Redis basics
Redis basicsRedis basics
Redis basics
 
MongoDB 在盛大大数据量下的应用
MongoDB 在盛大大数据量下的应用MongoDB 在盛大大数据量下的应用
MongoDB 在盛大大数据量下的应用
 
phptek13 - Caching and tuning fun tutorial
phptek13 - Caching and tuning fun tutorialphptek13 - Caching and tuning fun tutorial
phptek13 - Caching and tuning fun tutorial
 
Distributed systems at ok.ru #rigadevday
Distributed systems at ok.ru #rigadevdayDistributed systems at ok.ru #rigadevday
Distributed systems at ok.ru #rigadevday
 
Beyond PHP - It's not (just) about the code
Beyond PHP - It's not (just) about the codeBeyond PHP - It's not (just) about the code
Beyond PHP - It's not (just) about the code
 
groovy rules
groovy rulesgroovy rules
groovy rules
 
Gpu programming with java
Gpu programming with javaGpu programming with java
Gpu programming with java
 

Similar a What's New in the PHP Driver

MongoSV Schema Workshop
MongoSV Schema WorkshopMongoSV Schema Workshop
MongoSV Schema Workshop
MongoDB
 
Python utan-stodhjul-motorsag
Python utan-stodhjul-motorsagPython utan-stodhjul-motorsag
Python utan-stodhjul-motorsag
niklal
 

Similar a What's New in the PHP Driver (20)

Use Your MySQL Knowledge to Become a MongoDB Guru
Use Your MySQL Knowledge to Become a MongoDB GuruUse Your MySQL Knowledge to Become a MongoDB Guru
Use Your MySQL Knowledge to Become a MongoDB Guru
 
2013 london advanced-replication
2013 london advanced-replication2013 london advanced-replication
2013 london advanced-replication
 
Replication
ReplicationReplication
Replication
 
Replication MongoDB Days 2013
Replication MongoDB Days 2013Replication MongoDB Days 2013
Replication MongoDB Days 2013
 
Advanced Replication
Advanced ReplicationAdvanced Replication
Advanced Replication
 
Replication and Replica Sets
Replication and Replica SetsReplication and Replica Sets
Replication and Replica Sets
 
MongoSV Schema Workshop
MongoSV Schema WorkshopMongoSV Schema Workshop
MongoSV Schema Workshop
 
Gradle build tool that rocks with DSL JavaOne India 4th May 2012
Gradle build tool that rocks with DSL JavaOne India 4th May 2012Gradle build tool that rocks with DSL JavaOne India 4th May 2012
Gradle build tool that rocks with DSL JavaOne India 4th May 2012
 
Mongo db php_shaken_not_stirred_joomlafrappe
Mongo db php_shaken_not_stirred_joomlafrappeMongo db php_shaken_not_stirred_joomlafrappe
Mongo db php_shaken_not_stirred_joomlafrappe
 
NoSQL Infrastructure - Late 2013
NoSQL Infrastructure - Late 2013NoSQL Infrastructure - Late 2013
NoSQL Infrastructure - Late 2013
 
MongoDB London 2013: Basic Replication in MongoDB presented by Marc Schwering...
MongoDB London 2013: Basic Replication in MongoDB presented by Marc Schwering...MongoDB London 2013: Basic Replication in MongoDB presented by Marc Schwering...
MongoDB London 2013: Basic Replication in MongoDB presented by Marc Schwering...
 
Latinoware
LatinowareLatinoware
Latinoware
 
Python utan-stodhjul-motorsag
Python utan-stodhjul-motorsagPython utan-stodhjul-motorsag
Python utan-stodhjul-motorsag
 
Webinar: Replication and Replica Sets
Webinar: Replication and Replica SetsWebinar: Replication and Replica Sets
Webinar: Replication and Replica Sets
 
Redis the better NoSQL
Redis the better NoSQLRedis the better NoSQL
Redis the better NoSQL
 
About Data::ObjectDriver
About Data::ObjectDriverAbout Data::ObjectDriver
About Data::ObjectDriver
 
Deploying Plone and Volto, the Hard Way
Deploying Plone and Volto, the Hard WayDeploying Plone and Volto, the Hard Way
Deploying Plone and Volto, the Hard Way
 
veracruz
veracruzveracruz
veracruz
 
veracruz
veracruzveracruz
veracruz
 
veracruz
veracruzveracruz
veracruz
 

Más de MongoDB

Más de MongoDB (20)

MongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
MongoDB SoCal 2020: Migrate Anything* to MongoDB AtlasMongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
MongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
 
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!
 
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
 
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDBMongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB
 
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...
 
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series DataMongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data
 
MongoDB SoCal 2020: MongoDB Atlas Jump Start
 MongoDB SoCal 2020: MongoDB Atlas Jump Start MongoDB SoCal 2020: MongoDB Atlas Jump Start
MongoDB SoCal 2020: MongoDB Atlas Jump Start
 
MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]
MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]
MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]
 
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2
 
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...
 
MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!
MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!
MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!
 
MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your Mindset
MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your MindsetMongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your Mindset
MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your Mindset
 
MongoDB .local San Francisco 2020: MongoDB Atlas Jumpstart
MongoDB .local San Francisco 2020: MongoDB Atlas JumpstartMongoDB .local San Francisco 2020: MongoDB Atlas Jumpstart
MongoDB .local San Francisco 2020: MongoDB Atlas Jumpstart
 
MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...
MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...
MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...
 
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++MongoDB .local San Francisco 2020: Aggregation Pipeline Power++
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++
 
MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...
MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...
MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...
 
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep Dive
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep DiveMongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep Dive
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep Dive
 
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & Golang
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & GolangMongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & Golang
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & Golang
 
MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...
MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...
MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...
 
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...
 

Último

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Último (20)

Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 

What's New in the PHP Driver

  • 1. What’s new in the PHP Driver (1.3.0) Hannes Magnusson, 10gen bjori@10gen.com @bjori November 15th, 2012 Thursday, 15 November 12
  • 2. About me • Hannes / @bjori • Icelandic – Oslo, Norway – London, England – San Francisco, USA • PHP Contributor • PHP Driver Engineer » @10gen 3 Thursday, 15 November 12
  • 3. Agenda • Removed not-so-cool stuff • New cool stuff • Connection handling / Replica Sets – Write Concerns – Read Preferences Thursday, 15 November 12
  • 5. Pooling • Bye bye! • MongoPool::*() • Mongo->poolDebug(); • Mongo->get/setPoolSize(); – Replaced by one persistent connection per • host:port;replicaSetName;credentials;pid combo 6 Thursday, 15 November 12
  • 6. Deprecated • Mongo->connectUtil() • Mongo->get/setSlaveOkay() • Mongo->last/prev/reset/forceError() • Mongo->switchSlave() 7 Thursday, 15 November 12
  • 8. MongoClient !! • Acknowledged writes by default! o/o/ • No deprecated methods – Old Mongo class now extends MongoClient and adds back the old behaviour and methods 9 Thursday, 15 November 12
  • 9. • $mongoCollection->aggregate() • $mongoCollection->findAndModify() • TTL Collections $mongoCollection->ensureIndex( array("dateField" => 1), array("expireAfterSeconds" => 3600) ); 10 Thursday, 15 November 12
  • 10. Aggregation Framework $ops = array(     array(         '$project' => array(             "author" => 1,             "tags"   => 1,         )     ),     array('$unwind' => '$tags'),     array(         '$group' => array(             "_id" => array("tags" => '$tags'),             "authors" => array('$addToSet' => '$author'),         ),     ), ); $results = $collection->aggregate($ops); 11 Thursday, 15 November 12
  • 11. New cool stuff • ReadPreferences • WriteConcerns • Connection handling 12 Thursday, 15 November 12
  • 12. What does the driver do? Its responsibilities Connection handling/failover Thursday, 15 November 12
  • 13. The Driver • Full C level client library, no external dependencies – Connection handling – Memory usage reported by PHP (almost) – Connection handling – MongoDB Wire protocol (OP_[CRUD], KILL_CURSOR) – Connection handling – Authentication – Connection handling • BSON serialization • Connection handling • Command wrappers/helpers • Connection handling 14 Thursday, 15 November 12
  • 14. Replica Sets Establishing connections Thursday, 15 November 12
  • 15. Replica Set – Configuration Options > conf = { _id : "mySet", members : [ {_id : 0, host : "Node1”, tags : {"dc": "us"}}, {_id : 1, host : "Node2", priority : 20, tags : {"dc": "is"}}, {_id : 2, host : "Node3”, priority : 30, tags : {"dc": "is"}}, {_id : 3, host : "Node4", hidden : true}, {_id : 4, host : "Node5", hidden : true, slaveDelay : 3600} ] } > rs.initiate(conf) Thursday, 15 November 12
  • 16. Replica Set – Configuration Options > conf = { _id : "mySet", Primary DC members : [ {_id : 0, host : "Node1”, tags : {"dc": "us"}}, {_id : 1, host : "Node2", priority : 20, tags : {"dc": "is"}}, {_id : 2, host : "Node3”, priority : 30, tags : {"dc": "is"}}, {_id : 3, host : "Node4", hidden : true}, {_id : 4, host : "Node5", hidden : true, slaveDelay : 3600} ] } > rs.initiate(conf) Thursday, 15 November 12
  • 17. Replica Set – Configuration Options > conf = { Secondary DC _id : "mySet", Default priority = 1 members : [ {_id : 0, host : "Node1”, tags : {"dc": "us"}}, {_id : 1, host : "Node2", priority : 20, tags : {"dc": "is"}}, {_id : 2, host : "Node3”, priority : 30, tags : {"dc": "is"}}, {_id : 3, host : "Node4", hidden : true}, {_id : 4, host : "Node5", hidden : true, slaveDelay : 3600} ] } > rs.initiate(conf) Thursday, 15 November 12
  • 18. Replica Set – Configuration Options > conf = { _id : "mySet", Analytics node members : [ {_id : 0, host : "Node1”, tags : {"dc": "us"}}, {_id : 1, host : "Node2", priority : 20, tags : {"dc": "is"}}, {_id : 2, host : "Node3”, priority : 30, tags : {"dc": "is"}}, {_id : 3, host : "Node4", hidden : true}, {_id : 4, host : "Node5", hidden : true, slaveDelay : 3600} ] } > rs.initiate(conf) Thursday, 15 November 12
  • 19. Replica Set – Configuration Options > conf = { _id : "mySet", members : [ {_id : 0, host : "Node1”, tags : {"dc": "us"}}, {_id : 1, host : "Node2", priority : 20, tags : {"dc": "is"}}, {_id : 2, host : "Node3”, priority : 30, tags : {"dc": "is"}}, {_id : 3, host : "Node4", hidden : true}, {_id : 4, host : "Node5", hidden : true, slaveDelay : 3600} ] } Backup node > rs.initiate(conf) Thursday, 15 November 12
  • 20. Replica Set - Creation Node 1 Node 2 Node 4 Node 3 Node 5 Thursday, 15 November 12
  • 21. Replica Set - Initialize RS Init Node 1 Node 2 Node 4 Node 3 Node 5 Thursday, 15 November 12
  • 22. Replica Set - Initializing Node 1 Node 2 Heartbeat Election Node 4 Node 3 Node 5 Thursday, 15 November 12
  • 23. Replica Set - Initialized Node 1 Node 2 Secondary Secondary Node 4 Node 3 Node 5 (hidden) Primary (hidden) Thursday, 15 November 12
  • 24. Replica Set - Driver view Driver Node 1 Node 2 Secondary Secondary Node 3 Primary Thursday, 15 November 12
  • 25. Connecting to Replica Set <?php $servers = "mongodb://Node1,Node3"; $options = array( "replicaSet" => "mySet", ); $m = new MongoClient($servers, $options); ?> • Connect to Node1 – send `ismaster` then `ping` • Connect to Node3... • Topology discovery – Match hostnames & Replica Set names – Verify the seedlist – Discover more nodes – Connect to Node2... 26 Thursday, 15 November 12
  • 26. Connections • Each unique connection string • host:port;replicaSetName;user/pass/db;pid • Once per process • Closed & Cleaned up during shutdown – Please don’t close connections manually :) 27 Thursday, 15 November 12
  • 27. Read Preference Secondary reads Prioritise servers / datacenters Thursday, 15 November 12
  • 28. Replica Set - Default only primary Driver Node 1 Node 2 Secondary Secondary Node 3 Primary Thursday, 15 November 12
  • 29. Read Preferences • Only read from primary • Read from secondaries • Read from specific secondaries • Only read from secondaries when primary down • Don’t care, just the nearest one • Preferably node with a given tag 30 Thursday, 15 November 12
  • 30. Read Preferences • Modes (readPreference) – primary, primaryPreferred – secondary, secondaryPreferred – nearest • Tag Sets (readPreferenceTags) – Uses Replica Set tags – Passed Tag is used to find matching members 31 Thursday, 15 November 12
  • 31. Detecting failures / failovers • Runs `ping` every 5 seconds (mongo.ping_interval) • Runs `ismaster` every 60 seconds (mongo.is_master_interval) • Server/connection failure/force close – rs.stepDown() – service mongod stop – Query failure – ... 32 Thursday, 15 November 12
  • 32. Read Preference + Failovers No primary available Thursday, 15 November 12
  • 33. Replica Set - all well Driver Node 1 Node 2 Secondary Secondary Node 3 Primary Thursday, 15 November 12
  • 34. Replica Set Driver Node 1 Node 2 Secondary Secondary Node 3 Primary Thursday, 15 November 12
  • 35. Read Preferences <?php $servers = "mongodb://Node1,Node2,Node3"; $options = array( "replicaSet" => "mySet", "readPreference" => "primaryPreferred", "readPreferenceTagS" => "dc:is", ); $m = new MongoClient($servers, $options); ?> • Read from Primary if available • Otherwise from a secondary in Iceland 36 Thursday, 15 November 12
  • 36. WriteConcerns How much do you love your data? (not actually new, but still cool) Thursday, 15 November 12
  • 37. Write Preference • Unacknowledged (w=0) • Acknowledged (w=1) • Wait for replication (w=2+) • Wait for replication to tagset (w=string) • Wait for journal sync (j=1) Thursday, 15 November 12
  • 38. Write Preference <?php $examples = $mongo->test->example; $data = array("Hello" => "World"); $examples->insert($data, array("w" => 2)); $examples->insert($data, array("w" => "is")); ?> • w=majority • (replicate to the majority of the RS) Thursday, 15 November 12
  • 39. New Connection handling Read Preferences Acknowledged writes by default RC2 released last Monday... RC3 this coming Monday... Final .. 2weeks? Thursday, 15 November 12
  • 40. download at mongodb.org We’re Hiring ! bjori@10gen.com @bjori conferences, appearances, and meetups http://www.10gen.com/events Facebook | Twitter | LinkedIn http://bit.ly/mongofb @mongodb http://linkd.in/joinmongo Thursday, 15 November 12