Tuning Linux For MongoDB
Tuning Linux For MongoDB
Tuning Linux For MongoDB
Tim Vaillancourt
Sr. Technical Operations Architect
About Me
• Joined Percona in January 2016
• Sr Technical Operations Architect for MongoDB
• Previous:
• EA DICE (MySQL DBA)
• EA SPORTS (Sys/NoSQL DBA Ops)
• Amazon/AbeBooks Inc (Sys/MySQL+NoSQL DBA Ops)
• Main techs: MySQL, MongoDB, Cassandra, Solr, Redis, queues, etc
• 10+ years tuning Linux for database workloads (off and on)
• Not a kernel-guy, learned from breaking things
Linux
• UNIX-like, mostly POSIX-compliant operating system
• First released on September 17th, 1991 by Linus Torvalds
• 50Mhz CPUs were considered fast
• CPUs had 1 core
• RAM was measured in megabytes
• Ethernet speed was 1 - 10mbps
• General purpose
• It will run on a Raspberry Pi -> Mainframes
• Geared towards many different users and use cases
• Linux 3.2+ is much more efficient
MongoDB
• Document-oriented database first released in 2009
• Thread per connection model
• Non-contiguous memory access pattern
• Storage Engines
• MMAPv1
• Keeps warm data in Linux filesystem cache
• Highly random I/O pattern
• Cache uses all the RAM it can get
• Few background threads
MongoDB
• Storage Engines
• WiredTiger and RocksDB
• Built-in Compression
• Uses combination of in-heap cache and filesystem cache
• In-heap cache: uncompressed pages
• Filesystem cache: compressed pages
• Relatively sequential write patterns, low write overhead
• Scales with RAM, Disk and CPUs
Ulimit
• Allows per-Linux-user resource constraints
• Number of User-level Processes
• Number of Open Files
• CPU Seconds
• Scheduling Priority
• Others…
• MongoDB
• Should probably have it’s own VM,
container or server
• Creates a process for each connection
Ulimit
• MongoDB (continued)
• Creates an open file for each active data file on disk
• 64,000 open files and 64,000 max processes is a good start
/etc/udev/rules.d/60-mongodb-disk.rules:
# set deadline scheduler and 32/16kb read-ahead for /dev/sda
ACTION=="add|change", KERNEL=="sda", ATTR{queue/scheduler}="deadline", ATTR{bdi/read_ahead_kb}="16"
• https://www.percona.com/doc/percona-monitoring-and-management/index.html
• https://github.com/Percona-Lab/grafana_mongodb_dashboards
• https://github.com/Percona-Lab/prometheus_mongodb_exporter
• https://www.percona.com/blog/2014/04/28/oom-relation-vm-swappiness0-new-kernel/
Questions?
DATABASE PERFORMANCE
MATTERS