90
High Performance with MongoDB or "how to design fast applications" Asya Kamsky Lead Product Manager, MongoDB Inc #MongoDB @asya999 #askAsya

High Performance Applications with MongoDB

  • Upload
    mongodb

  • View
    1.730

  • Download
    2

Embed Size (px)

Citation preview

Page 1: High Performance Applications with MongoDB

High Performance with MongoDB

or "how to design fast applications"

Asya KamskyLead Product Manager, MongoDB Inc

#MongoDB @asya999 #askAsya

Page 2: High Performance Applications with MongoDB

What Is Fast?

• Must understand – what "fast" means– how to measure it– what are requirements– what's the context

Page 3: High Performance Applications with MongoDB

What Is Fast?

Page 4: High Performance Applications with MongoDB

What Is Fast?

Page 5: High Performance Applications with MongoDB

What Is Fast?

Page 6: High Performance Applications with MongoDB

George Washington Bridge

Page 7: High Performance Applications with MongoDB
Page 8: High Performance Applications with MongoDB
Page 9: High Performance Applications with MongoDB

Is It Fast?

Page 10: High Performance Applications with MongoDB

Is It Fast?

• In context of crossing the bridge, fast means:– how long will it take one car– how many cars can do it "at the same time"

Page 11: High Performance Applications with MongoDB

Is It Fast?Facts & Info

Opened to trafficUpper level: October 25, 1931Lower level: August 29, 1962

Bus Station opened: January 17, 1963

Length of bridge between anchorages: 4,760 feet Width of bridge: 119 feet Width of roadway: 90 feet Height of tower above water: 604 feet Water clearance at midspan: 212 feet

Number of toll lanes: Upper level: 12Lower level: 10 Palisades Interstate Parkway: 7** E-ZPass only overnight

2013 Traffic Volumes

Total New York-bound (eastbound) traffic: 49,402,245 vehicles

Page 12: High Performance Applications with MongoDB

What Is Fast?

Page 13: High Performance Applications with MongoDB

What Is Fast?

Latency Throughput

How long "it" takes How many "per unit of time"

Page 14: High Performance Applications with MongoDB

What Is Fast?

Latency Throughput Throughput Latency

Page 15: High Performance Applications with MongoDB

What Is Fast?

Latency Throughput Throughput Latency

Orthogonal, but highly interdependent

Page 16: High Performance Applications with MongoDB
Page 17: High Performance Applications with MongoDB

What Is Fast?

Latency Throughput Throughput Latency

Page 18: High Performance Applications with MongoDB

What Is Fast?

Latency Throughput Throughput Latency

Page 19: High Performance Applications with MongoDB
Page 20: High Performance Applications with MongoDB

What Is Fast?

New Jersey New York

Page 21: High Performance Applications with MongoDB

What Is Fast?

New Jersey New York

Page 22: High Performance Applications with MongoDB

What Is Fast?

New Jersey New York

Page 23: High Performance Applications with MongoDB

Must address the "limiting factor"

Page 24: High Performance Applications with MongoDB

Application

DriverDB Requests

Page 25: High Performance Applications with MongoDB

Application

SchemaIndexes

Storage Engine

DriverDB Requests

Page 26: High Performance Applications with MongoDB

Application

SchemaIndexes

File System

Storage Engine

OS

DriverDB Requests

Page 27: High Performance Applications with MongoDB

Application

SchemaIndexes

File System

Storage Engine

OS

DriverDB Requests

Page 28: High Performance Applications with MongoDB

Application

SchemaIndexes

File System

Storage Engine

OS

DriverDB Requests

PhysicalConceptual

Page 29: High Performance Applications with MongoDB

Application

SchemaIndexes

File System

Storage Engine

OS

DriverDB Requests

PhysicalConceptual

Page 30: High Performance Applications with MongoDB

SchemaIndexes

Storage Engine

Page 31: High Performance Applications with MongoDB

Schema

Page 32: High Performance Applications with MongoDB

Schema Patterns

Page 33: High Performance Applications with MongoDB
Page 34: High Performance Applications with MongoDB
Page 35: High Performance Applications with MongoDB

Schema Anti-Patterns

Page 36: High Performance Applications with MongoDB

Parent Object

OVER-NORMALIZATION OVER-EMBEDDING

Schema Anti-Patterns

Page 37: High Performance Applications with MongoDB

Unbounded growth

Deeply nested arrays

Really large documents

Schema Anti-Patterns: over-embedding

Page 38: High Performance Applications with MongoDB

Unbounded growth

Deeply nested arrays

Really large documents

Schema Anti-Patterns: over-embedding

Page 39: High Performance Applications with MongoDB

Unbounded growth

Deeply nested arrays

Really large documents

Schema Anti-Patterns: over-embedding

Page 40: High Performance Applications with MongoDB

Unbounded growth

Deeply nested arrays

Really large documents

Schema Anti-Patterns: over-normalizing

you are over-normalizing if you are doing JOINS in your application

instead of "finds"

Page 41: High Performance Applications with MongoDB

reads vs writes

polymorphic collections

polymorphic fields

Schema Anti-Patterns: signs of trouble

Page 42: High Performance Applications with MongoDB

reads vs writes

polymorphic collections

polymorphic fields

Schema Anti-Patterns: signs of trouble

Page 43: High Performance Applications with MongoDB

reads vs writes

polymorphic collections

polymorphic fields

Schema Anti-Patterns: signs of trouble

Page 44: High Performance Applications with MongoDB

bad regex queries

lots of indexes

no indexes

Schema Anti-Patterns: can't use indexes

Page 45: High Performance Applications with MongoDB

bad regex queries

lots of indexes

no indexes

Schema Anti-Patterns: can't use indexes

Page 46: High Performance Applications with MongoDB

bad regex queries

lots of indexes

no indexes

Schema Anti-Patterns: can't use indexes

Page 47: High Performance Applications with MongoDB

bad regex queries

lots of indexes

no indexes

Schema Anti-Patterns: can't use indexes

Page 48: High Performance Applications with MongoDB

Indexes

Page 49: High Performance Applications with MongoDB
Page 50: High Performance Applications with MongoDB
Page 51: High Performance Applications with MongoDB
Page 52: High Performance Applications with MongoDB
Page 53: High Performance Applications with MongoDB
Page 54: High Performance Applications with MongoDB
Page 55: High Performance Applications with MongoDB

Storage Engine

Page 56: High Performance Applications with MongoDB

Storage Engine: compression

Page 57: High Performance Applications with MongoDB
Page 58: High Performance Applications with MongoDB
Page 59: High Performance Applications with MongoDB

Is It Fast?

Disk IOPS a factor?

Page 60: High Performance Applications with MongoDB

Is It Fast?

Disk IOPS a factor?Data compressible?

Page 61: High Performance Applications with MongoDB

Is It Fast?

Disk IOPS a factor?Data compressible?Extra CPU cycles available?

Page 62: High Performance Applications with MongoDB

Is It Fast?

Disk IOPS a factor?Data compressible?Extra CPU cycles available?

- Yes WT FTW!

Page 63: High Performance Applications with MongoDB

Storage Engine: concurrency

Page 64: High Performance Applications with MongoDB

MMAPV1 WiredTiger

Granularity lowLatency low

Granularity highLatency higher

Page 65: High Performance Applications with MongoDB

New Jersey New York

Page 66: High Performance Applications with MongoDB

New Jersey New York

Page 67: High Performance Applications with MongoDB

New Jersey New York

Page 68: High Performance Applications with MongoDB

New Jersey New York

Page 69: High Performance Applications with MongoDB

New Jersey New York

Page 70: High Performance Applications with MongoDB

Is It Fast?

Multiple threads?

Page 71: High Performance Applications with MongoDB

Is It Fast?

Multiple threads?Same collection?

Page 72: High Performance Applications with MongoDB

Is It Fast?

Multiple threads?Same collection?Not the same document(s)?

Page 73: High Performance Applications with MongoDB

Is It Fast?

Multiple threads?Same collection?Not the same document(s)?Extra CPU cycles available?

Page 74: High Performance Applications with MongoDB

Is It Fast?

Multiple threads?Same collection?Not the same document(s)?Extra CPU cycles available?Not "too many" workers?

Page 75: High Performance Applications with MongoDB

Is It Fast?

Multiple threads?Same collection?Not the same document(s)?Extra CPU cycles available?Not "too many" workers?

- Yes WT FTW!

Page 76: High Performance Applications with MongoDB

Uniform Latest Zipfian0

10,000

20,000

30,000

40,000

50,000

60,000

Throughput: 50/50 Workload in RAM

Page 77: High Performance Applications with MongoDB
Page 78: High Performance Applications with MongoDB
Page 79: High Performance Applications with MongoDB

htop

Page 80: High Performance Applications with MongoDB

Storage Engine: write-pattern

Page 81: High Performance Applications with MongoDB

{ timestamp_hour: ISODate("2015-11-10T23:00:00.000Z"), type: “memory_used”, values: { 0: { 0: 999999, 1: 999999, …, 59: 1000000 }, 1: { 0: 2000000, 1: 2000000, …, 59: 1000000 }, …, 58: { 0: 1600000, 1: 1200000, …, 59: 1100000 }, 59: { 0: 1300000, 1: 1400000, …, 59: 1500000 } }}

Page 82: High Performance Applications with MongoDB

{ timestamp_hour: ISODate("2015-11-10T23:00:00.000Z"), type: “memory_used”, values: { 0: { 0: 999999, 1: 999999, …, 59: 1000000 }, 1: { 0: 2000000, 1: 2000000, …, 59: 1000000 }, …, 58: { 0: 1600000, 1: 1200000, …, 59: 1100000 }, 59: { 0: 1300000, 1: 1400000, …, 59: 1500000 } }}db.metrics.update( { timestamp_hour: ISODate("2015-11-10T23:00:00.000Z"), type: “memory_used” }, {$set: {“values.59.59”: 2000000 } })

Page 83: High Performance Applications with MongoDB

{ timestamp_hour: ISODate("2015-11-10T23:00:00.000Z"), type: “memory_used”, values: { 0: { 0: 999999, 1: 999999, …, 59: 1000000 }, 1: { 0: 2000000, 1: 2000000, …, 59: 1000000 }, …, 58: { 0: 1600000, 1: 1200000, …, 59: 1100000 }, 59: { 0: 1300000, 1: 1400000, …, 59: 2000000 } }}db.metrics.update( { timestamp_hour: ISODate("2015-11-10T23:00:00.000Z"), type: “memory_used” }, {$set: {“values.59.59”: 2000000 } })

Page 84: High Performance Applications with MongoDB

{ timestamp_hour: ISODate("2015-11-10T23:00:00.000Z"), type: “memory_used”, values: { 0: { 0: 999999, 1: 999999, …, 59: 1000000 }, 1: { 0: 2000000, 1: 2000000, …, 59: 1000000 }, …, 58: { 0: 1600000, 1: 1200000, …, 59: 1100000 }, 59: { 0: 1300000, 1: 1400000, …, 59: 1500000 } }}

Page 85: High Performance Applications with MongoDB

{ timestamp_hour: ISODate("2015-11-10T23:00:00.000Z"), type: “memory_used”, values: { 0: { 0: 999999, 1: 999999, …, 59: 1000000 }, 1: { 0: 2000000, 1: 2000000, …, 59: 1000000 }, …, 58: { 0: 1600000, 1: 1200000, …, 59: 1100000 }, 59: { 0: 1300000, 1: 1400000, …, 59: 1500000 } }}db.metrics.update( { timestamp_hour: ISODate("2015-11-10T23:00:00.000Z"), type: “memory_used” }, {$set: {“values.59.59”: 2000000 } })

Page 86: High Performance Applications with MongoDB

{ timestamp_hour: ISODate("2015-11-10T23:00:00.000Z"), type: “memory_used”, values: { 0: { 0: 999999, 1: 999999, …, 59: 1000000 }, 1: { 0: 2000000, 1: 2000000, …, 59: 1000000 }, …, 58: { 0: 1600000, 1: 1200000, …, 59: 1100000 }, 59: { 0: 1300000, 1: 1400000, …, 59: 1500000 } }}db.metrics.update( { timestamp_hour: ISODate("2015-11-10T23:00:00.000Z"), type: “memory_used” }, {$set: {“values.59.59”: 2000000 } })

{ timestamp_hour: ISODate("2015-11-10T23:00:00.000Z"), type: “memory_used”, values: { 0: { 0: 999999, 1: 999999, …, 59: 1000000 }, 1: { 0: 2000000, 1: 2000000, …, 59: 1000000 }, …, 58: { 0: 1600000, 1: 1200000, …, 59: 1100000 }, 59: { 0: 1300000, 1: 1400000, …, 59: 2000000 } }}

Page 87: High Performance Applications with MongoDB

MongoDB Cloud Monitoring

Page 88: High Performance Applications with MongoDB

Benchmark your own applicationUse realistic workloadUse real dataMeasure throughput and latency

Page 89: High Performance Applications with MongoDB
Page 90: High Performance Applications with MongoDB