+ All Categories
Home > Technology > MongoDB Deployment Tips

MongoDB Deployment Tips

Date post: 15-Jan-2015
Category:
Upload: jared-rosoff
View: 3,012 times
Download: 0 times
Share this document with a friend
Description:
This presentation covers two important topics for scalable mongodb deployments. First, we will discus how MongoDB stores data so you can figure out how much RAM you need in each of your servers. Second, we'll look at replica sets and how to design a highly available topology for your replica set.
Popular Tags:
46
MongoDB deployment tips Jared Rosoff - @forjared
Transcript
Page 1: MongoDB Deployment Tips

MongoDB deployment tipsJared Rosoff - @forjared

Page 2: MongoDB Deployment Tips

Agenda

• Sizing Machines– Understanding working set – Sizing RAM – Sizing Disk

• Configuring Replica Sets– Understanding failover – Avoiding single points of failure –Minimizing recovery time

Page 3: MongoDB Deployment Tips

Shard 1

Overview

Primary

Secondary

Secondary

Shard 2

Primary

Secondary

Secondary

Shard 3

Primary

Secondary

Secondary

Config

Config

Config

Router Router

Page 4: MongoDB Deployment Tips

Shard 1

Servers and Hardware

Primary

Secondary

Secondary

Shard 2

Primary

Secondary

Secondary

Shard 3

Primary

Secondary

Secondary

Config

Config

Config

Router Router

Page 5: MongoDB Deployment Tips

SIZING RAM AND DISK

Page 6: MongoDB Deployment Tips

Collection 1

Index 1

Page 7: MongoDB Deployment Tips

Virtual Address Space 1

Collection 1

Index 1

Page 8: MongoDB Deployment Tips

Virtual Address Space 1

Collection 1

Index 1 This is your virtual memory size (mapped)

Page 9: MongoDB Deployment Tips

Virtual Address Space 1

Physical RAM

Collection 1

Index 1

Page 10: MongoDB Deployment Tips

Virtual Address Space 1

Physical RAM

Collection 1

Index 1

This is your resident memory size

Page 11: MongoDB Deployment Tips

Virtual Address Space 1

Physical RAM

DiskCollection 1

Index 1

Page 12: MongoDB Deployment Tips

Virtual Address Space 1

Physical RAM

Disk

Virtual Address Space 2

Collection 1

Index 1

Page 13: MongoDB Deployment Tips

Virtual Address Space 1

Physical RAM

DiskCollection 1

Index 1

100 ns

10,000 ns

=

=

Page 14: MongoDB Deployment Tips

Disk configurations

~200 seeks / second

Single Disk

Page 15: MongoDB Deployment Tips

Disk configurations

~200 seeks / second

~200 seeks / second~200 seeks / second~200 seeks / second

Single Disk

RAID 0

Page 16: MongoDB Deployment Tips

Disk configurations

~200 seeks / second

~200 seeks / second~200 seeks / second~200 seeks / second

~400 seeks / second~400 seeks / second~400 seeks / second

Single Disk

RAID 0

RAID 10

Page 17: MongoDB Deployment Tips

SSDs ??

• Seek time of 0.1ms vs 5ms (200 seeks / sec => 10000 seeks / sec)

• But expensive

Page 18: MongoDB Deployment Tips

Tips for sizing hardware

• Know how important page faults are– If you want low latency, avoid page

faults

• Size memory appropriately – To avoid page faults, fit everything in

RAM– Collection Data + Index Data

• Provision disk appropriately– RAID10 is recommended– SSD’s are fast, if you can afford them

Page 19: MongoDB Deployment Tips

Shard 1

Replica Sets

Primary

Secondary

Secondary

Shard 2

Primary

Secondary

Secondary

Shard 3

Primary

Secondary

Secondary

Config

Config

Config

Router Router

Page 20: MongoDB Deployment Tips

UNDERSTANDING AUTOMATIC FAILOVER

Page 21: MongoDB Deployment Tips

Primary Election

Primary

Secondary

Secondary

As long as a partition can see a majority (>50%) of the cluster, then it will elect a primary.

Page 22: MongoDB Deployment Tips

Simple Failure

Primary

Failed Node

Secondary

66% of cluster visible. Primary is elected

Page 23: MongoDB Deployment Tips

Simple Failure

Failed Node

33% of cluster visible. Read only mode.

Failed Node

Secondary

Page 24: MongoDB Deployment Tips

Network Partition

Primary

Secondary

Secondary

Page 25: MongoDB Deployment Tips

Network Partition

Primary

Secondary

Secondary

Primary

Failed Node

Secondary

66% of cluster visible. Primary is elected

Page 26: MongoDB Deployment Tips

Secondary

Network Partition

33% of cluster visible. Read only mode.

Primary

Secondary

Failed Node

Failed Node

Secondary

Page 27: MongoDB Deployment Tips

Even Cluster Size

Primary

Secondary

Secondary

Secondary

Page 28: MongoDB Deployment Tips

Even Cluster Size

Primary

Secondary

Secondary

Secondary

Failed Node

Secondary

Failed Node

50% of cluster visible. Read only mode.

Secondary

Page 29: MongoDB Deployment Tips

Even Cluster Size

Primary

Secondary

Failed Node

Secondary

Failed Node

50% of cluster visible. Read only mode.

Secondary

Secondary

Secondary

Page 30: MongoDB Deployment Tips

AVOIDING SINGLE POINTS OF FAILURE

Page 31: MongoDB Deployment Tips

Avoid Single points of failure

Page 32: MongoDB Deployment Tips

Avoid Single points of failure

Primary

Secondary

Secondary

Top of rack switch

Rack falls over

Page 33: MongoDB Deployment Tips

Better

Primary

Secondary

Secondary

Loss of internet

Building burns down

Page 34: MongoDB Deployment Tips

Better yet

Primary

Secondary

Secondary

San Francisco

Dallas

Page 35: MongoDB Deployment Tips

Priorities

Primary

Secondary

Secondary

San Francisco

Dallas

Priority 1

Priority 1

Priority 0

Disaster recover data center. Will never become primary automatically.

Page 36: MongoDB Deployment Tips

Even Better

Primary

Secondary

Secondary

San Francisco

Dallas

New York

Page 37: MongoDB Deployment Tips

FAST RECOVERY

Page 38: MongoDB Deployment Tips

2 Replicas + Arbiter??

Primary

Arbiter

Secondary Is this a good idea?

Page 39: MongoDB Deployment Tips

2 Replicas + Arbiter??

Primary

Arbiter

Secondary

1

Page 40: MongoDB Deployment Tips

2 Replicas + Arbiter??

Primary

Arbiter

Secondary

Primary

Arbiter

Secondary

1 2

Page 41: MongoDB Deployment Tips

2 Replicas + Arbiter??

Primary

Arbiter

Secondary

Primary

Arbiter

Secondary

1 2

Primary

Arbiter

Secondary

3

Secondary

Full Sync

Uh oh. Full Sync is going to use a lot of resources on the primary. So I may have downtime or degraded performance

Page 42: MongoDB Deployment Tips

With 3 replicas

Primary

Secondary

1

Secondary

Page 43: MongoDB Deployment Tips

With 3 replicas

Primary

Secondary

Primary

Secondary

1 2

Secondary Secondary

Page 44: MongoDB Deployment Tips

With 3 replicas

Primary

Secondary

Primary

Secondary

1 2

Primary

Secondary

3

Secondary

Full Sync

Sync can happen from secondary, which will not impact traffic on Primary.

Secondary Secondary Secondary

Page 45: MongoDB Deployment Tips

Tips for choosing replica set topology

• Avoid single points of failure – Separate racks– Separate data centers

• Avoid long recovery downtime– Use journaling – Use 3+ replicas

• Keep your actives close – Use priority to control where failovers

happen

Page 46: MongoDB Deployment Tips

Summary

• Sizing a machine – Know your working set size – Size RAM appropriately – Provision sufficient disks

• Designing a replica set – Know how failover happens – Design for failure – Design for fast recover


Recommended