mongodb days uk: scaling mongodb with docker and cgroups

41
Scaling MongoDB with Docker and cgroups Marco Bonezzi Technical Services Engineer, MongoDB [email protected] @marcobonezzi

Upload: mongodb

Post on 16-Apr-2017

2.562 views

Category:

Technology


3 download

TRANSCRIPT

Page 1: MongoDB Days UK: Scaling MongoDB with Docker and cgroups

Scaling MongoDB with Docker and cgroups

Marco Bonezzi Technical Services Engineer, MongoDB

[email protected]

@marcobonezzi

Page 2: MongoDB Days UK: Scaling MongoDB with Docker and cgroups

2

Agenda

•  MongoDBandWiredTiger

•  WhyshouldyouuseDockerwithMongoDB?

•  ScalingMongoDBwithDocker

•  Results

Page 3: MongoDB Days UK: Scaling MongoDB with Docker and cgroups

PS

S

config

SS

PS

S

SHARD2

SHARD1

mongos

Page 4: MongoDB Days UK: Scaling MongoDB with Docker and cgroups

MongoDB and WiredTiger

Page 5: MongoDB Days UK: Scaling MongoDB with Docker and cgroups

5

MongoDB3.0andWiredTiger

MongoDBStorageEngineAPI+WiredTigerstorageengineMainfeatures•  Document-levelconcurrencycontrol•  Durability•  Compression•  EncrypHonatrest(3.2)

Page 6: MongoDB Days UK: Scaling MongoDB with Docker and cgroups

6

WiredTigerincreasedscalability

•  MulH-corescaling

•  Lock-freealgorithms(hazard-pointers)

•  Noin-placeupdate(skiplists)

•  Eliminateblockingwithconcurrencycontrol

Page 7: MongoDB Days UK: Scaling MongoDB with Docker and cgroups

7

WiredTigerincreasedscalability

•  Higherthroughputonwriteandupdates(skiplists)

Page 8: MongoDB Days UK: Scaling MongoDB with Docker and cgroups

8

Bestprac>cesforWiredTiger

•  XFSfilesystem

•  #concurrentac+veopera+ons•  Bestthroughputwhen<=#CPU

•  MemoryandWiredTigercache

•  storage.wiredTiger.engineConfig.cacheSizeGB

Page 9: MongoDB Days UK: Scaling MongoDB with Docker and cgroups

9

MongoDBMemoryandWiredTigercache

cacheSizeGB=max(1GB,0.5*memory)

WiredTigercache: Usedfordataandindexesonly

Page 10: MongoDB Days UK: Scaling MongoDB with Docker and cgroups

10

MongoDBMemoryandWiredTigercache

WiredTigercache: Usedtostorethecurrentworkingset

cacheSizeGB=max(1GB,0.5*memory)

Page 11: MongoDB Days UK: Scaling MongoDB with Docker and cgroups

11

MongoDBMemoryandWiredTigercache

MongoDBMemory:mongodprocess:connecHons,aggregaHons,mapReduce,etc

cacheSizeGB=max(1GB,0.5*memory)

Totalmemory=mem(mongod)+cacheSizeGB

Page 12: MongoDB Days UK: Scaling MongoDB with Docker and cgroups

12

ContainerizingMongoDB

•  MongoDBdockerfile(orcreateyourown)hPps://github.com/sisteming/mongodocker/[mongodb.docker]

•  Genericmongod.confconfiguraHonfile•  Automateyourdeploymentforscaling:

•  #mongods• Portsandnetworkinterfaces•  SingleormulHplehosts• CPUormemorylimits

Page 13: MongoDB Days UK: Scaling MongoDB with Docker and cgroups

13

Summary

•  MongoDBwithWiredTiger:•  Higherthroughputwithincreasedscalability•  AddiHonalfeatures:compression,encrypHon•  WiredTigercachememory

•  MongoDBonDocker:•  Genericimage•  Automatetoscale

Page 14: MongoDB Days UK: Scaling MongoDB with Docker and cgroups

Why should you use Docker for MongoDB?

Page 15: MongoDB Days UK: Scaling MongoDB with Docker and cgroups

15

DockerAccordingtodocker.com:

HowcanthisbeusefulformyMongoDBdeployments?

(That’swhyyouareheretoday)

Page 16: MongoDB Days UK: Scaling MongoDB with Docker and cgroups

16

WhyshouldyouuseDockerforMongoDB?

Build•  anddefineyour

containerbasedonOS,mongodbreleaseorconfiguraHon

•  Buildonce,deployeverywhere

Page 17: MongoDB Days UK: Scaling MongoDB with Docker and cgroups

17

WhyshouldyouuseDockerforMongoDB?

Ship•  DeploythesameimageinDev,Pre-prod(or

evenProd!)withthesamesetup•  MongoDBstandalone,ReplicaSetsorcluster

withmulHpleshardsfromthesameimage

Page 18: MongoDB Days UK: Scaling MongoDB with Docker and cgroups

18

WhyshouldyouuseDockerforMongoDB?

Run•  YourmongoDBprocessesisolatedfromthe

restofprocessesonthesystem•  Isolatetheresourcesforco-locatedmongodb

processes

Page 19: MongoDB Days UK: Scaling MongoDB with Docker and cgroups

19

VS

Page 20: MongoDB Days UK: Scaling MongoDB with Docker and cgroups

20

Resourcemanagement

CgroupsImplementaHononDocker

Page 21: MongoDB Days UK: Scaling MongoDB with Docker and cgroups

21

Resourcemanagement

CgroupsImplementaHononDocker

--cpu-shares--cpuset-cpus

--memory

--blkio-weight

--net

Page 22: MongoDB Days UK: Scaling MongoDB with Docker and cgroups

22

Summary

UsingDockerforMongoDBisusefulformanyreasons:

•  Buildonce,deployeverywhere•  Environmentportability•  MongodprocessisolaHon•  Fasterdeploymentsofcomplexclusters•  Resourcemanagementwithcgroups

Page 23: MongoDB Days UK: Scaling MongoDB with Docker and cgroups

Scaling MongoDB with Docker

config

SS

PS

S

PS

S

SHARD2

SHARD1

mongos

Page 24: MongoDB Days UK: Scaling MongoDB with Docker and cgroups

24

UsecasesofMongoDBandDockerMicrosharding

•  MulHpleco-locatedmongodinstances

•  Eachmongod=shard•  AggregaHons

Mul>pleinstances•  Controlco-locatedmongod

processesonsameserver•  Differentinstances/uses

Page 25: MongoDB Days UK: Scaling MongoDB with Docker and cgroups

25

Memorylimit

MEM=($TOTAL_MEMORY-2048)/$NUM_MONGODWiredTigercache=$MEM/2

Page 26: MongoDB Days UK: Scaling MongoDB with Docker and cgroups

26

CPUlimit

NUMBER=from0toMAX_CPU_CORES(i.e.with32cores->--cpuset=0,16)

Page 27: MongoDB Days UK: Scaling MongoDB with Docker and cgroups

27

Docker+cgroups:Memorymapping

WiredTigercachesize:definedforeachshard50%MongoDBmemory–50%WiredTigercache

Page 28: MongoDB Days UK: Scaling MongoDB with Docker and cgroups

28

MongoDBonDocker+cgroups:CPUmapping

Eachshardmappedto1(ormore)core(using--cpuset-cpus)

core0 core1 core2 core3

core4 core5 core6 core7

core8 core9 core10 core11

core12 core13 core14 core15

Page 29: MongoDB Days UK: Scaling MongoDB with Docker and cgroups

29

ResourceusagewithDocker•  Understandingresourceusage:•  ContainerstatsavailablethroughDockerremoteAPI:

GET/containers/(id)/statsecho-e"GET/containers/$id/statsHTTP/1.0\r\n"|

nc-U/var/run/docker.sock

Page 30: MongoDB Days UK: Scaling MongoDB with Docker and cgroups

30

Summary

•  UsesofscalingMongoDBwithDocker

•  LimiHngCPUonyourcontainer

•  DefiningmemoryandWiredTigercachelimits

•  ResourceusagewithDocker

Page 31: MongoDB Days UK: Scaling MongoDB with Docker and cgroups

Results

Page 32: MongoDB Days UK: Scaling MongoDB with Docker and cgroups

32

TargetandscenariosScalabilitybymicroshardingMongoDBwith

WiredTigerusingdocker(andcgroups)

•  Maintestscenarios:– ShardedclusterwithP/S/SReplicaSet

•  From2upto16shards– Eachscenario:

• numberofthreads:8,16,32• Write/ReadraHo:95/5• memoryandWiredTigercache

Page 33: MongoDB Days UK: Scaling MongoDB with Docker and cgroups

33

Workload

POCDriver (https://github.com/johnlpage/POCDriver) • Easy to use

–  java -jar POCDriver.jar -d 610 -c mongoDB://node1:37019 -o test.log -i 95 -t 10 -k 5 –e

• Automatic collection sharding with even distribution

Page 34: MongoDB Days UK: Scaling MongoDB with Docker and cgroups

34

Workloadresultssummary

ScenarioAMEM=2GB

WiredTigercache=1GB

ScenarioBMEM=32GB/$NUM_SHARDS

WiredTigercache=$MEM/2(GB)

Page 35: MongoDB Days UK: Scaling MongoDB with Docker and cgroups

35

TotalInserts

Page 36: MongoDB Days UK: Scaling MongoDB with Docker and cgroups

36

Inserts/second

Page 37: MongoDB Days UK: Scaling MongoDB with Docker and cgroups

37

Workloadresultssummary

3xc3x4largeAWSinstances:16cores32GBram

SSDvolumes

0

10

20

30

40

50

0 2 4 6 8 10 12 14 16 18

Millions

TotalInsertsvs#shards

TotalInserts

0

10

20

30

40

50

0 2 4 6 8 10 12 14 16 18

Millions

TotalInsertsvs#shards

TotalInserts

ScenarioAMEM=2GB

WiredTigercache=1GB

ScenarioBMEM=32GB/$NUM_SHARDS

WiredTigercache=$MEM/2(GB)

Page 38: MongoDB Days UK: Scaling MongoDB with Docker and cgroups

Summary

Page 39: MongoDB Days UK: Scaling MongoDB with Docker and cgroups

39

Keys for scaling MongoDB and WiredTiger with Docker

•  Startfromagenericimage,automatetoscale

•  Setlimitstoallyourcontainers

•  Define–WiredTigerCacheSizeGBoneachmongod

•  EsHmateanddefineresourcedistribuHonforyourarchitecture

•  Deployandtestwithyourownworkload

Page 40: MongoDB Days UK: Scaling MongoDB with Docker and cgroups

Questions?

Thank You!

Marco Bonezzi

@marcobonezzi

[email protected]

Page 41: MongoDB Days UK: Scaling MongoDB with Docker and cgroups

#MDBDaysmongodb.com

Getyourtechnicalques+onsansweredBenjaminBri3enlounge(3rdfloor),10:00-17:00Byappointmentonly–registerinperson