SlideShare a Scribd company logo
1 of 46
Download to read offline
MADRID · NOV 18-19 · 2016
19th November 2016
18:30-19:15
MongoDB:
Improve the performance
of your application
by @juanroycouto
@codemotion_es
1
MADRID · NOV 18-19 · 2016
#whoami
❖ @juanroycouto
❖ www.juanroy.es
❖ www.mongodbspain.com/en/author/juanroy
❖ juanroycouto@gmail.com
❖ MongoDB DBA at Grupo Undanet
2
MADRID · NOV 18-19 · 2016
#Agenda
3
● Data Model
● Application Patterns
● .explain()
● Indexes
● Storage Engines
● Query Optimizer
● Aggregation Framework
● Profiling
● Tuning
● Sharding
● Storage & Compression
MADRID · NOV 18-19 · 2016
#Data Model
4
MADRID · NOV 18-19 · 2016
#Data Model
5
● All the information in one document:
○ No joins
○ Single read
○ Higher performance
○ ACID compliance at the document level
● MMAPv1: avoid unbounded document growth
● WiredTiger rewrites the document for each update
MADRID · NOV 18-19 · 2016
#Application Patterns
6
● Modify only those fields that have changed
● Project only the fields you need
● Avoid negation in queries
● Use Covered Queries when possible
● Avoid scatter-gather queries
● Write Concern:
○ w : 0 → faster than w : all
MADRID · NOV 18-19 · 2016
#.explain()
7
● Use .explain() to get the time a query needs
● Verbose options:
○ queryPlanner (default)
○ executionStats (stats for the winner plan)
○ allPlansExecution (stats for all candidate
plans)
MADRID · NOV 18-19 · 2016
#.explain()
8
● In-memory sorting data is limited to 32MB (you
need an index)
● My index selectivity is the relationship between
nReturned and totalKeysExamined
MADRID · NOV 18-19 · 2016
#Indexes
9
MADRID · NOV 18-19 · 2016
#Indexes
10
● Improve the performance of
read-intensive apps
● Overhead:
○ Write operations
○ Disk usage
○ Memory consumption
MADRID · NOV 18-19 · 2016
● Working Set is made of:
○ Indexes
○ Your most frequently accessed data
#Indexes-Working Set
11
MADRID · NOV 18-19 · 2016
● If your Working Set does not fit into RAM:
○ Increment your RAM
○ Shard the database
○ Avoid scan all documents in the collection
■ Page faults
■ You will fill in your Working Set with
infrequent accessed data
#Indexes-Working Set
12
MADRID · NOV 18-19 · 2016
#Indexes-Before creating indexes
13
● Understand your data
● How your queries will be
● Create as few indexes as possible
● Put your highly selective fields first in the index
● Check your current indexes before creating new
ones
MADRID · NOV 18-19 · 2016
#Indexes-Advices
14
● Do not index a little cardinality field
● Check your index performance
● Monitor your system to check if:
○ Your strategy is still up to date
○ You need new indexes
○ You can remove unnecessary indexes
MADRID · NOV 18-19 · 2016
#Indexes-Compound
15
● A compound index has better performance than:
○ Single indexes
○ Intersection
● Remove indexes that are prefixes of other
● The value of the combined fields must have high
cardinality
MADRID · NOV 18-19 · 2016
#Indexes-Compound
16
>db.collection.createIndex( { equality, sort, range } );
>db.collection.find(
{
book_author : ‘John’, #equality
book_id : { $gt : 54 } #range
} )
.sort( { book_price : 1 } ); #sort
MADRID · NOV 18-19 · 2016
> use test
> db.example.createIndex( { a : 1, b : 1 } );
> db.example.explain("executionStats").find( { a : 56, b : 87 } );
"nReturned" : 100,
"executionTimeMillis" : 2,
"totalKeysExamined" : 100,
"totalDocsExamined" : 100,
> db.example.dropIndex( { a : 1, b : 1 } );
> db.example.createIndex( { a : 1 } );
> db.example.createIndex( { b : 1 } );
> db.example.explain("executionStats").find( { a : 56, b : 87 } );
"nReturned" : 100,
"executionTimeMillis" : 36,
"totalKeysExamined" : 10000,
"totalDocsExamined" : 10000
#Indexes-Compound example
17
MADRID · NOV 18-19 · 2016
#Indexes-Covered Queries
18
● They return results from the indexes
● A covered query does not read from the
document level:
○ ndocsExamined : 0
● In the index must be all the fields:
○ Included in the query
○ Returned by the query
MADRID · NOV 18-19 · 2016
#Indexes-Covered Queries example
19
> use test
> db.example.createIndex( { a : 1, b : 1 } );
> db.example.explain("executionStats").find( { a : 56, b : 87 } );
"nReturned" : 100,
"executionTimeMillis" : 3,
"totalKeysExamined" : 100,
"totalDocsExamined" : 100
> db.example.explain("executionStats").find( { a : 56, b : 87 }, {
_id : 0, a : 1, b : 1 } );
"nReturned" : 100,
"executionTimeMillis" : 3,
"totalKeysExamined" : 100,
"totalDocsExamined" : 0
MADRID · NOV 18-19 · 2016
#Indexes-TTL
20
● TTL (TimeToLive) Indexes
○ Allow the user to specify a period of time after
which the data will be automatically deleted
MADRID · NOV 18-19 · 2016
#Indexes-TTL example
21
> use test
> db.timetolive.createIndex( { date : 1 } , { expireAfterSeconds: 20 } );
> db.timetolive.insert( { date : new Date() } );
> db.timetolive.find().pretty()
{
"_id" : ObjectId("581fb43f5626d57bcf66fe73"),
"date" : ISODate("2016-11-06T22:52:47.373Z")
}
> db.timetolive.count()
0
>
The background task that removes expired documents
runs every 60 seconds.
MADRID · NOV 18-19 · 2016
#Indexes-Partial
22
● Partial Indexes
○ Allow to index a subset of your data by
specifying a filtering expression during the
index creation
○ Better query performance while reducing
system overhead
MADRID · NOV 18-19 · 2016
#Indexes-Partial example
> use test
> db.sysprofile.createIndex( { ns : 1, op : 1 }, {
partialFilterExpression : { millis : { $gt : 10000 } } } );
> db.sysprofile.explain().find( { ns : 'school2.students', op :
'query' }, { millis : 1 } );
"winningPlan" : {
"inputStage" : {
"stage" : "COLLSCAN"
> db.sysprofile.explain().find( { ns : 'school2.students', op :
'query', millis : { $gte : 20000 } }, { millis : 1 } );
"winningPlan" : {
"inputStage" : {
"stage" : "IXSCAN"
23
MADRID · NOV 18-19 · 2016
#Indexes-Sparse
24
● Sparse Indexes
○ Only contain entries for documents that
contain a specific field
○ Smaller and more efficient indexes
MADRID · NOV 18-19 · 2016
> use test
> db.test.createIndex( { b : 1 } , { sparse : true } );
> db.test.stats()
16384
>
> db.test.createIndex( { b : 1 } );
> db.test.stats()
2580480
>
#Indexes-Sparse example
25
MADRID · NOV 18-19 · 2016
#Storage Engines-WiredTiger
26
● Reduced storage space and higher I/O scalability
● It compresses indexes into RAM, freeing up
Working Set for documents
● Performance (granular concurrency control)
● Native compression:
○ per collection
○ per index
MADRID · NOV 18-19 · 2016
#Storage Engines-WiredTiger
27
● Types of compression:
○ Snappy (default): Data and Journal
○ zlib: maximum compression
○ Prefix: for indexes
MADRID · NOV 18-19 · 2016
#Storage Engines: In-Memory
28
● Extreme performance coupled with real time
analytics for the most demanding,
latency-sensitive applications
● Delivers the extreme throughput and predictable
latency
● Eliminates the need for separate caching layers
MADRID · NOV 18-19 · 2016
#Query Optimizer
29
● It selects the best index to use
● It periodically runs alternate query plans and
selects the index with the best response time for
each query type
● The results of these tests are stored as a cached
query plan and are updated periodically
MADRID · NOV 18-19 · 2016
#Aggregation Framework
30
MADRID · NOV 18-19 · 2016
#Aggregation Framework
31
● Use $indexStats to determine how frequently
your index is used
● Each shard has its own statistics
● Stats are reset when you restart your mongod
service
>db.collection.aggregate([
{ $indexStats : {} }
])
MADRID · NOV 18-19 · 2016
#Aggregation Framework example
32
> db.test.aggregate([ { $indexStats : {} } ]).pretty()
{
"name" : "b_1",
"key" : {
"b" : 1
},
"host" : "hostname:27017",
"accesses" : {
"ops" : NumberLong(4),
"since" : ISODate("2016-11-07T00:05:39.771Z")
}
}
...
MADRID · NOV 18-19 · 2016
#Tools-Compass
33
MADRID · NOV 18-19 · 2016
#Tools-Compass
34
● MongoDB Compass
○ Analyze the size and usage of the indexes
○ It offers visual plan explanations
○ Index creation
○ Real time stats
○ Identify and fix performance and data problems
MADRID · NOV 18-19 · 2016
#Tools-Ops Manager
35
● The Visual Query Profiler allows to analyze a
query performance and recommends on the
addition of indexes
● It can be used to visualize output from the
profiler when identifying slow queries
MADRID · NOV 18-19 · 2016
#Tools-Cloud Manager & Atlas
36
● Use the Query Targeting chart
MADRID · NOV 18-19 · 2016
#Tools-Profiling
37
● Guess the slowest queries for improving their
indexes
● Log information for all events or only those whose
duration exceeds a configurable threshold (100ms
default)
MADRID · NOV 18-19 · 2016
#Tools-Profiling example
38
> db.setProfilingLevel(2)
{ "was" : 0, "slowms" : 100, "ok" : 1 }
> db.example.find( { c : 98 } );
> db.system.profile.find().pretty()
{
"op" : "query",
"ns" : "test.example",
"query" : {
"find" : "example",
"filter" : {
"c" : 98
}
},
…
"millis" : 6
MADRID · NOV 18-19 · 2016
#Tuning-SSD
39
● Most disk access patterns are not sequential
● Data files benefit from SSDs
● MongoDB journal files have high sequential write
patterns (good for spinning disks)
● RAM/SSDs better than spinning drives
● Use high performance storage
● Avoid networked storage
MADRID · NOV 18-19 · 2016
#Tuning-CPU
40
● MongoDB has better performance on faster CPUs
● The MongoDB WiredTiger Storage Engine is better
able to saturate multi-core processor resources than
the MMAPv1 Storage Engine
MADRID · NOV 18-19 · 2016
#Tuning-Thread
41
● The WiredTiger Storage Engine is multi-threaded
and can take advantage of many CPU Cores
MADRID · NOV 18-19 · 2016
#Sharding
42
● The balancer has been moved from the mongos to
the primary member of the config server
● Sharding improves the performance of reads
● Benefits (even with a ‘poor’ shard key and
scatter-gather):
○ A larger amount of memory to store indexes
○ Parallelize queries across shards reducing latency
MADRID · NOV 18-19 · 2016
#Storage & Compression types
43
● Balance query latency with storage density and
cost by assigning data sets based on a value
such as a timestamp to specific storage devices
MADRID · NOV 18-19 · 2016
#Storage & Compression types
44
● Recent, frequently accessed data can be assigned to
high performance SSDs with Snappy compression
● Older, less frequently accessed data is tagged to
lower-throughput hard disk drives compressed with
zlib to attain maximum storage density with a lower
cost-per-bit
● As data ages, MongoDB will automatically migrates it
between shards
MADRID · NOV 18-19 · 2016
#Questions?
45
Questions?
MongoDB:
Improve the performance of your application
by @juanroycouto
MADRID · NOV 18-19 · 2016
46
Thank you for your attention!

More Related Content

What's hot

ManetoDB: Key/Value storage, BigData in Open Stack_Сергей Ковалев, Илья Свиридов
ManetoDB: Key/Value storage, BigData in Open Stack_Сергей Ковалев, Илья СвиридовManetoDB: Key/Value storage, BigData in Open Stack_Сергей Ковалев, Илья Свиридов
ManetoDB: Key/Value storage, BigData in Open Stack_Сергей Ковалев, Илья СвиридовGeeksLab Odessa
 
Tweaking perfomance on high-load projects_Думанский Дмитрий
Tweaking perfomance on high-load projects_Думанский ДмитрийTweaking perfomance on high-load projects_Думанский Дмитрий
Tweaking perfomance on high-load projects_Думанский ДмитрийGeeksLab Odessa
 
MongoDB - visualisation of slow operations
MongoDB - visualisation of slow operationsMongoDB - visualisation of slow operations
MongoDB - visualisation of slow operationsKay1A
 
Techniques used in RDF Data Publishing at Nature Publishing Group
Techniques used in RDF Data Publishing at Nature Publishing GroupTechniques used in RDF Data Publishing at Nature Publishing Group
Techniques used in RDF Data Publishing at Nature Publishing GroupTony Hammond
 
JDD 2016 - Michal Matloka - Small Intro To Big Data
JDD 2016 - Michal Matloka - Small Intro To Big DataJDD 2016 - Michal Matloka - Small Intro To Big Data
JDD 2016 - Michal Matloka - Small Intro To Big DataPROIDEA
 
RedisConf18 - Redis and Elasticsearch
RedisConf18 - Redis and ElasticsearchRedisConf18 - Redis and Elasticsearch
RedisConf18 - Redis and ElasticsearchRedis Labs
 
MongoDB - javascript for your data
MongoDB - javascript for your dataMongoDB - javascript for your data
MongoDB - javascript for your dataaaronheckmann
 
Webinar: MongoDB Use Cases within the Oil, Gas, and Energy Industries
Webinar: MongoDB Use Cases within the Oil, Gas, and Energy IndustriesWebinar: MongoDB Use Cases within the Oil, Gas, and Energy Industries
Webinar: MongoDB Use Cases within the Oil, Gas, and Energy IndustriesMongoDB
 
Eventually, time will kill your data pipeline
Eventually, time will kill your data pipelineEventually, time will kill your data pipeline
Eventually, time will kill your data pipelineLars Albertsson
 
Small intro to Big Data - Old version
Small intro to Big Data - Old versionSmall intro to Big Data - Old version
Small intro to Big Data - Old versionSoftwareMill
 
Conceptos básicos. Seminario web 4: Indexación avanzada, índices de texto y g...
Conceptos básicos. Seminario web 4: Indexación avanzada, índices de texto y g...Conceptos básicos. Seminario web 4: Indexación avanzada, índices de texto y g...
Conceptos básicos. Seminario web 4: Indexación avanzada, índices de texto y g...MongoDB
 
An introduction to MongoDB
An introduction to MongoDBAn introduction to MongoDB
An introduction to MongoDBCésar Trigo
 
Austin bdug 2011_01_27_small_and_big_data
Austin bdug 2011_01_27_small_and_big_dataAustin bdug 2011_01_27_small_and_big_data
Austin bdug 2011_01_27_small_and_big_dataAlex Pinkin
 
MongoDB Europe 2016 - Big Data meets Big Compute
MongoDB Europe 2016 - Big Data meets Big ComputeMongoDB Europe 2016 - Big Data meets Big Compute
MongoDB Europe 2016 - Big Data meets Big ComputeMongoDB
 
J-Day Kraków: Listen to the sounds of your application
J-Day Kraków: Listen to the sounds of your applicationJ-Day Kraków: Listen to the sounds of your application
J-Day Kraków: Listen to the sounds of your applicationMaciej Bilas
 
MongoDB - An Introduction
MongoDB - An IntroductionMongoDB - An Introduction
MongoDB - An Introductionsethfloydjr
 
Combine Spring Data Neo4j and Spring Boot to quickl
Combine Spring Data Neo4j and Spring Boot to quicklCombine Spring Data Neo4j and Spring Boot to quickl
Combine Spring Data Neo4j and Spring Boot to quicklNeo4j
 
Data Con LA 2019 - Hybrid Transactional Analytical Processing (HTAP) with Mar...
Data Con LA 2019 - Hybrid Transactional Analytical Processing (HTAP) with Mar...Data Con LA 2019 - Hybrid Transactional Analytical Processing (HTAP) with Mar...
Data Con LA 2019 - Hybrid Transactional Analytical Processing (HTAP) with Mar...Data Con LA
 
SOLR Power FTW: short version
SOLR Power FTW: short versionSOLR Power FTW: short version
SOLR Power FTW: short versionAlex Pinkin
 
Mongodb Performance
Mongodb PerformanceMongodb Performance
Mongodb PerformanceJack
 

What's hot (20)

ManetoDB: Key/Value storage, BigData in Open Stack_Сергей Ковалев, Илья Свиридов
ManetoDB: Key/Value storage, BigData in Open Stack_Сергей Ковалев, Илья СвиридовManetoDB: Key/Value storage, BigData in Open Stack_Сергей Ковалев, Илья Свиридов
ManetoDB: Key/Value storage, BigData in Open Stack_Сергей Ковалев, Илья Свиридов
 
Tweaking perfomance on high-load projects_Думанский Дмитрий
Tweaking perfomance on high-load projects_Думанский ДмитрийTweaking perfomance on high-load projects_Думанский Дмитрий
Tweaking perfomance on high-load projects_Думанский Дмитрий
 
MongoDB - visualisation of slow operations
MongoDB - visualisation of slow operationsMongoDB - visualisation of slow operations
MongoDB - visualisation of slow operations
 
Techniques used in RDF Data Publishing at Nature Publishing Group
Techniques used in RDF Data Publishing at Nature Publishing GroupTechniques used in RDF Data Publishing at Nature Publishing Group
Techniques used in RDF Data Publishing at Nature Publishing Group
 
JDD 2016 - Michal Matloka - Small Intro To Big Data
JDD 2016 - Michal Matloka - Small Intro To Big DataJDD 2016 - Michal Matloka - Small Intro To Big Data
JDD 2016 - Michal Matloka - Small Intro To Big Data
 
RedisConf18 - Redis and Elasticsearch
RedisConf18 - Redis and ElasticsearchRedisConf18 - Redis and Elasticsearch
RedisConf18 - Redis and Elasticsearch
 
MongoDB - javascript for your data
MongoDB - javascript for your dataMongoDB - javascript for your data
MongoDB - javascript for your data
 
Webinar: MongoDB Use Cases within the Oil, Gas, and Energy Industries
Webinar: MongoDB Use Cases within the Oil, Gas, and Energy IndustriesWebinar: MongoDB Use Cases within the Oil, Gas, and Energy Industries
Webinar: MongoDB Use Cases within the Oil, Gas, and Energy Industries
 
Eventually, time will kill your data pipeline
Eventually, time will kill your data pipelineEventually, time will kill your data pipeline
Eventually, time will kill your data pipeline
 
Small intro to Big Data - Old version
Small intro to Big Data - Old versionSmall intro to Big Data - Old version
Small intro to Big Data - Old version
 
Conceptos básicos. Seminario web 4: Indexación avanzada, índices de texto y g...
Conceptos básicos. Seminario web 4: Indexación avanzada, índices de texto y g...Conceptos básicos. Seminario web 4: Indexación avanzada, índices de texto y g...
Conceptos básicos. Seminario web 4: Indexación avanzada, índices de texto y g...
 
An introduction to MongoDB
An introduction to MongoDBAn introduction to MongoDB
An introduction to MongoDB
 
Austin bdug 2011_01_27_small_and_big_data
Austin bdug 2011_01_27_small_and_big_dataAustin bdug 2011_01_27_small_and_big_data
Austin bdug 2011_01_27_small_and_big_data
 
MongoDB Europe 2016 - Big Data meets Big Compute
MongoDB Europe 2016 - Big Data meets Big ComputeMongoDB Europe 2016 - Big Data meets Big Compute
MongoDB Europe 2016 - Big Data meets Big Compute
 
J-Day Kraków: Listen to the sounds of your application
J-Day Kraków: Listen to the sounds of your applicationJ-Day Kraków: Listen to the sounds of your application
J-Day Kraków: Listen to the sounds of your application
 
MongoDB - An Introduction
MongoDB - An IntroductionMongoDB - An Introduction
MongoDB - An Introduction
 
Combine Spring Data Neo4j and Spring Boot to quickl
Combine Spring Data Neo4j and Spring Boot to quicklCombine Spring Data Neo4j and Spring Boot to quickl
Combine Spring Data Neo4j and Spring Boot to quickl
 
Data Con LA 2019 - Hybrid Transactional Analytical Processing (HTAP) with Mar...
Data Con LA 2019 - Hybrid Transactional Analytical Processing (HTAP) with Mar...Data Con LA 2019 - Hybrid Transactional Analytical Processing (HTAP) with Mar...
Data Con LA 2019 - Hybrid Transactional Analytical Processing (HTAP) with Mar...
 
SOLR Power FTW: short version
SOLR Power FTW: short versionSOLR Power FTW: short version
SOLR Power FTW: short version
 
Mongodb Performance
Mongodb PerformanceMongodb Performance
Mongodb Performance
 

Similar to Mongo db improve the performance of your application codemotion2016

Indexing and Query Performance in MongoDB.pdf
Indexing and Query Performance in MongoDB.pdfIndexing and Query Performance in MongoDB.pdf
Indexing and Query Performance in MongoDB.pdfMalak Abu Hammad
 
MariaDB Paris Workshop 2023 - Performance Optimization
MariaDB Paris Workshop 2023 - Performance OptimizationMariaDB Paris Workshop 2023 - Performance Optimization
MariaDB Paris Workshop 2023 - Performance OptimizationMariaDB plc
 
Precog & MongoDB User Group: Skyrocket Your Analytics
Precog & MongoDB User Group: Skyrocket Your Analytics Precog & MongoDB User Group: Skyrocket Your Analytics
Precog & MongoDB User Group: Skyrocket Your Analytics MongoDB
 
Codemotion akka persistence, cqrs%2 fes y otras siglas del montón
Codemotion   akka persistence, cqrs%2 fes y otras siglas del montónCodemotion   akka persistence, cqrs%2 fes y otras siglas del montón
Codemotion akka persistence, cqrs%2 fes y otras siglas del montónJavier Santos Paniego
 
Our journey with druid - from initial research to full production scale
Our journey with druid - from initial research to full production scaleOur journey with druid - from initial research to full production scale
Our journey with druid - from initial research to full production scaleItai Yaffe
 
Patroni - HA PostgreSQL made easy
Patroni - HA PostgreSQL made easyPatroni - HA PostgreSQL made easy
Patroni - HA PostgreSQL made easyAlexander Kukushkin
 
Counting Unique Users in Real-Time: Here's a Challenge for You!
Counting Unique Users in Real-Time: Here's a Challenge for You!Counting Unique Users in Real-Time: Here's a Challenge for You!
Counting Unique Users in Real-Time: Here's a Challenge for You!DataWorks Summit
 
MongoDB Distilled
MongoDB DistilledMongoDB Distilled
MongoDB Distilledb0ris_1
 
Solr Power FTW: Powering NoSQL the World Over
Solr Power FTW: Powering NoSQL the World OverSolr Power FTW: Powering NoSQL the World Over
Solr Power FTW: Powering NoSQL the World OverAlex Pinkin
 
BSSML16 L8. REST API, Bindings, and Basic Workflows
BSSML16 L8. REST API, Bindings, and Basic WorkflowsBSSML16 L8. REST API, Bindings, and Basic Workflows
BSSML16 L8. REST API, Bindings, and Basic WorkflowsBigML, Inc
 
Avoiding Pitfalls for Cassandra.pdf
Avoiding Pitfalls for Cassandra.pdfAvoiding Pitfalls for Cassandra.pdf
Avoiding Pitfalls for Cassandra.pdfCédrick Lunven
 
Cloud Cost Management and Apache Spark with Xuan Wang
Cloud Cost Management and Apache Spark with Xuan WangCloud Cost Management and Apache Spark with Xuan Wang
Cloud Cost Management and Apache Spark with Xuan WangDatabricks
 
MongoDB 3.2 - a giant leap. What’s new?
MongoDB 3.2 - a giant leap. What’s new?MongoDB 3.2 - a giant leap. What’s new?
MongoDB 3.2 - a giant leap. What’s new?Binary Studio
 
R Statistics With MongoDB
R Statistics With MongoDBR Statistics With MongoDB
R Statistics With MongoDBMongoDB
 
R statistics with mongo db
R statistics with mongo dbR statistics with mongo db
R statistics with mongo dbMongoDB
 
Distributing Queries the Citus Way | PostgresConf US 2018 | Marco Slot
Distributing Queries the Citus Way | PostgresConf US 2018 | Marco SlotDistributing Queries the Citus Way | PostgresConf US 2018 | Marco Slot
Distributing Queries the Citus Way | PostgresConf US 2018 | Marco SlotCitus Data
 
How to make data available for analytics ASAP
How to make data available for analytics ASAPHow to make data available for analytics ASAP
How to make data available for analytics ASAPMariaDB plc
 

Similar to Mongo db improve the performance of your application codemotion2016 (20)

MongoDB FabLab León
MongoDB FabLab LeónMongoDB FabLab León
MongoDB FabLab León
 
Indexing and Query Performance in MongoDB.pdf
Indexing and Query Performance in MongoDB.pdfIndexing and Query Performance in MongoDB.pdf
Indexing and Query Performance in MongoDB.pdf
 
MariaDB Paris Workshop 2023 - Performance Optimization
MariaDB Paris Workshop 2023 - Performance OptimizationMariaDB Paris Workshop 2023 - Performance Optimization
MariaDB Paris Workshop 2023 - Performance Optimization
 
Precog & MongoDB User Group: Skyrocket Your Analytics
Precog & MongoDB User Group: Skyrocket Your Analytics Precog & MongoDB User Group: Skyrocket Your Analytics
Precog & MongoDB User Group: Skyrocket Your Analytics
 
Codemotion akka persistence, cqrs%2 fes y otras siglas del montón
Codemotion   akka persistence, cqrs%2 fes y otras siglas del montónCodemotion   akka persistence, cqrs%2 fes y otras siglas del montón
Codemotion akka persistence, cqrs%2 fes y otras siglas del montón
 
Demonstration
DemonstrationDemonstration
Demonstration
 
Druid
DruidDruid
Druid
 
Our journey with druid - from initial research to full production scale
Our journey with druid - from initial research to full production scaleOur journey with druid - from initial research to full production scale
Our journey with druid - from initial research to full production scale
 
Patroni - HA PostgreSQL made easy
Patroni - HA PostgreSQL made easyPatroni - HA PostgreSQL made easy
Patroni - HA PostgreSQL made easy
 
Counting Unique Users in Real-Time: Here's a Challenge for You!
Counting Unique Users in Real-Time: Here's a Challenge for You!Counting Unique Users in Real-Time: Here's a Challenge for You!
Counting Unique Users in Real-Time: Here's a Challenge for You!
 
MongoDB Distilled
MongoDB DistilledMongoDB Distilled
MongoDB Distilled
 
Solr Power FTW: Powering NoSQL the World Over
Solr Power FTW: Powering NoSQL the World OverSolr Power FTW: Powering NoSQL the World Over
Solr Power FTW: Powering NoSQL the World Over
 
BSSML16 L8. REST API, Bindings, and Basic Workflows
BSSML16 L8. REST API, Bindings, and Basic WorkflowsBSSML16 L8. REST API, Bindings, and Basic Workflows
BSSML16 L8. REST API, Bindings, and Basic Workflows
 
Avoiding Pitfalls for Cassandra.pdf
Avoiding Pitfalls for Cassandra.pdfAvoiding Pitfalls for Cassandra.pdf
Avoiding Pitfalls for Cassandra.pdf
 
Cloud Cost Management and Apache Spark with Xuan Wang
Cloud Cost Management and Apache Spark with Xuan WangCloud Cost Management and Apache Spark with Xuan Wang
Cloud Cost Management and Apache Spark with Xuan Wang
 
MongoDB 3.2 - a giant leap. What’s new?
MongoDB 3.2 - a giant leap. What’s new?MongoDB 3.2 - a giant leap. What’s new?
MongoDB 3.2 - a giant leap. What’s new?
 
R Statistics With MongoDB
R Statistics With MongoDBR Statistics With MongoDB
R Statistics With MongoDB
 
R statistics with mongo db
R statistics with mongo dbR statistics with mongo db
R statistics with mongo db
 
Distributing Queries the Citus Way | PostgresConf US 2018 | Marco Slot
Distributing Queries the Citus Way | PostgresConf US 2018 | Marco SlotDistributing Queries the Citus Way | PostgresConf US 2018 | Marco Slot
Distributing Queries the Citus Way | PostgresConf US 2018 | Marco Slot
 
How to make data available for analytics ASAP
How to make data available for analytics ASAPHow to make data available for analytics ASAP
How to make data available for analytics ASAP
 

Recently uploaded

20240419 - Measurecamp Amsterdam - SAM.pdf
20240419 - Measurecamp Amsterdam - SAM.pdf20240419 - Measurecamp Amsterdam - SAM.pdf
20240419 - Measurecamp Amsterdam - SAM.pdfHuman37
 
Minimizing AI Hallucinations/Confabulations and the Path towards AGI with Exa...
Minimizing AI Hallucinations/Confabulations and the Path towards AGI with Exa...Minimizing AI Hallucinations/Confabulations and the Path towards AGI with Exa...
Minimizing AI Hallucinations/Confabulations and the Path towards AGI with Exa...Thomas Poetter
 
Semantic Shed - Squashing and Squeezing.pptx
Semantic Shed - Squashing and Squeezing.pptxSemantic Shed - Squashing and Squeezing.pptx
Semantic Shed - Squashing and Squeezing.pptxMike Bennett
 
Effects of Smartphone Addiction on the Academic Performances of Grades 9 to 1...
Effects of Smartphone Addiction on the Academic Performances of Grades 9 to 1...Effects of Smartphone Addiction on the Academic Performances of Grades 9 to 1...
Effects of Smartphone Addiction on the Academic Performances of Grades 9 to 1...limedy534
 
Multiple time frame trading analysis -brianshannon.pdf
Multiple time frame trading analysis -brianshannon.pdfMultiple time frame trading analysis -brianshannon.pdf
Multiple time frame trading analysis -brianshannon.pdfchwongval
 
Top 5 Best Data Analytics Courses In Queens
Top 5 Best Data Analytics Courses In QueensTop 5 Best Data Analytics Courses In Queens
Top 5 Best Data Analytics Courses In Queensdataanalyticsqueen03
 
Student Profile Sample report on improving academic performance by uniting gr...
Student Profile Sample report on improving academic performance by uniting gr...Student Profile Sample report on improving academic performance by uniting gr...
Student Profile Sample report on improving academic performance by uniting gr...Seán Kennedy
 
Statistics, Data Analysis, and Decision Modeling, 5th edition by James R. Eva...
Statistics, Data Analysis, and Decision Modeling, 5th edition by James R. Eva...Statistics, Data Analysis, and Decision Modeling, 5th edition by James R. Eva...
Statistics, Data Analysis, and Decision Modeling, 5th edition by James R. Eva...ssuserf63bd7
 
原版1:1定制南十字星大学毕业证(SCU毕业证)#文凭成绩单#真实留信学历认证永久存档
原版1:1定制南十字星大学毕业证(SCU毕业证)#文凭成绩单#真实留信学历认证永久存档原版1:1定制南十字星大学毕业证(SCU毕业证)#文凭成绩单#真实留信学历认证永久存档
原版1:1定制南十字星大学毕业证(SCU毕业证)#文凭成绩单#真实留信学历认证永久存档208367051
 
RS 9000 Call In girls Dwarka Mor (DELHI)⇛9711147426🔝Delhi
RS 9000 Call In girls Dwarka Mor (DELHI)⇛9711147426🔝DelhiRS 9000 Call In girls Dwarka Mor (DELHI)⇛9711147426🔝Delhi
RS 9000 Call In girls Dwarka Mor (DELHI)⇛9711147426🔝Delhijennyeacort
 
Predictive Analysis for Loan Default Presentation : Data Analysis Project PPT
Predictive Analysis for Loan Default  Presentation : Data Analysis Project PPTPredictive Analysis for Loan Default  Presentation : Data Analysis Project PPT
Predictive Analysis for Loan Default Presentation : Data Analysis Project PPTBoston Institute of Analytics
 
Consent & Privacy Signals on Google *Pixels* - MeasureCamp Amsterdam 2024
Consent & Privacy Signals on Google *Pixels* - MeasureCamp Amsterdam 2024Consent & Privacy Signals on Google *Pixels* - MeasureCamp Amsterdam 2024
Consent & Privacy Signals on Google *Pixels* - MeasureCamp Amsterdam 2024thyngster
 
Identifying Appropriate Test Statistics Involving Population Mean
Identifying Appropriate Test Statistics Involving Population MeanIdentifying Appropriate Test Statistics Involving Population Mean
Identifying Appropriate Test Statistics Involving Population MeanMYRABACSAFRA2
 
Vision, Mission, Goals and Objectives ppt..pptx
Vision, Mission, Goals and Objectives ppt..pptxVision, Mission, Goals and Objectives ppt..pptx
Vision, Mission, Goals and Objectives ppt..pptxellehsormae
 
9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort service
9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort service9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort service
9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort servicejennyeacort
 
Data Analysis Project : Targeting the Right Customers, Presentation on Bank M...
Data Analysis Project : Targeting the Right Customers, Presentation on Bank M...Data Analysis Project : Targeting the Right Customers, Presentation on Bank M...
Data Analysis Project : Targeting the Right Customers, Presentation on Bank M...Boston Institute of Analytics
 
Conf42-LLM_Adding Generative AI to Real-Time Streaming Pipelines
Conf42-LLM_Adding Generative AI to Real-Time Streaming PipelinesConf42-LLM_Adding Generative AI to Real-Time Streaming Pipelines
Conf42-LLM_Adding Generative AI to Real-Time Streaming PipelinesTimothy Spann
 
NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...
NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...
NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...Boston Institute of Analytics
 
Biometric Authentication: The Evolution, Applications, Benefits and Challenge...
Biometric Authentication: The Evolution, Applications, Benefits and Challenge...Biometric Authentication: The Evolution, Applications, Benefits and Challenge...
Biometric Authentication: The Evolution, Applications, Benefits and Challenge...GQ Research
 
NO1 Certified Black Magic Specialist Expert Amil baba in Lahore Islamabad Raw...
NO1 Certified Black Magic Specialist Expert Amil baba in Lahore Islamabad Raw...NO1 Certified Black Magic Specialist Expert Amil baba in Lahore Islamabad Raw...
NO1 Certified Black Magic Specialist Expert Amil baba in Lahore Islamabad Raw...Amil Baba Dawood bangali
 

Recently uploaded (20)

20240419 - Measurecamp Amsterdam - SAM.pdf
20240419 - Measurecamp Amsterdam - SAM.pdf20240419 - Measurecamp Amsterdam - SAM.pdf
20240419 - Measurecamp Amsterdam - SAM.pdf
 
Minimizing AI Hallucinations/Confabulations and the Path towards AGI with Exa...
Minimizing AI Hallucinations/Confabulations and the Path towards AGI with Exa...Minimizing AI Hallucinations/Confabulations and the Path towards AGI with Exa...
Minimizing AI Hallucinations/Confabulations and the Path towards AGI with Exa...
 
Semantic Shed - Squashing and Squeezing.pptx
Semantic Shed - Squashing and Squeezing.pptxSemantic Shed - Squashing and Squeezing.pptx
Semantic Shed - Squashing and Squeezing.pptx
 
Effects of Smartphone Addiction on the Academic Performances of Grades 9 to 1...
Effects of Smartphone Addiction on the Academic Performances of Grades 9 to 1...Effects of Smartphone Addiction on the Academic Performances of Grades 9 to 1...
Effects of Smartphone Addiction on the Academic Performances of Grades 9 to 1...
 
Multiple time frame trading analysis -brianshannon.pdf
Multiple time frame trading analysis -brianshannon.pdfMultiple time frame trading analysis -brianshannon.pdf
Multiple time frame trading analysis -brianshannon.pdf
 
Top 5 Best Data Analytics Courses In Queens
Top 5 Best Data Analytics Courses In QueensTop 5 Best Data Analytics Courses In Queens
Top 5 Best Data Analytics Courses In Queens
 
Student Profile Sample report on improving academic performance by uniting gr...
Student Profile Sample report on improving academic performance by uniting gr...Student Profile Sample report on improving academic performance by uniting gr...
Student Profile Sample report on improving academic performance by uniting gr...
 
Statistics, Data Analysis, and Decision Modeling, 5th edition by James R. Eva...
Statistics, Data Analysis, and Decision Modeling, 5th edition by James R. Eva...Statistics, Data Analysis, and Decision Modeling, 5th edition by James R. Eva...
Statistics, Data Analysis, and Decision Modeling, 5th edition by James R. Eva...
 
原版1:1定制南十字星大学毕业证(SCU毕业证)#文凭成绩单#真实留信学历认证永久存档
原版1:1定制南十字星大学毕业证(SCU毕业证)#文凭成绩单#真实留信学历认证永久存档原版1:1定制南十字星大学毕业证(SCU毕业证)#文凭成绩单#真实留信学历认证永久存档
原版1:1定制南十字星大学毕业证(SCU毕业证)#文凭成绩单#真实留信学历认证永久存档
 
RS 9000 Call In girls Dwarka Mor (DELHI)⇛9711147426🔝Delhi
RS 9000 Call In girls Dwarka Mor (DELHI)⇛9711147426🔝DelhiRS 9000 Call In girls Dwarka Mor (DELHI)⇛9711147426🔝Delhi
RS 9000 Call In girls Dwarka Mor (DELHI)⇛9711147426🔝Delhi
 
Predictive Analysis for Loan Default Presentation : Data Analysis Project PPT
Predictive Analysis for Loan Default  Presentation : Data Analysis Project PPTPredictive Analysis for Loan Default  Presentation : Data Analysis Project PPT
Predictive Analysis for Loan Default Presentation : Data Analysis Project PPT
 
Consent & Privacy Signals on Google *Pixels* - MeasureCamp Amsterdam 2024
Consent & Privacy Signals on Google *Pixels* - MeasureCamp Amsterdam 2024Consent & Privacy Signals on Google *Pixels* - MeasureCamp Amsterdam 2024
Consent & Privacy Signals on Google *Pixels* - MeasureCamp Amsterdam 2024
 
Identifying Appropriate Test Statistics Involving Population Mean
Identifying Appropriate Test Statistics Involving Population MeanIdentifying Appropriate Test Statistics Involving Population Mean
Identifying Appropriate Test Statistics Involving Population Mean
 
Vision, Mission, Goals and Objectives ppt..pptx
Vision, Mission, Goals and Objectives ppt..pptxVision, Mission, Goals and Objectives ppt..pptx
Vision, Mission, Goals and Objectives ppt..pptx
 
9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort service
9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort service9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort service
9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort service
 
Data Analysis Project : Targeting the Right Customers, Presentation on Bank M...
Data Analysis Project : Targeting the Right Customers, Presentation on Bank M...Data Analysis Project : Targeting the Right Customers, Presentation on Bank M...
Data Analysis Project : Targeting the Right Customers, Presentation on Bank M...
 
Conf42-LLM_Adding Generative AI to Real-Time Streaming Pipelines
Conf42-LLM_Adding Generative AI to Real-Time Streaming PipelinesConf42-LLM_Adding Generative AI to Real-Time Streaming Pipelines
Conf42-LLM_Adding Generative AI to Real-Time Streaming Pipelines
 
NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...
NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...
NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...
 
Biometric Authentication: The Evolution, Applications, Benefits and Challenge...
Biometric Authentication: The Evolution, Applications, Benefits and Challenge...Biometric Authentication: The Evolution, Applications, Benefits and Challenge...
Biometric Authentication: The Evolution, Applications, Benefits and Challenge...
 
NO1 Certified Black Magic Specialist Expert Amil baba in Lahore Islamabad Raw...
NO1 Certified Black Magic Specialist Expert Amil baba in Lahore Islamabad Raw...NO1 Certified Black Magic Specialist Expert Amil baba in Lahore Islamabad Raw...
NO1 Certified Black Magic Specialist Expert Amil baba in Lahore Islamabad Raw...
 

Mongo db improve the performance of your application codemotion2016

  • 1. MADRID · NOV 18-19 · 2016 19th November 2016 18:30-19:15 MongoDB: Improve the performance of your application by @juanroycouto @codemotion_es 1
  • 2. MADRID · NOV 18-19 · 2016 #whoami ❖ @juanroycouto ❖ www.juanroy.es ❖ www.mongodbspain.com/en/author/juanroy ❖ juanroycouto@gmail.com ❖ MongoDB DBA at Grupo Undanet 2
  • 3. MADRID · NOV 18-19 · 2016 #Agenda 3 ● Data Model ● Application Patterns ● .explain() ● Indexes ● Storage Engines ● Query Optimizer ● Aggregation Framework ● Profiling ● Tuning ● Sharding ● Storage & Compression
  • 4. MADRID · NOV 18-19 · 2016 #Data Model 4
  • 5. MADRID · NOV 18-19 · 2016 #Data Model 5 ● All the information in one document: ○ No joins ○ Single read ○ Higher performance ○ ACID compliance at the document level ● MMAPv1: avoid unbounded document growth ● WiredTiger rewrites the document for each update
  • 6. MADRID · NOV 18-19 · 2016 #Application Patterns 6 ● Modify only those fields that have changed ● Project only the fields you need ● Avoid negation in queries ● Use Covered Queries when possible ● Avoid scatter-gather queries ● Write Concern: ○ w : 0 → faster than w : all
  • 7. MADRID · NOV 18-19 · 2016 #.explain() 7 ● Use .explain() to get the time a query needs ● Verbose options: ○ queryPlanner (default) ○ executionStats (stats for the winner plan) ○ allPlansExecution (stats for all candidate plans)
  • 8. MADRID · NOV 18-19 · 2016 #.explain() 8 ● In-memory sorting data is limited to 32MB (you need an index) ● My index selectivity is the relationship between nReturned and totalKeysExamined
  • 9. MADRID · NOV 18-19 · 2016 #Indexes 9
  • 10. MADRID · NOV 18-19 · 2016 #Indexes 10 ● Improve the performance of read-intensive apps ● Overhead: ○ Write operations ○ Disk usage ○ Memory consumption
  • 11. MADRID · NOV 18-19 · 2016 ● Working Set is made of: ○ Indexes ○ Your most frequently accessed data #Indexes-Working Set 11
  • 12. MADRID · NOV 18-19 · 2016 ● If your Working Set does not fit into RAM: ○ Increment your RAM ○ Shard the database ○ Avoid scan all documents in the collection ■ Page faults ■ You will fill in your Working Set with infrequent accessed data #Indexes-Working Set 12
  • 13. MADRID · NOV 18-19 · 2016 #Indexes-Before creating indexes 13 ● Understand your data ● How your queries will be ● Create as few indexes as possible ● Put your highly selective fields first in the index ● Check your current indexes before creating new ones
  • 14. MADRID · NOV 18-19 · 2016 #Indexes-Advices 14 ● Do not index a little cardinality field ● Check your index performance ● Monitor your system to check if: ○ Your strategy is still up to date ○ You need new indexes ○ You can remove unnecessary indexes
  • 15. MADRID · NOV 18-19 · 2016 #Indexes-Compound 15 ● A compound index has better performance than: ○ Single indexes ○ Intersection ● Remove indexes that are prefixes of other ● The value of the combined fields must have high cardinality
  • 16. MADRID · NOV 18-19 · 2016 #Indexes-Compound 16 >db.collection.createIndex( { equality, sort, range } ); >db.collection.find( { book_author : ‘John’, #equality book_id : { $gt : 54 } #range } ) .sort( { book_price : 1 } ); #sort
  • 17. MADRID · NOV 18-19 · 2016 > use test > db.example.createIndex( { a : 1, b : 1 } ); > db.example.explain("executionStats").find( { a : 56, b : 87 } ); "nReturned" : 100, "executionTimeMillis" : 2, "totalKeysExamined" : 100, "totalDocsExamined" : 100, > db.example.dropIndex( { a : 1, b : 1 } ); > db.example.createIndex( { a : 1 } ); > db.example.createIndex( { b : 1 } ); > db.example.explain("executionStats").find( { a : 56, b : 87 } ); "nReturned" : 100, "executionTimeMillis" : 36, "totalKeysExamined" : 10000, "totalDocsExamined" : 10000 #Indexes-Compound example 17
  • 18. MADRID · NOV 18-19 · 2016 #Indexes-Covered Queries 18 ● They return results from the indexes ● A covered query does not read from the document level: ○ ndocsExamined : 0 ● In the index must be all the fields: ○ Included in the query ○ Returned by the query
  • 19. MADRID · NOV 18-19 · 2016 #Indexes-Covered Queries example 19 > use test > db.example.createIndex( { a : 1, b : 1 } ); > db.example.explain("executionStats").find( { a : 56, b : 87 } ); "nReturned" : 100, "executionTimeMillis" : 3, "totalKeysExamined" : 100, "totalDocsExamined" : 100 > db.example.explain("executionStats").find( { a : 56, b : 87 }, { _id : 0, a : 1, b : 1 } ); "nReturned" : 100, "executionTimeMillis" : 3, "totalKeysExamined" : 100, "totalDocsExamined" : 0
  • 20. MADRID · NOV 18-19 · 2016 #Indexes-TTL 20 ● TTL (TimeToLive) Indexes ○ Allow the user to specify a period of time after which the data will be automatically deleted
  • 21. MADRID · NOV 18-19 · 2016 #Indexes-TTL example 21 > use test > db.timetolive.createIndex( { date : 1 } , { expireAfterSeconds: 20 } ); > db.timetolive.insert( { date : new Date() } ); > db.timetolive.find().pretty() { "_id" : ObjectId("581fb43f5626d57bcf66fe73"), "date" : ISODate("2016-11-06T22:52:47.373Z") } > db.timetolive.count() 0 > The background task that removes expired documents runs every 60 seconds.
  • 22. MADRID · NOV 18-19 · 2016 #Indexes-Partial 22 ● Partial Indexes ○ Allow to index a subset of your data by specifying a filtering expression during the index creation ○ Better query performance while reducing system overhead
  • 23. MADRID · NOV 18-19 · 2016 #Indexes-Partial example > use test > db.sysprofile.createIndex( { ns : 1, op : 1 }, { partialFilterExpression : { millis : { $gt : 10000 } } } ); > db.sysprofile.explain().find( { ns : 'school2.students', op : 'query' }, { millis : 1 } ); "winningPlan" : { "inputStage" : { "stage" : "COLLSCAN" > db.sysprofile.explain().find( { ns : 'school2.students', op : 'query', millis : { $gte : 20000 } }, { millis : 1 } ); "winningPlan" : { "inputStage" : { "stage" : "IXSCAN" 23
  • 24. MADRID · NOV 18-19 · 2016 #Indexes-Sparse 24 ● Sparse Indexes ○ Only contain entries for documents that contain a specific field ○ Smaller and more efficient indexes
  • 25. MADRID · NOV 18-19 · 2016 > use test > db.test.createIndex( { b : 1 } , { sparse : true } ); > db.test.stats() 16384 > > db.test.createIndex( { b : 1 } ); > db.test.stats() 2580480 > #Indexes-Sparse example 25
  • 26. MADRID · NOV 18-19 · 2016 #Storage Engines-WiredTiger 26 ● Reduced storage space and higher I/O scalability ● It compresses indexes into RAM, freeing up Working Set for documents ● Performance (granular concurrency control) ● Native compression: ○ per collection ○ per index
  • 27. MADRID · NOV 18-19 · 2016 #Storage Engines-WiredTiger 27 ● Types of compression: ○ Snappy (default): Data and Journal ○ zlib: maximum compression ○ Prefix: for indexes
  • 28. MADRID · NOV 18-19 · 2016 #Storage Engines: In-Memory 28 ● Extreme performance coupled with real time analytics for the most demanding, latency-sensitive applications ● Delivers the extreme throughput and predictable latency ● Eliminates the need for separate caching layers
  • 29. MADRID · NOV 18-19 · 2016 #Query Optimizer 29 ● It selects the best index to use ● It periodically runs alternate query plans and selects the index with the best response time for each query type ● The results of these tests are stored as a cached query plan and are updated periodically
  • 30. MADRID · NOV 18-19 · 2016 #Aggregation Framework 30
  • 31. MADRID · NOV 18-19 · 2016 #Aggregation Framework 31 ● Use $indexStats to determine how frequently your index is used ● Each shard has its own statistics ● Stats are reset when you restart your mongod service >db.collection.aggregate([ { $indexStats : {} } ])
  • 32. MADRID · NOV 18-19 · 2016 #Aggregation Framework example 32 > db.test.aggregate([ { $indexStats : {} } ]).pretty() { "name" : "b_1", "key" : { "b" : 1 }, "host" : "hostname:27017", "accesses" : { "ops" : NumberLong(4), "since" : ISODate("2016-11-07T00:05:39.771Z") } } ...
  • 33. MADRID · NOV 18-19 · 2016 #Tools-Compass 33
  • 34. MADRID · NOV 18-19 · 2016 #Tools-Compass 34 ● MongoDB Compass ○ Analyze the size and usage of the indexes ○ It offers visual plan explanations ○ Index creation ○ Real time stats ○ Identify and fix performance and data problems
  • 35. MADRID · NOV 18-19 · 2016 #Tools-Ops Manager 35 ● The Visual Query Profiler allows to analyze a query performance and recommends on the addition of indexes ● It can be used to visualize output from the profiler when identifying slow queries
  • 36. MADRID · NOV 18-19 · 2016 #Tools-Cloud Manager & Atlas 36 ● Use the Query Targeting chart
  • 37. MADRID · NOV 18-19 · 2016 #Tools-Profiling 37 ● Guess the slowest queries for improving their indexes ● Log information for all events or only those whose duration exceeds a configurable threshold (100ms default)
  • 38. MADRID · NOV 18-19 · 2016 #Tools-Profiling example 38 > db.setProfilingLevel(2) { "was" : 0, "slowms" : 100, "ok" : 1 } > db.example.find( { c : 98 } ); > db.system.profile.find().pretty() { "op" : "query", "ns" : "test.example", "query" : { "find" : "example", "filter" : { "c" : 98 } }, … "millis" : 6
  • 39. MADRID · NOV 18-19 · 2016 #Tuning-SSD 39 ● Most disk access patterns are not sequential ● Data files benefit from SSDs ● MongoDB journal files have high sequential write patterns (good for spinning disks) ● RAM/SSDs better than spinning drives ● Use high performance storage ● Avoid networked storage
  • 40. MADRID · NOV 18-19 · 2016 #Tuning-CPU 40 ● MongoDB has better performance on faster CPUs ● The MongoDB WiredTiger Storage Engine is better able to saturate multi-core processor resources than the MMAPv1 Storage Engine
  • 41. MADRID · NOV 18-19 · 2016 #Tuning-Thread 41 ● The WiredTiger Storage Engine is multi-threaded and can take advantage of many CPU Cores
  • 42. MADRID · NOV 18-19 · 2016 #Sharding 42 ● The balancer has been moved from the mongos to the primary member of the config server ● Sharding improves the performance of reads ● Benefits (even with a ‘poor’ shard key and scatter-gather): ○ A larger amount of memory to store indexes ○ Parallelize queries across shards reducing latency
  • 43. MADRID · NOV 18-19 · 2016 #Storage & Compression types 43 ● Balance query latency with storage density and cost by assigning data sets based on a value such as a timestamp to specific storage devices
  • 44. MADRID · NOV 18-19 · 2016 #Storage & Compression types 44 ● Recent, frequently accessed data can be assigned to high performance SSDs with Snappy compression ● Older, less frequently accessed data is tagged to lower-throughput hard disk drives compressed with zlib to attain maximum storage density with a lower cost-per-bit ● As data ages, MongoDB will automatically migrates it between shards
  • 45. MADRID · NOV 18-19 · 2016 #Questions? 45 Questions?
  • 46. MongoDB: Improve the performance of your application by @juanroycouto MADRID · NOV 18-19 · 2016 46 Thank you for your attention!