managing a mongodb deployment

19
MANAGING A MONGODB DEPLOYMENT Tony Tam @fehguy

Upload: tony-tam

Post on 11-May-2015

5.689 views

Category:

Technology


2 download

DESCRIPTION

Talk by Wordnik's Tony Tam on managing a large scale MongoDB deployment

TRANSCRIPT

Page 1: Managing a MongoDB Deployment

MANAGING A MONGODB DEPLOYMENT

Tony Tam @fehguy

Page 2: Managing a MongoDB Deployment

AREAS OF DISCUSSION

Many drivers to go non-relationalMaybe you already are?SOA?

“Yes we should!” Now what? Implementation details, best practices

Depends on what system you chooseOperational Architecture

Making your deployment “maintainable”Maximizing performance

Software + Hardware tuning

Page 3: Managing a MongoDB Deployment

WORDNIK SAYS YES TO MONGODB

And we’re alive to talk about itOur stats

14 M REST API calls yesterday7 ms avg. response3 TB of MongoDB dataMostly all “un-cached” responses

Page 4: Managing a MongoDB Deployment

SOFTWARE ARCHITECTURE

Java/Scala/Jetty application serversShare (almost) nothingAll roads in must speak REST

Page 5: Managing a MongoDB Deployment

DEPLOYMENT ARCHITECTURE

Wordnik uses physical servers

Page 6: Managing a MongoDB Deployment

OPERATIONAL CONSTRAINTS

Fundamental question to answerCan we support this?

You need to considerIf you want it to scaleIf you have a SLA to supportIf you carry the pager

Also important ifYou have customersYou like your job

Page 7: Managing a MongoDB Deployment

OPERATIONAL CONSTRAINTS

Core items for WordnikRedundancy with master/slave

Multi-datacenter deployment possible?Design for read-only mode

Control at the driver levelBlocking

When is it OK?Steps around with MongoDB

ConsistencyWhen does it matter?

Scale-outWhat limits our speed/size?

Other?Some features => opportunity

Page 8: Managing a MongoDB Deployment

REDUNDANCY

MongoDB supports MS and Replica SetsRS is like MS with auto-failoverDriver intelligenceStill one master, elected by peers

Master

Slave

Slave

Slave

Master

Slave

Slave

Master

Slave

Slave

Slave

Page 9: Managing a MongoDB Deployment

REDUNDANCY

Master/Slave fine for us but…Not fine for multi operational datacenters

resync?Your data drives the appropriate solutionCustom tools to support thishttps://github.com/wordnik/wordnik-oss

SCP

Primary Datacenter

Master

Incremental Backup

Files

Hot Datacenter

Master

Replay Util

Page 10: Managing a MongoDB Deployment

REDUNDANCY

Multi-datacenter deploymentSome data need not be consistent

Some doesReplication tricks for master-master

Master 1 Master 2

db.documentsdocuments.src == 1

db.documentsdocuments.src == 2

Page 11: Managing a MongoDB Deployment

CONTROLLING BLOCKING OPERATIONS

Important to know what blocksSome situations can create global locks

Know what happens with:Adding dataDeleting dataModifying data

…Then toss in 100 reads/secOnly access your DB “the right way”

Enforce by good software designThe right way == “right way for your db”

Page 12: Managing a MongoDB Deployment

CONTROLLING BLOCKING OPERATIONS

Wordnik SolutionMongoDB access via service layer

Only allow queries you want runAll others => non-production server,

HadoopSmart driver manager

Slave bias $inc:{page_views:1} => $set{page_views:10038}

Read-only modeHot-remove server from pool

Page 13: Managing a MongoDB Deployment

HANDLING EVENTUAL CONSISTENCY

EC makes things fastMay create timing issuesSometimes need current data

val db:DB = getReadWriteConnection()

Avoid this a much as possibleBut if you must…

Write then call “getLastError”Forces commit to DB

RS allows “replicate to n nodes”Forces commit to master, n slaves

Page 14: Managing a MongoDB Deployment

SCALE-OUT

What are you scaling?Size of dataSize of indexesOperations

Add slave serversWon’t help if size > index/server capacity

Sharding if done rightAutoshard solutionRoll your own

Page 15: Managing a MongoDB Deployment

SCALE-OUT

Selecting a shard keyCan be trickyDepends on what you need

Page 16: Managing a MongoDB Deployment

KEEPING IT RUNNING

BackupsExport with “mongodump”No incremental backup solution included

Wordnik tools https://github.com/wordnik/wordnik-oss

Page 17: Managing a MongoDB Deployment

WORDNIK OSS TOOLS

Take our tools-They work!!!SnapshotUtil

Selectively snapshot in BSON Index info too!

IncrementalBackupUtilTail the oplog, stream to disk

Only the collections you want! Compress & rotate

RestoreUtilRecover your snapshots

Apply indexes yourself

ReplayUtilApply your Incremental backups

Page 18: Managing a MongoDB Deployment

WHAT IF SCENARIOS

One collection gets corrupt?Restore itApply all operations to it

“My top developer dropped a collection!”Restore just that oneApply operations to it until that POT

“We got hacked!”Restore it allApply operations until that POT

Page 19: Managing a MongoDB Deployment

WRAP UP: WE LIKE MONGODB

See more @ http://developer.wordnik.com

Questions?