what's new in the php driver

Download What's New in the PHP Driver

Post on 25-May-2015

1.103 views

Category:

Technology

2 download

Embed Size (px)

DESCRIPTION

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

TRANSCRIPT

  • 1. Whats new in the PHP Driver (1.3.0) Hannes Magnusson, 10gen bjori@10gen.com @bjori November 15th, 2012Thursday, 15 November 12

2. About me Hannes / @bjori Icelandic Oslo, Norway London, England San Francisco, USA PHP Contributor PHP Driver Engineer @10gen3Thursday, 15 November 12 3. Agenda Removed not-so-cool stuff New cool stuff Connection handling / Replica Sets Write Concerns Read PreferencesThursday, 15 November 12 4. Removed stuffThursday, 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 6Thursday, 15 November 12 6. Deprecated Mongo->connectUtil() Mongo->get/setSlaveOkay() Mongo->last/prev/reset/forceError() Mongo->switchSlave() 7Thursday, 15 November 12 7. New stuffThursday, 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 9Thursday, 15 November 12 9. $mongoCollection->aggregate() $mongoCollection->findAndModify() TTL Collections $mongoCollection->ensureIndex( array("dateField" => 1), array("expireAfterSeconds" => 3600) ); 10Thursday, 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);11Thursday, 15 November 12 11. New cool stuff ReadPreferences WriteConcerns Connection handling12Thursday, 15 November 12 12. What does the driver do? Its responsibilitiesConnection handling/failoverThursday, 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 14Thursday, 15 November 12 14. Replica Sets Establishing connectionsThursday, 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 DCmembers : [ {_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 = 1members : [ {_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 nodemembers : [ {_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 2Node 4 Node 3 Node 5Thursday, 15 November 12 21. Replica Set - Initialize RS Init Node 1 Node 2Node 4Node 3Node 5Thursday, 15 November 12 22. Replica Set - Initializing Node 1Node 2HeartbeatElectionNode 4 Node 3 Node 5Thursday, 15 November 12 23. Replica Set - InitializedNode 1Node 2 Secondary SecondaryNode 4Node 3 Node 5(hidden)Primary(hidden)Thursday, 15 November 12 24. Replica Set - Driver view DriverNode 1Node 2 Secondary Secondary Node 3 PrimaryThursday, 15 November 12 25. Connecting to Replica Set 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. Connections Each unique connection string host:port;replicaSetName;user/pass/db;pid Once per process Closed & Cleaned up during shutdown Please dont close connections manually :)27Thursday, 15 November 12 27. Read PreferenceSecondary reads Prioritise servers / datacentersThursday, 15 November 12 28. Replica Set - Default only primaryDriverNode 1Node 2 Secondary Secondary Node 3 PrimaryThursday, 15 November 12 29. Read Preferences Only read from primary Read from secondaries Read from specific secondaries Only read from secondaries when primary down Dont care, just the nearest one Preferably node with a given tag 30Thursday, 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 31Thursday, 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 ...32Thursday, 15 November 12 32. Read Preference+FailoversNo primary availableThursday, 15 November 12 33. Replica Set - all well DriverNode 1 Node 2 SecondarySecondary Node 3 PrimaryThursday, 15 November 12 34. Replica SetDriverNode 1Node 2 Secondary SecondaryNode 3PrimaryThursday, 15 November 12 35. Read Preferences Read from Primary if available Otherwise from a secondary in Iceland36Thursday, 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 w=majority (replicate to the majority of the RS)Thursday, 15 November 12 39. New Connection handling Read PreferencesAcknowledged writes by defaultRC2 released last Monday...RC3 this coming Monday...Final .. 2weeks?Thursday, 15 November 12 40. download at mongodb.org Were Hiring ! bjori@10gen.com @bjoriconferences, appearances, and meetupshttp://www.10gen.com/eventsFacebook | Twitter | LinkedIn http://bit.ly/mongofb@mongodbhttp://linkd.in/joinmongoThursday, 15 November 12