SlideShare a Scribd company logo
1 of 32
Download to read offline
MongoDB And Server
Performance
Alon	
  Horev	
  
Israel	
  MongoDB	
  user	
  group	
  	
  
August	
  2013	
  
Meta
Alon	
  Horev	
  
Twitter:	
  @alonhorev	
  	
  
Mail:	
  alon@horev.net	
  
Blog:	
  http://alon.horev.net	
  
	
  
	
  
Performance Considerations
! Speed	
  -­‐	
  make	
  things	
  fast:	
  
! Optimize	
  queries	
  
! Optimize	
  schema	
  
! Growth	
  -­‐	
  things	
  should	
  stay	
  fast:	
  
! When	
  will	
  queries	
  slow	
  down?	
  
! When	
  will	
  we	
  run	
  out	
  of	
  resources?	
  
! Troubleshoot	
  -­‐	
  what	
  went	
  wrong?	
  
Tools Of The Trade
! Profiling	
  –	
  focus	
  on	
  specific	
  queries	
  
! Query	
  explain	
  
! system.profile	
  collection	
  
! Monitoring	
  –	
  focus	
  on	
  overall	
  performance	
  
! logs	
  
! MMS	
  
! Mongo	
  commands	
  
! CLI	
  tools	
  
! munin,	
  nagios,	
  etc’	
  
Server Resources
	
  
! Storage:	
  DISK,	
  RAM	
  
! Network	
  
! CPU	
  
Storage
MongoDB	
  storage	
  stack:	
  
	
  
MongoDB	
  
Memory	
  Mapped	
  Files	
  
Page	
  Cache	
  	
  
Disk	
  and	
  RAM	
  
Storage – Disk And RAM
	
  
! Variety	
  of	
  storage	
  types:	
  RAM,	
  SSD,	
  HDD	
  
! Different	
  attributes:	
  price,	
  volatility,	
  speed,	
  
access	
  patterns,	
  wear,	
  capacity,	
  latency	
  
! Most	
  systems	
  use	
  a	
  mix	
  
	
  
Compare
Attribute	
   RAM	
   SSD	
   HDD	
  
Volatile	
   Yes	
   No	
   No	
  
Wear	
   Very	
  Slow	
  	
   Fast	
   Slow	
  
Latency	
   Low	
   Low	
   High	
  
Read	
  MB/s	
   4000+	
   520	
   164	
  
Write	
  MB/s	
   4000+	
   480	
   160	
  
Price	
  per	
  GB	
   5.5	
  USD	
   0.5	
  USD	
   0.05	
  USD	
  
Page Cache
! Uses	
  RAM	
  to	
  cache	
  the	
  disk	
  
! Recently	
  accessed	
  buffers	
  are	
  saved	
  in	
  RAM	
  
! Writes	
  are	
  flushed	
  to	
  disk	
  in	
  the	
  background	
  
! Exists	
  in	
  all	
  modern	
  operating	
  systems	
  
! Already	
  extensively	
  used	
  by	
  file	
  systems	
  
User	
  Space	
   Kernel	
  Space	
  
Process	
  calls	
  
read/write	
  
disk	
  Page	
  Cache	
  
	
  	
  
File+Offset	
  -­‐>	
  Physical	
  Memory	
   Write	
  on	
  flush	
  
Read	
  on	
  fault	
  	
  
Memory Mapped Files
! Maps	
  a	
  chunk	
  of	
  a	
  file	
  to	
  a	
  chunk	
  of	
  memory	
  
! memory	
  access	
  translates	
  to	
  file	
  read/write	
  
! Page	
  cache	
  caches	
  reads	
  and	
  writes	
  
! Reduces	
  system	
  calls	
  and	
  memory	
  duplication	
  
! Reading	
  from	
  a	
  page	
  (4k)	
  that’s	
  not	
  in	
  memory	
  
triggers	
  the	
  infamous	
  page	
  fault	
  
User	
  Space	
   Kernel	
  Space	
  
Process	
  read	
  
or	
  writes	
  to	
  
memory	
  
Page	
  Cache	
  
	
  	
  
File+Offset	
  -­‐>	
  Physical	
  Memory	
  
Virtual	
  Memory	
  Manager	
  
maps	
  a	
  process	
  memory	
  
segment	
  to	
  file	
  +	
  offset	
  
read	
   write	
  
No	
  system	
  call!	
  
disk	
  
Write	
  on	
  flush	
  
Read	
  on	
  fault	
  	
  
Pros & Cons
! Pros:	
  
! Simple!	
  abstracts	
  away	
  RAM	
  and	
  disk	
  
! Cons:	
  
! Performance	
  not	
  always	
  predictable	
  
! Other	
  applications	
  can	
  hurt	
  mongo	
  
! Warm	
  up	
  –	
  first	
  query	
  is	
  slow	
  
! Can’t	
  lock	
  documents	
  in	
  memory	
  
	
  
Disk Limits - Capacity
! Indications:	
  crash	
  or	
  read-­‐only	
  mode	
  
! Capacity	
  can	
  be	
  predictable	
  
! db.collection.stats()	
  	
  
! size	
  
! avgObjSize	
  
! indexSizes	
  
! You	
  can	
  limit:	
  addShard	
  accepts	
  maxSize	
  
Disk Limits - Throughput
! Indications:	
  slow	
  queries,	
  high	
  lock	
  %	
  
! Is	
  the	
  disk	
  saturated?	
  
! iostat	
  –x	
  shows	
  disk	
  utilization	
  
! Is	
  it	
  Mongo?	
  
! iotop	
  shows	
  which	
  process	
  does	
  most	
  I/O	
  
! Disk	
  is	
  usually	
  faster	
  than	
  mongo	
  
! Load	
  often	
  indicates	
  lack	
  of	
  	
  RAM	
  
Many	
  page	
  faults	
  =	
  
Reading	
  a	
  lot	
  from	
  disk	
  =	
  
Slower	
  queries	
  
Disk	
  is	
  loaded	
  for	
  reads	
  =	
  
Disk	
  is	
  loaded	
  for	
  writes	
  
Queues	
  contain	
  blocked	
  
queries	
  waiting	
  in	
  line	
  
for	
  execution	
  
Write	
  lock	
  blocks	
  all	
  
reads.	
  This	
  time	
  slow	
  
writes	
  impact	
  reads!	
  
Offending Queries
>	
  db.currentOp()	
  
{	
  	
  "secs_running"	
  :	
  9,	
  
	
  	
  	
  	
  "numYields"	
  :	
  132,	
  #	
  number	
  of	
  page	
  faults	
  
	
  	
  	
  	
  "lockStats"	
  :	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  "timeLockedMicros"	
  :	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  "r"	
  :	
  NumberLong(4774),	
  #	
  held	
  the	
  read	
  lock	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  "w"	
  :	
  NumberLong(0)	
  }	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  "timeAcquiringMicros”:	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  "r"	
  :	
  NumberLong(2),	
  #	
  waited	
  for	
  read	
  lock	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  "w"	
  :	
  NumberLong(0)	
  }}}	
  
	
  
CLI utilities
! mongotop	
  –	
  active	
  queries	
  	
  and	
  duration	
  
! mongostat	
  –	
  faults,	
  queues,	
  locks,	
  queries	
  
! mongostat	
  and	
  the	
  MMS	
  rely	
  on	
  db.serverStatus()	
  
Memory Limits
! Indications:	
  page	
  faults,	
  slow	
  queries	
  
! Hard	
  to	
  predict:	
  limit	
  is	
  application	
  specific	
  
! Not	
  all	
  data	
  has	
  to	
  be	
  in	
  memory	
  
! Not	
  all	
  indexes	
  have	
  to	
  be	
  in	
  memory	
  
! Page	
  faults	
  can	
  be	
  acceptable	
  
! Example:	
  a	
  user	
  searching	
  an	
  archive	
  can	
  
experience	
  degraded	
  performance	
  
Working Set
! Working	
  set:	
  what	
  has	
  to	
  stay	
  in	
  RAM	
  
! Boundary	
  that	
  once	
  passed	
  –	
  hurts	
  application	
  
! Examples:	
  
! Documents	
  that	
  are	
  often	
  accesses	
  
! Parts	
  of	
  index	
  that	
  are	
  often	
  traversed	
  
! Entire	
  collection	
  when	
  query	
  isn’t	
  indexed	
  
Estimate Working Set
>	
  db.serverStatus({workingSet:	
  1})	
  #	
  new	
  in	
  2.4	
  
"workingSet"	
  :	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  "pagesInMemory"	
  :	
  <num>,	
  #	
  4k	
  pages	
  
	
  	
  	
  	
  	
  	
  	
  	
  "overSeconds"	
  :	
  <num>	
  #	
  oldest	
  page	
  age	
  
}	
  
#	
  if	
  oldest	
  page	
  is	
  rather	
  new	
  –	
  not	
  enough	
  RAM	
  
	
  
Mapped	
  -­‐	
  size	
  of	
  the	
  database	
  
Resident	
  -­‐	
  data	
  in	
  RAM	
  
	
  
	
  
Non-­‐mapped	
  -­‐	
  internal	
  data	
  structures	
  
like	
  threads	
  and	
  connections	
  
Network
! Usually	
  not	
  the	
  bottleneck	
  
! 	
  Could	
  be	
  for	
  multi	
  data	
  center	
  clusters	
  
! Latency	
  hurts	
  cross	
  shard	
  queries	
  
! Bandwidth	
  is	
  limited	
  
! CLI	
  monitoring	
  tools	
  
! nethogs	
  –	
  bandwidth	
  per	
  process	
  
! iftop	
  –	
  bandwidth	
  per	
  remote	
  host	
  
CPU
! Can	
  be	
  a	
  bottleneck	
  for	
  query-­‐heavy	
  apps	
  
! Load	
  often	
  indicates	
  inefficient	
  queries	
  
! JavaScript	
  (both	
  spidermonky	
  and	
  v8)	
  
! One	
  interpreter	
  per	
  mongod	
  
! Means	
  one	
  core	
  per	
  mongod!	
  
! Aggregation	
  framework	
  is	
  better!	
  
! Fast	
  –	
  implemented	
  in	
  C++	
  
	
  
CPU limits
! top	
  –	
  understand	
  ‘load	
  average’	
  
! Needed	
  processors	
  for	
  a	
  period	
  of	
  time	
  
! Three	
  periods	
  (minutes):	
  1	
  ,	
  5,	
  15	
  
! Example:	
  	
  
! load	
  average:	
  4.12,	
  3.79,	
  3.61	
  
! For	
  a	
  two	
  processor	
  system,	
  it’s	
  overloaded	
  
! For	
  a	
  16	
  processor	
  system,	
  it’s	
  underutilized	
  
! Find	
  number	
  of	
  processors	
  in	
  /proc/cpuinfo	
  
Hardware Specification
! No	
  one	
  size	
  fits	
  all	
  
! Simulate	
  your	
  application	
  
! Disk:	
  fill	
  the	
  database	
  
! RAM	
  +	
  CPU:	
  run	
  common	
  queries	
  
To Scale Or Not To Scale?
! Will	
  you	
  really	
  need	
  a	
  cluster?	
  
! It	
  has	
  several	
  moving	
  parts	
  
! You	
  can	
  do	
  it	
  later	
  with	
  no	
  code	
  changes	
  
! You	
  will	
  need	
  to	
  migrate	
  the	
  data	
  
! Sharding	
  
! Scale	
  writes	
  
! Unlimited	
  capacity	
  
! Replica	
  sets	
  
! Scale	
  reads	
  
! Failover	
  
Read/Write	
  ratio	
  can	
  help	
  predict	
  scaling	
  requirements	
  

More Related Content

What's hot

Development to Production with Sharded MongoDB Clusters
Development to Production with Sharded MongoDB ClustersDevelopment to Production with Sharded MongoDB Clusters
Development to Production with Sharded MongoDB ClustersSeveralnines
 
Advanced Administration, Monitoring and Backup
Advanced Administration, Monitoring and BackupAdvanced Administration, Monitoring and Backup
Advanced Administration, Monitoring and BackupMongoDB
 
Introducing MongoDB in a multi-site HA environment
Introducing MongoDB in a multi-site HA environmentIntroducing MongoDB in a multi-site HA environment
Introducing MongoDB in a multi-site HA environmentSebastian Geib
 
초보자를 위한 분산 캐시 이야기
초보자를 위한 분산 캐시 이야기초보자를 위한 분산 캐시 이야기
초보자를 위한 분산 캐시 이야기OnGameServer
 
Setting up mongodb sharded cluster in 30 minutes
Setting up mongodb sharded cluster in 30 minutesSetting up mongodb sharded cluster in 30 minutes
Setting up mongodb sharded cluster in 30 minutesSudheer Kondla
 
PostgreSQL Replication in 10 Minutes - SCALE
PostgreSQL Replication in 10  Minutes - SCALEPostgreSQL Replication in 10  Minutes - SCALE
PostgreSQL Replication in 10 Minutes - SCALEPostgreSQL Experts, Inc.
 
Elephant Roads: a tour of Postgres forks
Elephant Roads: a tour of Postgres forksElephant Roads: a tour of Postgres forks
Elephant Roads: a tour of Postgres forksCommand Prompt., Inc
 
Redis trouble shooting_eng
Redis trouble shooting_engRedis trouble shooting_eng
Redis trouble shooting_engDaeMyung Kang
 
MongoDB: Advantages of an Open Source NoSQL Database
MongoDB: Advantages of an Open Source NoSQL DatabaseMongoDB: Advantages of an Open Source NoSQL Database
MongoDB: Advantages of an Open Source NoSQL DatabaseFITC
 
How to optimize CloudLinux OS limits
How to optimize CloudLinux OS limitsHow to optimize CloudLinux OS limits
How to optimize CloudLinux OS limitsCloudLinux
 
Troubleshooting redis
Troubleshooting redisTroubleshooting redis
Troubleshooting redisDaeMyung Kang
 
Optimizing MongoDB: Lessons Learned at Localytics
Optimizing MongoDB: Lessons Learned at LocalyticsOptimizing MongoDB: Lessons Learned at Localytics
Optimizing MongoDB: Lessons Learned at LocalyticsBenjamin Darfler
 
MongoDB World 2015 - A Technical Introduction to WiredTiger
MongoDB World 2015 - A Technical Introduction to WiredTigerMongoDB World 2015 - A Technical Introduction to WiredTiger
MongoDB World 2015 - A Technical Introduction to WiredTigerWiredTiger
 

What's hot (20)

Shootout at the PAAS Corral
Shootout at the PAAS CorralShootout at the PAAS Corral
Shootout at the PAAS Corral
 
92 grand prix_2013
92 grand prix_201392 grand prix_2013
92 grand prix_2013
 
Development to Production with Sharded MongoDB Clusters
Development to Production with Sharded MongoDB ClustersDevelopment to Production with Sharded MongoDB Clusters
Development to Production with Sharded MongoDB Clusters
 
Advanced Administration, Monitoring and Backup
Advanced Administration, Monitoring and BackupAdvanced Administration, Monitoring and Backup
Advanced Administration, Monitoring and Backup
 
7 Ways To Crash Postgres
7 Ways To Crash Postgres7 Ways To Crash Postgres
7 Ways To Crash Postgres
 
Introducing MongoDB in a multi-site HA environment
Introducing MongoDB in a multi-site HA environmentIntroducing MongoDB in a multi-site HA environment
Introducing MongoDB in a multi-site HA environment
 
초보자를 위한 분산 캐시 이야기
초보자를 위한 분산 캐시 이야기초보자를 위한 분산 캐시 이야기
초보자를 위한 분산 캐시 이야기
 
Setting up mongodb sharded cluster in 30 minutes
Setting up mongodb sharded cluster in 30 minutesSetting up mongodb sharded cluster in 30 minutes
Setting up mongodb sharded cluster in 30 minutes
 
GUC Tutorial Package (9.0)
GUC Tutorial Package (9.0)GUC Tutorial Package (9.0)
GUC Tutorial Package (9.0)
 
PostgreSQL Replication in 10 Minutes - SCALE
PostgreSQL Replication in 10  Minutes - SCALEPostgreSQL Replication in 10  Minutes - SCALE
PostgreSQL Replication in 10 Minutes - SCALE
 
Elephant Roads: a tour of Postgres forks
Elephant Roads: a tour of Postgres forksElephant Roads: a tour of Postgres forks
Elephant Roads: a tour of Postgres forks
 
Redis trouble shooting_eng
Redis trouble shooting_engRedis trouble shooting_eng
Redis trouble shooting_eng
 
MongoDB: Advantages of an Open Source NoSQL Database
MongoDB: Advantages of an Open Source NoSQL DatabaseMongoDB: Advantages of an Open Source NoSQL Database
MongoDB: Advantages of an Open Source NoSQL Database
 
How to optimize CloudLinux OS limits
How to optimize CloudLinux OS limitsHow to optimize CloudLinux OS limits
How to optimize CloudLinux OS limits
 
Troubleshooting redis
Troubleshooting redisTroubleshooting redis
Troubleshooting redis
 
Optimizing MongoDB: Lessons Learned at Localytics
Optimizing MongoDB: Lessons Learned at LocalyticsOptimizing MongoDB: Lessons Learned at Localytics
Optimizing MongoDB: Lessons Learned at Localytics
 
Fail over fail_back
Fail over fail_backFail over fail_back
Fail over fail_back
 
Redis acc 2015_eng
Redis acc 2015_engRedis acc 2015_eng
Redis acc 2015_eng
 
MongoDB World 2015 - A Technical Introduction to WiredTiger
MongoDB World 2015 - A Technical Introduction to WiredTigerMongoDB World 2015 - A Technical Introduction to WiredTiger
MongoDB World 2015 - A Technical Introduction to WiredTiger
 
Deployment
DeploymentDeployment
Deployment
 

Viewers also liked

MongoDB Performance Tuning
MongoDB Performance TuningMongoDB Performance Tuning
MongoDB Performance TuningMongoDB
 
mongodb와 mysql의 CRUD 연산의 성능 비교
mongodb와 mysql의 CRUD 연산의 성능 비교mongodb와 mysql의 CRUD 연산의 성능 비교
mongodb와 mysql의 CRUD 연산의 성능 비교Woo Yeong Choi
 
Mongo DB 성능최적화 전략
Mongo DB 성능최적화 전략Mongo DB 성능최적화 전략
Mongo DB 성능최적화 전략Jin wook
 
Optimizing Slow Queries with Indexes and Creativity
Optimizing Slow Queries with Indexes and CreativityOptimizing Slow Queries with Indexes and Creativity
Optimizing Slow Queries with Indexes and CreativityMongoDB
 
Hardware Provisioning for MongoDB
Hardware Provisioning for MongoDBHardware Provisioning for MongoDB
Hardware Provisioning for MongoDBMongoDB
 
MongoDB WiredTiger Internals
MongoDB WiredTiger InternalsMongoDB WiredTiger Internals
MongoDB WiredTiger InternalsNorberto Leite
 
Mongo performance tuning: tips and tricks
Mongo performance tuning: tips and tricksMongo performance tuning: tips and tricks
Mongo performance tuning: tips and tricksVladimir Malyk
 
MongoDB Performance Tuning and Monitoring
MongoDB Performance Tuning and MonitoringMongoDB Performance Tuning and Monitoring
MongoDB Performance Tuning and MonitoringMongoDB
 
Concurrency Patterns with MongoDB
Concurrency Patterns with MongoDBConcurrency Patterns with MongoDB
Concurrency Patterns with MongoDBYann Cluchey
 

Viewers also liked (9)

MongoDB Performance Tuning
MongoDB Performance TuningMongoDB Performance Tuning
MongoDB Performance Tuning
 
mongodb와 mysql의 CRUD 연산의 성능 비교
mongodb와 mysql의 CRUD 연산의 성능 비교mongodb와 mysql의 CRUD 연산의 성능 비교
mongodb와 mysql의 CRUD 연산의 성능 비교
 
Mongo DB 성능최적화 전략
Mongo DB 성능최적화 전략Mongo DB 성능최적화 전략
Mongo DB 성능최적화 전략
 
Optimizing Slow Queries with Indexes and Creativity
Optimizing Slow Queries with Indexes and CreativityOptimizing Slow Queries with Indexes and Creativity
Optimizing Slow Queries with Indexes and Creativity
 
Hardware Provisioning for MongoDB
Hardware Provisioning for MongoDBHardware Provisioning for MongoDB
Hardware Provisioning for MongoDB
 
MongoDB WiredTiger Internals
MongoDB WiredTiger InternalsMongoDB WiredTiger Internals
MongoDB WiredTiger Internals
 
Mongo performance tuning: tips and tricks
Mongo performance tuning: tips and tricksMongo performance tuning: tips and tricks
Mongo performance tuning: tips and tricks
 
MongoDB Performance Tuning and Monitoring
MongoDB Performance Tuning and MonitoringMongoDB Performance Tuning and Monitoring
MongoDB Performance Tuning and Monitoring
 
Concurrency Patterns with MongoDB
Concurrency Patterns with MongoDBConcurrency Patterns with MongoDB
Concurrency Patterns with MongoDB
 

Similar to MongoDB and server performance

MongoDB Capacity Planning
MongoDB Capacity PlanningMongoDB Capacity Planning
MongoDB Capacity PlanningNorberto Leite
 
Capacity Planning
Capacity PlanningCapacity Planning
Capacity PlanningMongoDB
 
Oracle Open World 2014: Lies, Damned Lies, and I/O Statistics [ CON3671]
Oracle Open World 2014: Lies, Damned Lies, and I/O Statistics [ CON3671]Oracle Open World 2014: Lies, Damned Lies, and I/O Statistics [ CON3671]
Oracle Open World 2014: Lies, Damned Lies, and I/O Statistics [ CON3671]Kyle Hailey
 
Capacity Planning For Your Growing MongoDB Cluster
Capacity Planning For Your Growing MongoDB ClusterCapacity Planning For Your Growing MongoDB Cluster
Capacity Planning For Your Growing MongoDB ClusterMongoDB
 
Webinar: Capacity Planning
Webinar: Capacity PlanningWebinar: Capacity Planning
Webinar: Capacity PlanningMongoDB
 
Hardware Provisioning
Hardware ProvisioningHardware Provisioning
Hardware ProvisioningMongoDB
 
MongoDB World 2019: Finding the Right MongoDB Atlas Cluster Size: Does This I...
MongoDB World 2019: Finding the Right MongoDB Atlas Cluster Size: Does This I...MongoDB World 2019: Finding the Right MongoDB Atlas Cluster Size: Does This I...
MongoDB World 2019: Finding the Right MongoDB Atlas Cluster Size: Does This I...MongoDB
 
Apache Con 2008 Top 10 Mistakes
Apache Con 2008 Top 10 MistakesApache Con 2008 Top 10 Mistakes
Apache Con 2008 Top 10 MistakesJohn Coggeshall
 
Deployment Strategies
Deployment StrategiesDeployment Strategies
Deployment StrategiesMongoDB
 
Lamp Stack Optimization
Lamp Stack OptimizationLamp Stack Optimization
Lamp Stack OptimizationDave Ross
 
Deployment Strategies (Mongo Austin)
Deployment Strategies (Mongo Austin)Deployment Strategies (Mongo Austin)
Deployment Strategies (Mongo Austin)MongoDB
 
Performance Whack-a-Mole Tutorial (pgCon 2009)
Performance Whack-a-Mole Tutorial (pgCon 2009) Performance Whack-a-Mole Tutorial (pgCon 2009)
Performance Whack-a-Mole Tutorial (pgCon 2009) PostgreSQL Experts, Inc.
 
Tuning Linux Windows and Firebird for Heavy Workload
Tuning Linux Windows and Firebird for Heavy WorkloadTuning Linux Windows and Firebird for Heavy Workload
Tuning Linux Windows and Firebird for Heavy WorkloadMarius Adrian Popa
 
Web20expo Scalable Web Arch
Web20expo Scalable Web ArchWeb20expo Scalable Web Arch
Web20expo Scalable Web Archroyans
 
Web20expo Scalable Web Arch
Web20expo Scalable Web ArchWeb20expo Scalable Web Arch
Web20expo Scalable Web Archguest18a0f1
 
Web20expo Scalable Web Arch
Web20expo Scalable Web ArchWeb20expo Scalable Web Arch
Web20expo Scalable Web Archmclee
 

Similar to MongoDB and server performance (20)

MongoDB Capacity Planning
MongoDB Capacity PlanningMongoDB Capacity Planning
MongoDB Capacity Planning
 
Capacity Planning
Capacity PlanningCapacity Planning
Capacity Planning
 
Performance
PerformancePerformance
Performance
 
Oracle Open World 2014: Lies, Damned Lies, and I/O Statistics [ CON3671]
Oracle Open World 2014: Lies, Damned Lies, and I/O Statistics [ CON3671]Oracle Open World 2014: Lies, Damned Lies, and I/O Statistics [ CON3671]
Oracle Open World 2014: Lies, Damned Lies, and I/O Statistics [ CON3671]
 
Capacity Planning For Your Growing MongoDB Cluster
Capacity Planning For Your Growing MongoDB ClusterCapacity Planning For Your Growing MongoDB Cluster
Capacity Planning For Your Growing MongoDB Cluster
 
Capacityplanning
Capacityplanning Capacityplanning
Capacityplanning
 
Webinar: Capacity Planning
Webinar: Capacity PlanningWebinar: Capacity Planning
Webinar: Capacity Planning
 
Cassandra as Memcache
Cassandra as MemcacheCassandra as Memcache
Cassandra as Memcache
 
Hardware Provisioning
Hardware ProvisioningHardware Provisioning
Hardware Provisioning
 
MongoDB World 2019: Finding the Right MongoDB Atlas Cluster Size: Does This I...
MongoDB World 2019: Finding the Right MongoDB Atlas Cluster Size: Does This I...MongoDB World 2019: Finding the Right MongoDB Atlas Cluster Size: Does This I...
MongoDB World 2019: Finding the Right MongoDB Atlas Cluster Size: Does This I...
 
Apache Con 2008 Top 10 Mistakes
Apache Con 2008 Top 10 MistakesApache Con 2008 Top 10 Mistakes
Apache Con 2008 Top 10 Mistakes
 
Real world capacity
Real world capacityReal world capacity
Real world capacity
 
Deployment Strategies
Deployment StrategiesDeployment Strategies
Deployment Strategies
 
Lamp Stack Optimization
Lamp Stack OptimizationLamp Stack Optimization
Lamp Stack Optimization
 
Deployment Strategies (Mongo Austin)
Deployment Strategies (Mongo Austin)Deployment Strategies (Mongo Austin)
Deployment Strategies (Mongo Austin)
 
Performance Whack-a-Mole Tutorial (pgCon 2009)
Performance Whack-a-Mole Tutorial (pgCon 2009) Performance Whack-a-Mole Tutorial (pgCon 2009)
Performance Whack-a-Mole Tutorial (pgCon 2009)
 
Tuning Linux Windows and Firebird for Heavy Workload
Tuning Linux Windows and Firebird for Heavy WorkloadTuning Linux Windows and Firebird for Heavy Workload
Tuning Linux Windows and Firebird for Heavy Workload
 
Web20expo Scalable Web Arch
Web20expo Scalable Web ArchWeb20expo Scalable Web Arch
Web20expo Scalable Web Arch
 
Web20expo Scalable Web Arch
Web20expo Scalable Web ArchWeb20expo Scalable Web Arch
Web20expo Scalable Web Arch
 
Web20expo Scalable Web Arch
Web20expo Scalable Web ArchWeb20expo Scalable Web Arch
Web20expo Scalable Web Arch
 

Recently uploaded

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 

Recently uploaded (20)

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 

MongoDB and server performance

  • 1. MongoDB And Server Performance Alon  Horev   Israel  MongoDB  user  group     August  2013  
  • 2. Meta Alon  Horev   Twitter:  @alonhorev     Mail:  alon@horev.net   Blog:  http://alon.horev.net      
  • 3. Performance Considerations ! Speed  -­‐  make  things  fast:   ! Optimize  queries   ! Optimize  schema   ! Growth  -­‐  things  should  stay  fast:   ! When  will  queries  slow  down?   ! When  will  we  run  out  of  resources?   ! Troubleshoot  -­‐  what  went  wrong?  
  • 4. Tools Of The Trade ! Profiling  –  focus  on  specific  queries   ! Query  explain   ! system.profile  collection   ! Monitoring  –  focus  on  overall  performance   ! logs   ! MMS   ! Mongo  commands   ! CLI  tools   ! munin,  nagios,  etc’  
  • 5. Server Resources   ! Storage:  DISK,  RAM   ! Network   ! CPU  
  • 6. Storage MongoDB  storage  stack:     MongoDB   Memory  Mapped  Files   Page  Cache     Disk  and  RAM  
  • 7. Storage – Disk And RAM   ! Variety  of  storage  types:  RAM,  SSD,  HDD   ! Different  attributes:  price,  volatility,  speed,   access  patterns,  wear,  capacity,  latency   ! Most  systems  use  a  mix    
  • 8. Compare Attribute   RAM   SSD   HDD   Volatile   Yes   No   No   Wear   Very  Slow     Fast   Slow   Latency   Low   Low   High   Read  MB/s   4000+   520   164   Write  MB/s   4000+   480   160   Price  per  GB   5.5  USD   0.5  USD   0.05  USD  
  • 9. Page Cache ! Uses  RAM  to  cache  the  disk   ! Recently  accessed  buffers  are  saved  in  RAM   ! Writes  are  flushed  to  disk  in  the  background   ! Exists  in  all  modern  operating  systems   ! Already  extensively  used  by  file  systems  
  • 10. User  Space   Kernel  Space   Process  calls   read/write   disk  Page  Cache       File+Offset  -­‐>  Physical  Memory   Write  on  flush   Read  on  fault    
  • 11. Memory Mapped Files ! Maps  a  chunk  of  a  file  to  a  chunk  of  memory   ! memory  access  translates  to  file  read/write   ! Page  cache  caches  reads  and  writes   ! Reduces  system  calls  and  memory  duplication   ! Reading  from  a  page  (4k)  that’s  not  in  memory   triggers  the  infamous  page  fault  
  • 12. User  Space   Kernel  Space   Process  read   or  writes  to   memory   Page  Cache       File+Offset  -­‐>  Physical  Memory   Virtual  Memory  Manager   maps  a  process  memory   segment  to  file  +  offset   read   write   No  system  call!   disk   Write  on  flush   Read  on  fault    
  • 13. Pros & Cons ! Pros:   ! Simple!  abstracts  away  RAM  and  disk   ! Cons:   ! Performance  not  always  predictable   ! Other  applications  can  hurt  mongo   ! Warm  up  –  first  query  is  slow   ! Can’t  lock  documents  in  memory    
  • 14.
  • 15. Disk Limits - Capacity ! Indications:  crash  or  read-­‐only  mode   ! Capacity  can  be  predictable   ! db.collection.stats()     ! size   ! avgObjSize   ! indexSizes   ! You  can  limit:  addShard  accepts  maxSize  
  • 16.
  • 17. Disk Limits - Throughput ! Indications:  slow  queries,  high  lock  %   ! Is  the  disk  saturated?   ! iostat  –x  shows  disk  utilization   ! Is  it  Mongo?   ! iotop  shows  which  process  does  most  I/O   ! Disk  is  usually  faster  than  mongo   ! Load  often  indicates  lack  of    RAM  
  • 18. Many  page  faults  =   Reading  a  lot  from  disk  =   Slower  queries   Disk  is  loaded  for  reads  =   Disk  is  loaded  for  writes  
  • 19. Queues  contain  blocked   queries  waiting  in  line   for  execution   Write  lock  blocks  all   reads.  This  time  slow   writes  impact  reads!  
  • 20. Offending Queries >  db.currentOp()   {    "secs_running"  :  9,          "numYields"  :  132,  #  number  of  page  faults          "lockStats"  :  {                    "timeLockedMicros"  :  {                                "r"  :  NumberLong(4774),  #  held  the  read  lock                                "w"  :  NumberLong(0)  }                    "timeAcquiringMicros”:  {                                "r"  :  NumberLong(2),  #  waited  for  read  lock                                "w"  :  NumberLong(0)  }}}    
  • 21. CLI utilities ! mongotop  –  active  queries    and  duration   ! mongostat  –  faults,  queues,  locks,  queries   ! mongostat  and  the  MMS  rely  on  db.serverStatus()  
  • 22. Memory Limits ! Indications:  page  faults,  slow  queries   ! Hard  to  predict:  limit  is  application  specific   ! Not  all  data  has  to  be  in  memory   ! Not  all  indexes  have  to  be  in  memory   ! Page  faults  can  be  acceptable   ! Example:  a  user  searching  an  archive  can   experience  degraded  performance  
  • 23. Working Set ! Working  set:  what  has  to  stay  in  RAM   ! Boundary  that  once  passed  –  hurts  application   ! Examples:   ! Documents  that  are  often  accesses   ! Parts  of  index  that  are  often  traversed   ! Entire  collection  when  query  isn’t  indexed  
  • 24. Estimate Working Set >  db.serverStatus({workingSet:  1})  #  new  in  2.4   "workingSet"  :  {                  "pagesInMemory"  :  <num>,  #  4k  pages                  "overSeconds"  :  <num>  #  oldest  page  age   }   #  if  oldest  page  is  rather  new  –  not  enough  RAM    
  • 25. Mapped  -­‐  size  of  the  database   Resident  -­‐  data  in  RAM       Non-­‐mapped  -­‐  internal  data  structures   like  threads  and  connections  
  • 26. Network ! Usually  not  the  bottleneck   !  Could  be  for  multi  data  center  clusters   ! Latency  hurts  cross  shard  queries   ! Bandwidth  is  limited   ! CLI  monitoring  tools   ! nethogs  –  bandwidth  per  process   ! iftop  –  bandwidth  per  remote  host  
  • 27.
  • 28. CPU ! Can  be  a  bottleneck  for  query-­‐heavy  apps   ! Load  often  indicates  inefficient  queries   ! JavaScript  (both  spidermonky  and  v8)   ! One  interpreter  per  mongod   ! Means  one  core  per  mongod!   ! Aggregation  framework  is  better!   ! Fast  –  implemented  in  C++    
  • 29. CPU limits ! top  –  understand  ‘load  average’   ! Needed  processors  for  a  period  of  time   ! Three  periods  (minutes):  1  ,  5,  15   ! Example:     ! load  average:  4.12,  3.79,  3.61   ! For  a  two  processor  system,  it’s  overloaded   ! For  a  16  processor  system,  it’s  underutilized   ! Find  number  of  processors  in  /proc/cpuinfo  
  • 30. Hardware Specification ! No  one  size  fits  all   ! Simulate  your  application   ! Disk:  fill  the  database   ! RAM  +  CPU:  run  common  queries  
  • 31. To Scale Or Not To Scale? ! Will  you  really  need  a  cluster?   ! It  has  several  moving  parts   ! You  can  do  it  later  with  no  code  changes   ! You  will  need  to  migrate  the  data   ! Sharding   ! Scale  writes   ! Unlimited  capacity   ! Replica  sets   ! Scale  reads   ! Failover  
  • 32. Read/Write  ratio  can  help  predict  scaling  requirements