Database Reference
In-Depth Information
10.4.1
Check indexes and queries for efficiency
When you discover a performance issue, indexes are the first place you should look.
This assumes that your application issues queries and updates, which are the primary
operations that can use indexes. 11 Chapter 7 outlines a procedure for identifying and
fixing slow operations; this involves enabling the query profiler and then ensuring
that every query and update uses an index efficiently. In general, this means that each
operation scans as few documents as possible.
It's also important to make sure that there are no redundant indexes, since a
redundant index will take up space on disk, require more RAM , and demand more
work on each write. Chapter 7 mentions ways to eliminate these redundant indexes.
What then? After auditing your indexes and queries, you may discover inefficien-
cies that, when corrected, fix the performance problems altogether. You'll no longer
see slow query warnings in the logs, and the iostat output will show reduced utiliza-
tion. Adjusting indexes fixes performance issues more often than you might think;
this should always be the first place you look when addressing a performance issue.
10.4.2
Add RAM
But altering the indexes doesn't always work. You might have the most optimized que-
ries and a perfect set of indexes, and still see high disk utilization. When this is the case,
you'll first want to look at the ratio of index size and working set to physical RAM . To
start, run the stats() command on each of the databases used by your application:
> use app
> db.stats()
{
"db" : "app",
"collections" : 5,
"objects" : 3932487,
"avgObjSize" : 543.012,
"dataSize" : 2135390324,
"storageSize" : 2419106304,
"numExtents" : 38,
"indexes" : 4,
"indexSize" : 226608064,
"fileSize" : 6373244928,
"nsSizeMB" : 16,
"ok" : 1
}
Now look at the data size and index size. Here the data size is just over 2 GB , and the
index size is around 230 MB . Assuming that the working set comprises all the data in
the system, you'll want at least 3 GB on this machine to keep from going to disk too
frequently. If this machine had just 1.5 GB RAM , then you'd expect to see high disk
utilization.
11
Certain database commands, like count , also use indexes.
Search WWH ::




Custom Search