Scaling MongoDB. Percona Webinar - Wed October 18th 11:00 AM PDT Adamo Tonete MongoDB Senior Service Technical Service Engineer.

Similar documents
How to upgrade MongoDB without downtime

How to Scale MongoDB. Apr

Your First MongoDB Environment: What You Should Know Before Choosing MongoDB as Your Database

Become a MongoDB Replica Set Expert in Under 5 Minutes:

MongoDB Backup & Recovery Field Guide

MongoDB: Replica Sets and Sharded Cluster. Monday, November 5, :30 AM - 5:00 PM - Bull

The course modules of MongoDB developer and administrator online certification training:

Mike Kania Truss

VMWARE VREALIZE OPERATIONS MANAGEMENT PACK FOR. MongoDB. User Guide

Scaling with mongodb

MongoDB Architecture

MongoDB Monitoring and Performance for The Savvy DBA

Exploring the replication in MongoDB. Date: Oct

MongoDB and Mysql: Which one is a better fit for me? Room 204-2:20PM-3:10PM

Run your own Open source. (MMS) to avoid vendor lock-in. David Murphy MongoDB Practice Manager, Percona

What s new in Mongo 4.0. Vinicius Grippa Percona

Reduce MongoDB Data Size. Steven Wang

SQL, NoSQL, MongoDB. CSE-291 (Cloud Computing) Fall 2016 Gregory Kesden

Course Content MongoDB

MongoDB. David Murphy MongoDB Practice Manager, Percona

MongoDB Backup and Recovery Field Guide. Tim Vaillancourt Sr Technical Operations Architect, Percona

Scaling for Humongous amounts of data with MongoDB

Time-Series Data in MongoDB on a Budget. Peter Schwaller Senior Director Server Engineering, Percona Santa Clara, California April 23th 25th, 2018

Scaling Without Sharding. Baron Schwartz Percona Inc Surge 2010

Review of Morphus Abstract 1. Introduction 2. System design

Running MongoDB in Production, Part I

Which technology to choose in AWS?

Percona Live Updated Sharding Guidelines in MongoDB 3.x with Storage Engine Considerations. Kimberly Wilkins

Scaling MongoDB: Avoiding Common Pitfalls. Jon Tobin Senior Systems

MongoDB - a No SQL Database What you need to know as an Oracle DBA

MongoDB 2.2 and Big Data

ITG Software Engineering

MongoDB Security: Making Things Secure by Default

~3333 write ops/s ms response

MongoDB Distributed Write and Read

NoSQL Databases MongoDB vs Cassandra. Kenny Huynh, Andre Chik, Kevin Vu

MongoDB Shell: A Primer

MongoDB Storage Engine with RocksDB LSM Tree. Denis Protivenskii, Software Engineer, Percona

Group13: Siddhant Deshmukh, Sudeep Rege, Sharmila Prakash, Dhanusha Varik

Why Do Developers Prefer MongoDB?

Making Non-Distributed Databases, Distributed. Ioannis Papapanagiotou, PhD Shailesh Birari

WiredTiger In-Memory vs WiredTiger B-Tree. October, 5, 2016 Mövenpick Hotel Amsterdam Sveta Smirnova

MMS Backup Manual Release 1.4

MongoDB: Comparing WiredTiger In-Memory Engine to Redis. Jason Terpko DBA, Rackspace/ObjectRocket 1

GR Reference Models. GR Reference Models. Without Session Replication

Sharding Introduction

MongoDB Schema Design for. David Murphy MongoDB Practice Manager - Percona

MySQL Performance Improvements

Beyond Relational Databases: MongoDB, Redis & ClickHouse. Marcos Albe - Principal Support Percona

4 Myths about in-memory databases busted

Recent Improvements in Gluster for VM image storage. Pranith Kumar Karampuri 20 th Aug 2015

CSE 124: Networked Services Lecture-16

Open Source Database Performance Optimization and Monitoring with PMM. Fernando Laudares, Vinicius Grippa, Michael Coburn Percona

GFS Overview. Design goals/priorities Design for big-data workloads Huge files, mostly appends, concurrency, huge bandwidth Design for failures

CSE 124: Networked Services Fall 2009 Lecture-19

Distributed Data Management Replication

CISC 7610 Lecture 5 Distributed multimedia databases. Topics: Scaling up vs out Replication Partitioning CAP Theorem NoSQL NewSQL

GFS: The Google File System. Dr. Yingwu Zhu

Amazon ElastiCache 8/1/17. Why Amazon ElastiCache is important? Introduction:

Atrium Webinar- What's new in ADDM Version 10

Scalability of web applications

Cassandra, MongoDB, and HBase. Cassandra, MongoDB, and HBase. I have chosen these three due to their recent

Evaluation Guide for ASP.NET Web CMS and Experience Platforms

AlwaysOn Availability Groups: Backups, Restores, and CHECKDB

A Guide to Architecting the Active/Active Data Center

Percona Live Santa Clara, California April 24th 27th, 2017

Exadata Implementation Strategy

Google File System. Arun Sundaram Operating Systems

MongoDB Index Types How, when and where should they be used?

GFS: The Google File System

MySQL In the Cloud. Migration, Best Practices, High Availability, Scaling. Peter Zaitsev CEO Los Angeles MySQL Meetup June 12 th, 2017.

Building High Performance Apps using NoSQL. Swami Sivasubramanian General Manager, AWS NoSQL

MONGODB INTERVIEW QUESTIONS

MongoDB Schema Design

Distributed Systems. Lec 10: Distributed File Systems GFS. Slide acks: Sanjay Ghemawat, Howard Gobioff, and Shun-Tak Leung

MyRocks deployment at Facebook and Roadmaps. Yoshinori Matsunobu Production Engineer / MySQL Tech Lead, Facebook Feb/2018, #FOSDEM #mysqldevroom

! Design constraints. " Component failures are the norm. " Files are huge by traditional standards. ! POSIX-like

Example File Systems Using Replication CS 188 Distributed Systems February 10, 2015

Why Choose Percona Server for MongoDB? Tyler Duzan

5 Fundamental Strategies for Building a Data-centered Data Center

Overview. CPS Architecture Overview. Operations, Administration and Management (OAM) CPS Architecture Overview, page 1 Geographic Redundancy, page 5

Goals. Facebook s Scaling Problem. Scaling Strategy. Facebook Three Layer Architecture. Workload. Memcache as a Service.

Scaling. Marty Weiner Grayskull, Eternia. Yashh Nelapati Gotham City

HDFS Federation. Sanjay Radia Founder and Hortonworks. Page 1

MySQL HA Solutions. Keeping it simple, kinda! By: Chris Schneider MySQL Architect Ning.com

Choosing a MySQL HA Solution Today. Choosing the best solution among a myriad of options

Real-Time & Big Data GIS: Best Practices. Josh Joyner Adam Mollenkopf

MySQL High Availability

MongoDB in AWS (MongoDB as a DBaaS)

Document Sub Title. Yotpo. Technical Overview 07/18/ Yotpo

Azure SQL Database. Indika Dalugama. Data platform solution architect Microsoft datalake.lk

PGConf.Russia 2019, Moscow. Alexander Kukushkin

MySQL High Availability. Michael Messina Senior Managing Consultant, Rolta-AdvizeX /

Cloud Backup and Recovery for Healthcare and ecommerce

Mesosphere and Percona Server for MongoDB. Jeff Sandstrom, Product Manager (Percona) Ravi Yadav, Tech. Partnerships Lead (Mesosphere)

Google File System 2

GridGain and Apache Ignite In-Memory Performance with Durability of Disk

MySQL HA Solutions Selecting the best approach to protect access to your data

API Gateway 8.0 Multi-Regional Deployment

FLAT DATACENTER STORAGE. Paper-3 Presenter-Pratik Bhatt fx6568

Transcription:

caling MongoDB Percona Webinar - Wed October 18th 11:00 AM PDT Adamo Tonete MongoDB enior ervice Technical ervice Engineer 1

Me and the expected audience @adamotonete Intermediate - At least 6+ months MongoDB experience 2

Agenda Overview on MongoDB The adamo.com story scaling out The adamo.com story scaling down Review Q&A 3

Overview on MongoDB Fast; Document-oriented database; Easy to deploy and manage; ecure database; HA by default; Easy to scale. 4

Internals Document size limit is 16 MB Different storage engines MMAPv2 WiredTiger RocksDB In Memory 5

Internals MongoDB shares features with Relational Databases such as: Indexes; Query Optimizer - Explain; Cache Management; Backups; Restores. 6

adamo.com is a startup that started using MongoDB as a single instance and was using a single machine on a cloud provider. In this webinar, I m going to tell you the story of how the company evolved from one instance to a sharded environment. I ingle instance 8 GB RAM, 2 processors - WiredTiger as torage Engine 7

After a few months, the database started answering queries very slowly. The company noticed high processor usage and a very active disk, so they decided to increase the instance type. ingle instance I ETL process 16 GB RAM, 4 processors - WiredTiger as torage Engine 8

Even after increasing the instance type, the company still noticed slow reads and writes. Processor usage was still high and the company still noticed high disk I/O. To make matters worse, the database failed after a few weeks. 9

Cache Cache evicted by ETL ingle instance ETL process 10 Free memory 16 GB RAM, 4 processors - WiredTiger as torage Engine

o, why was this database still slow even after increasing the machine resources? What could be done to avoid outages? Now the adamo.com company had learned both how to use replica-sets and the advantages of having multiple instances with High Availability. The HA was solved, the single instance became a replica-set with 3 members, but they were still having issues on the primary instance. The same problem as they had faced before. 11

A new environment. The replica-set was working properly but still facing issues while ETL was running, and the application auto fail-over was not working properly. CACHE ETL ETL Free memory 12

A few names you should know for the next step: Read Preference Write Concern Replication Lag Oplog Window 13

A new environment. The replica-set was working properly but still facing issues while ETL was running, and the application auto fail-over was not working properly. CACHE ETL ETL Free memory 14

A few names you should know for the next steps: Read Preference: Most application drivers feature the read preference option. This is, in simple words, where the application will get data from. All writes will be routed to the primary, but you can change the read preference option to: - Primary, secondary_prefered, secondary_only, nearest, and tags. 15

A few names you should know for the next steps: Write Concern: MongoDB offers eventual consistency, but we can tune it up and have more than one instance confirming a write command. This is very useful to guarantee data consistency across the replica-set and/or datacenters. The write concerns are: 1,2,<n> and majority, where majority means ½ + 1 instance from the replica-set. 16

A few names you should know for the next steps: Replication Lag: MongoDB replication between instances doesn't occur in real time. It is asynchronous. A secondary instance with fewer resources than the primary can easily fall behind to receive new writes and updates. The most common issues are slow disks, limited bandwidth, and slow processors. Replication lag is a critical metric when you run queries on secondaries. 17

A few names you should know for the next steps: Oplog Window: Per design, the replication is asynchronous and all the primary commands are saved on the oplog.rs collection. The oplog collection is a fixed-size collection that saves such operations, so that the secondaries can pull and apply the same commands. As it is a fixed-size collection, the old documents will be replaced by new ones when it gets full. The period of time between the first and the last command in this collection is called oplog window. 18

A new environment, spreading the read to all the secondaries, and primary only receives writes. P ETL 19

The new environment seemed to be really robust, but after a while the company started facing new issues. The understanding of the concepts below is required to discuss the next issues. Hidden Instance Priority Votes Arbiters 20

When someone from BI was running their ETL, a few clients started noticing slowness, why? ETL App is reading from here as well 21

PRIMARY P ETL H Hidden secondary 22

The hidden secondary was completely hidden from the replica-set, which means that the application was not connected to the instance to perform reads. In the case above, only the ETL process read data from this secondary. If we need more reads, it is ok to add new secondaries. However, we must make sure we don't add too many of them, as issues such as replication delay may occur. 23

PRIMARY P ETL H Hidden secondary 24

The replication delay can occur for several reasons. A replica-set may, for example, perform chained replication, which in other words means the database is replicating to a secondary, and that secondary is replicating to another secondary. The chained replication can be disabled on the replica-set configuration. https://docs.mongodb.com/manual/tutorial/manage-chained-replication/ 25

PRIMARY P ETL H Hidden secondary 26 Not In sync Replication Delay

Not all the instances will be eligible to vote. Replica-sets can only have up to 7 instances voting. Therefore, if there are more than 7 instances in the replica-set, only 7 can vote. As good practice, keep those close to the "primary" and choose the best ones. ometimes we need a mongodb instance that will only check whether the other instances are available. These are called arbiters and arbiters don t keep data, they only perform votes. 27

PRIMARY P Votes : 1 Priority : 1 ETL Votes : 1 Priority : 1 Votes : 1 Priority : 1 H Votes : 0 Priority : 0 28 Votes : 0 Priority : 0 Votes :0 Priority :0

It is time to consider sharding. Even with the replica-sets, the number of writes we need as well as the working set are making it too expensive to keep everything in a single replica-set. harding will create a virtual database among replicas and split the load between those replica sets, which will be called shards. 29

A simple 2-shard cluster mongos config P P 30

hards - Important words Mongo is the proxy process that the application will connect to. As the database is sharded,there is no guarantee that all the data is in just one shard. Configervers are the servers that store the data location. These special instances save all the data location in order to enable the mongos to find the expected data. This data is called cluster metadata. A hard is a replica set that belongs to a cluster. A Cluster is a combination of 1 or more shards along with a config server and mongos. 31

hards - Important words A hard Key is the field where the collection will be split. Chunks are small amounts of data, usually 64M, based on the shard key. There are several chunks in a database after it is sharded. A Balancer is the process that moves data between shards or even inside shards to different chunks. 32

Replicaset - Moving to a cluster adamo.com was now one of the most popular websites. Even though the replica-set helped them to handle reads, writes became a problem. It was time to start developing a cluster strategy. P Votes : 1 Priority : 1 Mongo Config Votes : 1 Priority : 1 Votes : 1 Priority : 1 H Votes : 0 Priority : 0 ETL 33 Votes : 0 Priority : 0 Votes :0 Priority :0

hards - 1-shard cluster mongos config 1-shard cluster P 34 H

- shards mongos config 2-shards cluster P P 35 H H

hards - Adding new shards Even after a new shard was added, the sample company didn t see any improvement in the write performance. In fact, the main database was not yet configured as a sharded database, so all the reads and writes were going to shard 1 only. 36

hards - Adding new shards used mongos non used config 37 P H E T L P H

hards - harding a database It is necessary to tell the config servers that we want to shard a database. After running: sh.sharddatabase('mydatabase') We need to start sharding the collections using a shard key. The most used collection is called posts, and for this collection we shard based on the hash of the _id field. We can change shards by range, but we choose the hash _id to speed up the writes and make them random. 38

hards - harding a database mongos config P balancer P 39 H E T L H

hards - Balancer After the balancer funs for a while, both shards keep data. Each part has its data and the information about where the data is stored is in the config database. adamo.com noticed that the etl was only moving "half" of the expected data because the data was now split between the shards. 40

hards - Balancer mongos E T L config P balancer P 41 H H

- shard ETL couldn't connect to the hidden secondaries because all the connections were made through the mongos. To work around this situation, the company decided to use tag-aware reads. In order to perform the reads, each instance had to have a tag, for different purposes: read or ETL. In this case, the application will perform reads from instances with the "read" tag and the ETL will only read from the ETL tag. https://docs.mongodb.com/v3.2/core/tag-aware-sharding/ 42

hards - Read Tag Aware mongos E T L config Tag: read Tag: read P P Tag: ETL 43 Tag: ETL

With such architecture, the example company could have 10 shards running at the same time, but unfortunately the success of the website didn't last too long. After 2 years running on a 10-shard replica-set, the company decided to start shrinking the environment to just 2 shards again. 44

The process was the inverse of sharding, where the company needed to remove shards from the cluster and wait until all the data moved to different shards. The balancer process works the other way round. Data from the shard was removed to the remaining shards and the config servers were updated to the new data location. All of those steps can be done online meaning that no downtime is required. 45

Review ingle Instances are not recommended; Replica-sets must have at least 3 instances storing data; Hidden instances can't be read by drivers; A cluster can have only one shard but there is no performance improvement; Adding new shards is easy, but you need to pick the right shard key to split the data among the instances; Use read tags to connect through the mongos in order to read from a specific instance in the shard. cale down is as easy as scale out in mongodb ome subjects, such as backups and security, were omitted from this presentation to keep it simple and concise. 46

Review Resources: https://www.percona.com/blog/2017/10/16/when-should-i-enable-mongodb-sharding/ https://docs.mongodb.com/manual/sharding/ https://www.percona.com/blog/2016/12/16/mongodb-pit-backups-in-depth/ 47

Q&A 48

DATABAE PERFORMANCE Database Performance Matters MATTER