What’s new in the                           PHP Driver (1.3.0)                             Hannes Magnusson, 10gen        ...
About me     • Hannes / @bjori     • Icelandic        – Oslo, Norway        – London, England        – San Francisco, USA ...
Agenda     • Removed not-so-cool stuff     • New cool stuff     • Connection handling / Replica Sets           – Write Con...
Removed stuffThursday, 15 November 12
Pooling     •   Bye bye!     •   MongoPool::*()     •   Mongo->poolDebug();     •   Mongo->get/setPoolSize();           – ...
Deprecated     •   Mongo->connectUtil()     •   Mongo->get/setSlaveOkay()     •   Mongo->last/prev/reset/forceError()     ...
New stuffThursday, 15 November 12
MongoClient !!     • Acknowledged writes by default! o/o/     • No deprecated methods       – Old Mongo class now extends ...
• $mongoCollection->aggregate()     • $mongoCollection->findAndModify()     • TTL Collections                           $m...
Aggregation Framework                $ops = array(                    array(                        $project => array(    ...
New cool stuff     • ReadPreferences     • WriteConcerns     • Connection handling                                        ...
What does the driver do?                                           Its responsibilities                                  C...
The Driver     • Full C level client library, no external dependencies        – Connection handling        – Memory usage ...
Replica Sets                           Establishing connectionsThursday, 15 November 12
Replica Set – Configuration Options      > conf = {        _id : "mySet",        members : [           {_id : 0, host : "N...
Replica Set – Configuration Options      > conf = {        _id : "mySet",                                Primary DC       ...
Replica Set – Configuration Options      > conf = {                                                      Secondary DC     ...
Replica Set – Configuration Options      > conf = {        _id : "mySet",                                Analytics node   ...
Replica Set – Configuration Options      > conf = {        _id : "mySet",        members : [           {_id : 0, host : "N...
Replica Set - Creation                 Node 1                       Node 2            Node 4               Node 3         ...
Replica Set - Initialize                                   RS Init                 Node 1                         Node 2  ...
Replica Set - Initializing                 Node 1                          Node 2                                  Heartbe...
Replica Set - Initialized                Node 1                          Node 2               Secondary                   ...
Replica Set - Driver view                                   Driver                Node 1                          Node 2  ...
Connecting to Replica Set             <?php             $servers = "mongodb://Node1,Node3";             $options = array( ...
Connections     • Each unique connection string                • host:port;replicaSetName;user/pass/db;pid     • Once per ...
Read Preference                                          Secondary reads                           Prioritise servers / da...
Replica Set - Default only primary                                    Driver                Node 1                        ...
Read Preferences         • Only read from primary         • Read from secondaries         • Read from specific secondaries...
Read Preferences         • Modes (readPreference)             – primary, primaryPreferred             – secondary, seconda...
Detecting failures / failovers     • Runs `ping` every 5 seconds         (mongo.ping_interval)     • Runs `ismaster` every...
Read Preference                                      +                                  Failovers                         ...
Replica Set - all well                                 Driver                Node 1                         Node 2        ...
Replica Set                            Driver                Node 1                    Node 2               Secondary     ...
Read Preferences          <?php          $servers = "mongodb://Node1,Node2,Node3";          $options = array(             ...
WriteConcerns                           How much do you love your data?                             (not actually new, but...
Write Preference     • Unacknowledged (w=0)     • Acknowledged (w=1)     • Wait for replication (w=2+)     • Wait for repl...
Write Preference              <?php              $examples = $mongo->test->example;              $data = array("Hello" => ...
New Connection handling                           Read Preferences                Acknowledged writes by default          ...
download at mongodb.org                                   We’re Hiring !                                 bjori@10gen.com  ...
Upcoming SlideShare
Loading in …5
×

What's New in the PHP Driver

1,355 views

Published on

Interested in learning more about MongoDB? Sign up for MongoSV, the largest annual user conference dedicated to MongoDB. Learn more at MongoSV.com

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,355
On SlideShare
0
From Embeds
0
Number of Embeds
433
Actions
Shares
0
Downloads
10
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

What's New in the PHP Driver

  1. 1. What’s new in the PHP Driver (1.3.0) Hannes Magnusson, 10gen bjori@10gen.com @bjori November 15th, 2012Thursday, 15 November 12
  2. 2. About me • Hannes / @bjori • Icelandic – Oslo, Norway – London, England – San Francisco, USA • PHP Contributor • PHP Driver Engineer » @10gen 3Thursday, 15 November 12
  3. 3. Agenda • Removed not-so-cool stuff • New cool stuff • Connection handling / Replica Sets – Write Concerns – Read PreferencesThursday, 15 November 12
  4. 4. Removed stuffThursday, 15 November 12
  5. 5. Pooling • Bye bye! • MongoPool::*() • Mongo->poolDebug(); • Mongo->get/setPoolSize(); – Replaced by one persistent connection per • host:port;replicaSetName;credentials;pid combo 6Thursday, 15 November 12
  6. 6. Deprecated • Mongo->connectUtil() • Mongo->get/setSlaveOkay() • Mongo->last/prev/reset/forceError() • Mongo->switchSlave() 7Thursday, 15 November 12
  7. 7. New stuffThursday, 15 November 12
  8. 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 9Thursday, 15 November 12
  9. 9. • $mongoCollection->aggregate() • $mongoCollection->findAndModify() • TTL Collections $mongoCollection->ensureIndex( array("dateField" => 1), array("expireAfterSeconds" => 3600) ); 10Thursday, 15 November 12
  10. 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); 11Thursday, 15 November 12
  11. 11. New cool stuff • ReadPreferences • WriteConcerns • Connection handling 12Thursday, 15 November 12
  12. 12. What does the driver do? Its responsibilities Connection handling/failoverThursday, 15 November 12
  13. 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 14Thursday, 15 November 12
  14. 14. Replica Sets Establishing connectionsThursday, 15 November 12
  15. 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. 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. 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. 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. 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. 20. Replica Set - Creation Node 1 Node 2 Node 4 Node 3 Node 5Thursday, 15 November 12
  21. 21. Replica Set - Initialize RS Init Node 1 Node 2 Node 4 Node 3 Node 5Thursday, 15 November 12
  22. 22. Replica Set - Initializing Node 1 Node 2 Heartbeat Election Node 4 Node 3 Node 5Thursday, 15 November 12
  23. 23. Replica Set - Initialized Node 1 Node 2 Secondary Secondary Node 4 Node 3 Node 5 (hidden) Primary (hidden)Thursday, 15 November 12
  24. 24. Replica Set - Driver view Driver Node 1 Node 2 Secondary Secondary Node 3 PrimaryThursday, 15 November 12
  25. 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... 26Thursday, 15 November 12
  26. 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 :) 27Thursday, 15 November 12
  27. 27. Read Preference Secondary reads Prioritise servers / datacentersThursday, 15 November 12
  28. 28. Replica Set - Default only primary Driver Node 1 Node 2 Secondary Secondary Node 3 PrimaryThursday, 15 November 12
  29. 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 30Thursday, 15 November 12
  30. 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 31Thursday, 15 November 12
  31. 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 – ... 32Thursday, 15 November 12
  32. 32. Read Preference + Failovers No primary availableThursday, 15 November 12
  33. 33. Replica Set - all well Driver Node 1 Node 2 Secondary Secondary Node 3 PrimaryThursday, 15 November 12
  34. 34. Replica Set Driver Node 1 Node 2 Secondary Secondary Node 3 PrimaryThursday, 15 November 12
  35. 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 36Thursday, 15 November 12
  36. 36. WriteConcerns How much do you love your data? (not actually new, but still cool)Thursday, 15 November 12
  37. 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. 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. 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. 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/joinmongoThursday, 15 November 12

×