Superficial mongo db

27

Click here to load reader

Transcript of Superficial mongo db

Page 1: Superficial mongo db

Superficial MongoDB

[email protected]

Page 2: Superficial mongo db

MongoDB NoSQL

Document

BSON

Page 3: Superficial mongo db

Document-Oriented Storage Full Index Support

Replication & High Availability

Auto Sharding Querying Fast In-Place Updates Map/Reduce GridFS

Page 4: Superficial mongo db

Document-Oriented Storage Full Index Support

Replication & High Availability

Auto Sharding Querying Fast In-Place Updates Map/Reduce GridFS

Page 5: Superficial mongo db

Document-Oriented > db.users.insert( { _id : "alex", name: { first:"Alex", last:"Benisson" }, karma : 1.0 } )

> db.posts.findOne() { _id : ObjectId("4e77bb3b8a3e000000004f7a"), when : Date("2011-09-19T02:10:11.3Z", author : "alex", title : "No Free Lunch", text : "This is the text of the post. It could be very long.", tags : [ "business", "ramblings" ], votes : 5, voters : [ "jane", "joe", "spencer", "phyllis", "li" ], comments : [ { who : "jane", when : Date("2011-09-19T04:00:10.112Z"), comment : "I agree." }, { who : "meghan", when : Date("2011-09-20T14:36:06.958Z"), comment : "You must be joking. etc etc ..." } ] }

Page 6: Superficial mongo db

Full-Index Support > db.things.ensureIndex({j:1});

> db.things.ensureIndex({"address.city": 1})

> db.things.ensureIndex({j:1, name:-1});

> db.factories.insert( { name: "xyz", metro: { city: "New York", state: "NY" } } ); > db.factories.ensureIndex( { metro : 1 } ); // this query can use the above index: > > db.factories.find( { metro: { city: "New York", state: "NY" } } ); // this one too, as {city:"New York"} < {city:"New York",state:"NY"} > db.factories.find( { metro: { $gte : { city: "New York" } } } ); // this query does not match the document because the order of fields is significant > db.factories.find( { metro: { state: "NY" , city: "New York" } } );

Page 7: Superficial mongo db

Replication Asynchronous Replication

Page 8: Superficial mongo db

HA & FailOver Only Write to Primary Can read from Secondary

Op Ordinal: Increasing ordinal to represent each operation

Using Server ID + Op Ordinal

Page 9: Superficial mongo db

Picking Primary 1. Get Max LocalOpOrdinal from each Server 2. if a majority of servers are not up (from this server's POV), remain in Secondary mode and stop. 3. if the last op time seems very old, stop and await human intervention. 4. else, using a consensus protocol, pick the server with the highest maxLocalOpOrdinal as the Primary.

Page 10: Superficial mongo db

TIPs.

Page 11: Superficial mongo db

Use 64bit Machine MongoDB Use Memory-Mapped File

In 32bit. DB Size can’t over 2.5GB

MongoDB is needed Big Memory

Page 12: Superficial mongo db

Use Replica Set Use Replica Set and Journaling

Page 13: Superficial mongo db

Use Lastest Version 2.0.2 is better than 1.8.x

MongoDB has global Lock

1.8.x uses global Write Lock 2.0.x uses write with yield.

Not supports db or collection lock

Page 14: Superficial mongo db

Use Big Memory Disk Op is slower than Memory Op

Page 15: Superficial mongo db

Shard

Page 16: Superficial mongo db

Shard Architecture

Page 17: Superficial mongo db

Basic

Replication unit is chunk.

Chunk: 64mb or 100,000 objects

Chunk Count > 9

Data is split up into Chunks

Page 18: Superficial mongo db

Mongod

Replica Set(3 mongod)

Data Store

Page 19: Superficial mongo db

Mongos

StateLess

Routing to Shard

Proxy

Page 20: Superficial mongo db

Mongod configSvr

Can’t use Replica Set or M/A

1(test) or 3(real)

mongod

Page 21: Superficial mongo db

Mongod configSvr

Changes are made with 2PC

If any are down, meta data goes read only

System is online as long as 1/3 is up

Page 22: Superficial mongo db

Use Scale Up than Sharding

Difficult to find good Shard Key.

Not Support Data Center awareness Add memory and hdd, ssd

Page 23: Superficial mongo db

Object Id_

Page 24: Superficial mongo db

Object Id_

12 bytes

Page 25: Superficial mongo db

Replica Set

Page 26: Superficial mongo db

Operations

Default: Write/read operation goes to master

Can read from slaves.

Page 27: Superficial mongo db

Thank you!