34
Consulting Manager, 10gen Richard Kreuter Right Ways and Wrong Ways to Implement MongoDB

Webinar: Right and Wrong Ways to Implement MongoDB

  • Upload
    mongodb

  • View
    3.593

  • Download
    3

Embed Size (px)

DESCRIPTION

MongoDB offers users a great deal of flexibility vis-a-vis implementation decisions, and this flexibility brings a lot of power. But with great power comes great responsibility. In this talk we'll cover some better and worse implementation options, including deployment topologies, capacity provisioning, data loading, and more!

Citation preview

Page 1: Webinar: Right and Wrong Ways to Implement MongoDB

Consulting Manager, 10gen

Richard Kreuter

Right Ways and Wrong Ways to Implement MongoDB

Page 2: Webinar: Right and Wrong Ways to Implement MongoDB

Right Ways, Wrong Ways – Richard Kreuter

This talk

• MongoDB is flexible.

• 3 areas where folks make mistakes

• Things you should remember

Page 3: Webinar: Right and Wrong Ways to Implement MongoDB

Flexibility

Page 4: Webinar: Right and Wrong Ways to Implement MongoDB

Right Ways, Wrong Ways – Richard Kreuter

MongoDB is very flexible

• Designed for cloud, commodity– Portable across OS, hardware, network

• HA/DR/Scaling options built-in– Replication: “How many copies of data?”– Sharding: “How are data & load distributed?”

• Many dimensions of choices– How many servers? Where? What hardware?

Page 5: Webinar: Right and Wrong Ways to Implement MongoDB

Right Ways, Wrong Ways – Richard Kreuter

These choices give you power

• Can provision for different fault tolerances• Can configure system to scale horizontally• Can use features for special requirements

(e.g., geographical distribution)

Page 6: Webinar: Right and Wrong Ways to Implement MongoDB

Right Ways, Wrong Ways – Richard Kreuter

With great power comes great responsibility1

• Some choices nonsensical 99% of the time

• (Contrived exceptions should be ignored.)

1: Stan Lee, author of Spider-Man

Page 7: Webinar: Right and Wrong Ways to Implement MongoDB

Right Ways, Wrong Ways – Richard Kreuter

Meta Rule of Thumb

To make good decisions about MongoDB implementations, you must understand MongoDB and your applications and the

workload your applications generate and your business requirements.

Page 8: Webinar: Right and Wrong Ways to Implement MongoDB

Deployment Topologies

Page 9: Webinar: Right and Wrong Ways to Implement MongoDB

Right Ways, Wrong Ways – Richard Kreuter

Replication Topology Mistakes

• All replica set members on one host

• Replica set members sharing same storage

• Replica set evenly split across 2 DCs– (Actually, two is a bad number for replica sets.)

Page 10: Webinar: Right and Wrong Ways to Implement MongoDB

Right Ways, Wrong Ways – Richard Kreuter

Replica Set Rule of Thumb:Decouple all modes of failure!

Page 11: Webinar: Right and Wrong Ways to Implement MongoDB

Right Ways, Wrong Ways – Richard Kreuter

Replication Topology Fixes

• All replica set members on one host– Put replicas on different hosts

• Replica set members sharing same storage– Give each replica separate storage

• Replica set evenly split across 2 DCs– Use more DCs– Understand RS elections

Page 12: Webinar: Right and Wrong Ways to Implement MongoDB

Right Ways, Wrong Ways – Richard Kreuter

Some Sharding Topology Mistakes

• Shards that aren’t Replica Sets

• Solitary config server

Page 13: Webinar: Right and Wrong Ways to Implement MongoDB

Right Ways, Wrong Ways – Richard Kreuter

Sharding Rule of Thumb #1:Avoid single points of failure!

Page 14: Webinar: Right and Wrong Ways to Implement MongoDB

Right Ways, Wrong Ways – Richard Kreuter

Some Sharding Topology Fixes

• Shards that aren’t Replica Sets– Each shard should be a replica set

• Solitary config server– Always use 3 config servers

Page 15: Webinar: Right and Wrong Ways to Implement MongoDB

Right Ways, Wrong Ways – Richard Kreuter

More Sharding Topology Mistakes

• Multiple shards on one box

• One/too few mongos processes

Page 16: Webinar: Right and Wrong Ways to Implement MongoDB

Right Ways, Wrong Ways – Richard Kreuter

Sharding Rule of Thumb #2:Add unshared resources for scaling!

Page 17: Webinar: Right and Wrong Ways to Implement MongoDB

Right Ways, Wrong Ways – Richard Kreuter

More Sharding Topology Fixes

• Multiple shards on one box– Shards should never share hardware.

• One/too few mongos processes– Run more mongos processes – (1+ per app server, say)

Page 18: Webinar: Right and Wrong Ways to Implement MongoDB

Performance Considerations

Page 19: Webinar: Right and Wrong Ways to Implement MongoDB

Right Ways, Wrong Ways – Richard Kreuter

Indexing Mistakes

• Failing to build necessary indexes

• Building unnecessary indexes

• Running ad-hoc queries in production

Page 20: Webinar: Right and Wrong Ways to Implement MongoDB

Right Ways, Wrong Ways – Richard Kreuter

Indexing Rule of Thumb:Build all and only necessary indexes!

Page 21: Webinar: Right and Wrong Ways to Implement MongoDB

Right Ways, Wrong Ways – Richard Kreuter

Indexing Fixes

• Failing to build necessary indexes– Learn to use the slow query log & db profiler

• Building unnecessary indexes– Talk to your app developers about usage

• Running ad-hoc queries in production- Have a staging environment, use secondaries

Page 22: Webinar: Right and Wrong Ways to Implement MongoDB

Right Ways, Wrong Ways – Richard Kreuter

Shard Key Selection Mistakes

• Shard key that’s never used

• Low cardinality shard key

• Picking a shard key for initial import, not regular usage

Page 23: Webinar: Right and Wrong Ways to Implement MongoDB

Right Ways, Wrong Ways – Richard Kreuter

Shard Key Rule of Thumb:Choose shard keys carefully!

Page 24: Webinar: Right and Wrong Ways to Implement MongoDB

Right Ways, Wrong Ways – Richard Kreuter

Shard Key Selection Fixes

• Shard key that’s never used– Understand your query/update patterns

• Low cardinality shard key– Find a higher cardinality option (or just concatenate the

_id field)

• Picking a shard key for initial import, not regular usage– Find other ways to make initial import fast

Page 25: Webinar: Right and Wrong Ways to Implement MongoDB

Hardware Choices

Page 26: Webinar: Right and Wrong Ways to Implement MongoDB

Right Ways, Wrong Ways – Richard Kreuter

Hardware Selection Mistakes

• Skimping on RAM

• Skimping on disk speeds

Page 27: Webinar: Right and Wrong Ways to Implement MongoDB

Right Ways, Wrong Ways – Richard Kreuter

Hardware Rule of Thumb #1:Choose your hardware with your use of MongoDB’s architecture in mind!

Page 28: Webinar: Right and Wrong Ways to Implement MongoDB

Right Ways, Wrong Ways – Richard Kreuter

Hardware Selection Fixes

• Skimping on RAM– Understand/estimate your Working Set

• Skimping on disk speeds– Understand/estimate your write load

Page 29: Webinar: Right and Wrong Ways to Implement MongoDB

Right Ways, Wrong Ways – Richard Kreuter

Hardware Selection Oddities

• (Re-)Provisioning hardware intended for other systems

• Not controlling virtual machine locations

Page 30: Webinar: Right and Wrong Ways to Implement MongoDB

Right Ways, Wrong Ways – Richard Kreuter

Hardware Rule of Thumb #2:Pick hardware/virtualization that serves your use of MongoDB!

Page 31: Webinar: Right and Wrong Ways to Implement MongoDB

Right Ways, Wrong Ways – Richard Kreuter

Hardware Selection Fixes

• (Re-)Provisioning hardware intended for other systems• Understand how MongoDB uses hardware

• Not controlling virtual machine locations• Be sure you can control where VMs run

Page 32: Webinar: Right and Wrong Ways to Implement MongoDB

Things to remember!

Page 33: Webinar: Right and Wrong Ways to Implement MongoDB

Right Ways, Wrong Ways – Richard Kreuter

In Conclusion…• Learn how MongoDB works.

• Do know what your technical & business requirements are.

• Work backwards from requirements to choices.

• Don’t make MongoDB choices based on legacy habits/practices

• Expect that things will change.

• Ask 10gen to Help!

Page 34: Webinar: Right and Wrong Ways to Implement MongoDB

Consulting Manager, 10gen

Richard Kreuter

Thank you!