mongodb at the silicon valley iphone and ipad developers' meetup

44
open-source, high- performance, document- oriented database Aaron Staple [email protected] m

Upload: mongodb

Post on 19-May-2015

10.207 views

Category:

Technology


1 download

DESCRIPTION

Aaron Staple's presentation at the Silicon Valley iPhone and iPad Developers' Meetup on July 19: http://www.meetup.com/sviphone/calendar/13248809/

TRANSCRIPT

Page 1: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup

open-source, high-performance, document-oriented database

Aaron [email protected]

m

Page 2: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup

Version 1.6comes out in 2 weeks

Page 3: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup

Production Examples

Page 4: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup

RDBMSRDBMS(Oracle, MySQL)(Oracle, MySQL)

New Gen. New Gen. OLAPOLAP

(vertica, aster, (vertica, aster, greenplum)greenplum)

Non-Non-relationalrelational

Operational Operational StoresStores(“NoSQL”)(“NoSQL”)

Page 5: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup

non-relational, next-generation operational datastores and databases

NoSQL Really Means:

Page 6: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup

Horizontally Scalable

Architectures

no joins

no complex transactions+

Page 7: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup

New Data Models

no joins

no complex transactions+

Page 8: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup

New Data Modelsmore natural ways to develop

applications?

Page 9: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup

JSON-style Documents

{“hello”: “world”}

\x16\x00\x00\x00\x02hello\x00\x06\x00\x00\x00world\x00\x00

http://bsonspec.org

represented as BSON

Page 10: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup

Flexible “Schemas”

{“author”: “mike”, “links”: 3, “date”: "Sun Jul 18 2010 14:40:20 GMT-0700 (PDT)" “text”: “...”}

Page 11: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup

Flexible “Schemas”

{“author”: “eliot”, “date”: "Sun Jul 18 2010 14:40:22 GMT-0700 (PDT)" “text”: “...”, “tags”: [“mongodb”]}

Page 12: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup

Dynamic Queries

Page 13: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup

Posts by Author

db.posts.find({author: “mike”})

Page 14: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup

Last 10 Posts

db.posts.find() .sort({date: -1}) .limit(10)

Page 15: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup

Posts Since April 1

april_1 = new Date(2010, 3, 1)db.posts.find({date: {$gt: april_1}})

Page 16: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup

Index any combination of fields, including embedded fields

Page 17: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup

Indexes{“author”: “mike”, “links”: 3, “date”: "Sun Jul 18 2010 14:40:20 GMT-0700 (PDT)" “text”: “...”}

db.posts.ensureIndex({links: 1})

Page 18: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup

Indexes{author: “mike”, …, comments: [ {author: “eliot”, date: new Date(), text: “great post!”} }, … ] }

db.posts.ensureIndex({‘comments.author’: 1, ‘comments.date’: -1 })

Page 19: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup

Advanced Queries and Map/Reduce

Support

Page 20: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup

Posts Ending With ‘Tech’

db.posts.find({text: /Tech$/})

Page 21: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup

Posts With a Tagdb.posts.find({tags: “mongodb”})

...and Fastdb.posts.ensureIndex({tags: 1})

(multi-key indexes)

Page 22: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup

Variety of Operators

db.posts.find( {$or: [{a:1}, {b:{$mod:[5,2]}} ]})

Page 23: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup

Map/Reduce> m = function() { emit(this.user_id, 1); }> r = function(k,vals) { return 1; }> res = db.events.mapReduce(m, r, { query : {type:'sale'} });> db[res.result].find().limit(2){ "_id" : 8321073716060 , "value" : 1 }{ "_id" : 7921232311289 , "value" : 1 }

Page 24: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup

Atomic Updates, Unique Key Constraints

Page 25: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup

Embedding a Comment

c = {author: “eliot”, date: new Date(), text: “great post!”}

db.posts.update({_id: post._id}, {$push: {comments: c}})

Page 26: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup

Many Supported Platforms / Languages

with Native Drivers

Page 27: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup

Focus on Performance

Page 28: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup

Focus on performance

depth of functionality

scala

bil

ity

& p

erf

orm

an

ce •memcached•key/

value

•RDBMS

Page 29: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup

Replication and Replica Sets

master

slave slave

master

slavemaster

slavemaster

slave

I II III

Page 30: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup

Auto Sharding

client

mongos ...mongos

mon

god

...

Shards

mongod

mongod

mongod

ConfigServers

mon

god

mon

god

mon

god

mon

god

mon

god

mon

god

mon

god

mon

god

...

Page 31: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup

Auto Shardingat bit.ly

•Sharding used for bit.ly user history

•~50M users (as of late May)

•Shard on user id

•Three secondary indexes

Page 32: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup
Page 33: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup

Features you guys care about

Page 34: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup

Geospatial Indexing

db.places.ensureIndex( { loc : "2d" } )

db.places.find( { loc : { $near :[50,50] } } ).limit(20)

Page 35: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup

Geospatial Indexingdb.places.ensureIndex(

{ location : "2d" , category : 1 } );

db.places.find( { location : { $near : [50,50] }, category : 'coffee' } );

Page 36: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup

Geospatial Indexing

•Also support matching within a spatial box

•And within a a circle

Page 37: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup

Geospatial Indexing at Foursquare

•~1.3M registered users. ~615k checkins/day. Nearly 50M checkins total (as of late May). Very rapid growth.

Page 38: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup

Geospatial Indexing at Foursquare•“Who’s here” service – tracks last

3 hours for every user – uses mongo exclusively

•All checkins, tips, venues written to mongo, reads a mix of mongo / legacy postgres (as of late May)

•Migrating geo related reads to mongo first

Page 39: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup

GridFS

•Store large files by splitting them into smaller documents

•Leverages existing sharding and replication configuration

•Store metadata along with files

•Works well behind a cdn

Page 40: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup

A Note on Security•Mongo supports basic per

database authentication

•No encryption

•Not security hardened (designed to work in a safe environment behind a firewall)

•Consider ssh tunnel from app server

Page 41: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup

Wordnik Configuration•1000 requests of various types /

second

•5 billion documents (1.2TB)

•Single 2x4 core server 32gb ram, FC SAN non virtualized

•NOTE: Virtualized storage tends to perform poorly, for example if you are on EC2 you should run several EBS volumes striped

Page 42: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup

Best Use Cases

The (Mobile) Web

High Volume• User comments, voting• Real time analytics

Scaling Out• User profile, session data• Content management

Caching• Fast, in-memory caching tier

Simplify Development• No ORM or fixed schema• Easy to install and maintain

Page 43: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup

•Commercial support

•Production support, 24x7

•Consulting

•Supercharge your app development

•Training

•Learn from the experts

•10gen.com

Page 44: MongoDB at the Silicon Valley iPhone and iPad Developers' Meetup

Download MongoDBmongodb.org

let us know what you think@mongodb

get free supportgroups.google.com/group/mongodb-user

request featuresjira.mongodb.org

(grab some friends and manipulate ourvoting system )