Skip to content

Commit 5395dd0

Browse files
author
Sam Kleinman
committed
DOCS-491 editing and organization
1 parent c7cd7b7 commit 5395dd0

File tree

2 files changed

+123
-119
lines changed

2 files changed

+123
-119
lines changed

source/faq/diagnostics.txt

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,123 @@ If your replica set or shard cluster experiences keepalive-related
7979
issues, you must must alter the ``tcp_keepalive_time`` value on all
8080
machines hosting MongoDB processes. This includes all machines hosting
8181
:program:`mongos` or :program:`mongod` servers.
82+
83+
Do I need to configure swap space?
84+
----------------------------------
85+
86+
Always configure systems to have swap space. Without swap, your system
87+
may not be reliant in some situations with extreme memory constrains,
88+
memory leaks, or multiple programs using the same memory. Think of
89+
the swap space as something like a steam release valve that allows the
90+
system to release extra pressure without affecting the overall
91+
functioning of the system.
92+
93+
Nevertheless, systems running MongoDB *do not* need swap for routine
94+
operation. Database files are :ref:`memory-mapped
95+
<faq-storage-memory-mapped-files>` and should constitute most of your
96+
MongoDB memory use. Therefore, it is unlikely that :program:`mongod`
97+
will ever use any swap space in normal operation. The operating system
98+
will release memory from the memory mapped files without needing
99+
swap and MongoDB can write data to the data files without needing the swap
100+
system.
101+
102+
.. _faq-fundamentals-working-set:
103+
104+
Must my working set size fit RAM?
105+
---------------------------------
106+
107+
Your working set should stay in memory to achieve good performance.
108+
Otherwise many random disk IO's will occur, and unless you are using
109+
SSD, this can be quite slow.
110+
111+
One area to watch specifically in managing the size of your working set
112+
is index access patterns. If you are inserting into indexes at random
113+
locations (as would happen with id's that are randomly
114+
generated by hashes), you will continually be updating the whole index.
115+
If instead you are able to create your id's in approximately ascending
116+
order (for example, day concatenated with a random id), all the updates
117+
will occur at the right side of the b-tree and the working set size for
118+
index pages will be much smaller.
119+
120+
It is fine if databases and thus virtual size are much larger than RAM.
121+
122+
.. todo Commenting out for now:
123+
124+
.. _faq-fundamentals-working-set-size:
125+
126+
How can I measure working set size?
127+
-----------------------------------
128+
129+
Measuring working set size can be difficult; even if it is much
130+
smaller than total RAM. If the database is much larger than RAM in
131+
total, all memory will be indicated as in use for the cache. Thus you
132+
need a different way to estimate the working set size.
133+
134+
One technique is to use the `eatmem.cpp
135+
<https://github.com/mongodb/mongo-snippets/blob/master/cpp/eatmem.cpp>`_.
136+
utility, which reserves a certain amount of system memory for itself.
137+
You can run the utility with a certain amount specified and see if
138+
the server continues to perform well. If not, the working set is
139+
larger than the total RAM minus the consumed RAM. The test will eject
140+
some data from the file system cache, which might take time to page
141+
back in after the utility is terminated.
142+
143+
Running eatmem.cpp continuously with a small percentage of total RAM,
144+
such as 20%, is a good technique to get an early warning if memory is
145+
too low. If disk I/O activity increases significantly, terminate
146+
eatmem.cpp to mitigate the problem for the moment until further steps
147+
can be taken.
148+
149+
In :term:`replica sets <replica set>`, if one server is underpowered
150+
the eatmem.cpp utility could help as an early warning mechanism for
151+
server capacity. Of course, the server must be receiving
152+
representative traffic to get an indication.
153+
154+
How do I calculate how much RAM I need for my application?
155+
----------------------------------------------------------
156+
157+
.. todo Improve this FAQ
158+
159+
The amount of RAM you need depends on several factors, including but not
160+
limited to:
161+
162+
- The relationship between :doc:`database storage </faq/storage>` and working set.
163+
164+
- The operating system's cache strategy for LRU (Least Recently Used)
165+
166+
- The impact of :doc:`journaling </administration/journaling>`
167+
168+
- The number or rate of page faults and other MMS gauges to detect when
169+
you need more RAM
170+
171+
MongoDB defers to the operating system when loading data into memory
172+
from disk. It simply :ref:`memory maps <faq-storage-memory-mapped-files>` all
173+
its data files and relies on the operating system to cache data. The OS
174+
typically evicts the least-recently-used data from RAM when it runs low
175+
on memory. For example if clients access indexes more frequently than
176+
documents, then indexes will more likely stay in RAM, but it depends on
177+
your particular usage.
178+
179+
To calculate how much RAM you need, you must calculate your working set
180+
size, or the portion of your data that clients use most often. This
181+
depends on your access patterns, what indexes you have, and the size of
182+
your documents.
183+
184+
If page faults are infrequent, your
185+
working set fits in RAM. If fault rates rise higher than that, you risk
186+
performance degradation. This is less critical with SSD drives than
187+
with spinning disks.
188+
189+
How do I read memory statistics in the UNIX ``top`` command
190+
-----------------------------------------------------------
191+
192+
Because :program:`mongod` uses :ref:`memory-mapped files
193+
<faq-storage-memory-mapped-files>`, the memory statistics in ``top``
194+
require interpretation in a special way. On a large database, ``VSIZE``
195+
(virtual bytes) tends to be the size of the entire database. If the
196+
:program:`mongod` doesn't have other processes running, ``RSIZE``
197+
(resident bytes) is the total memory of the machine, as this counts
198+
file system cache contents.
199+
200+
For Linux systems, use the ``vmstat`` command to help determine how
201+
the system uses memory. On OS X systems use ``vm_stat``.

source/faq/fundamentals.txt

Lines changed: 3 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ FAQ: MongoDB Fundamentals
44

55
.. default-domain:: mongodb
66

7-
This document answers basic questions about MongoDB.
7+
This document addresses basic high level questions about MongoDB and
8+
it's use.
89

910
If you don't find the answer you're looking for, check
1011
the :doc:`complete list of FAQs </faq>` or post your question to the
@@ -17,7 +18,7 @@ the :doc:`complete list of FAQs </faq>` or post your question to the
1718
What kind of database is MongoDB?
1819
---------------------------------
1920

20-
MongoDB is :term:`document`-oriented DBMS. Think of MySQL but with
21+
MongoDB is :term:`document`\-oriented DBMS. Think of MySQL but with
2122
:term:`JSON`-like objects comprising the data model, rather than RDBMS
2223
tables. Significantly, MongoDB supports neither joins nor transactions.
2324
However, it features secondary indexes, an expressive query language,
@@ -145,123 +146,6 @@ as it can, swapping to disk as needed. Deployments with enough memory
145146
to fit the application's working data set in RAM will achieve the best
146147
performance.
147148

148-
Do I need a swap space?
149-
-----------------------
150-
151-
You should always have a swap space in case you run into extreme memory
152-
constraints, memory leaks, or another program stealing a lot of memory.
153-
Think of the swap space as something like a steam release valve which
154-
allows excess pressure to release without blowing the system up.
155-
156-
But you *do not* need swap for routine use. Database files are
157-
:ref:`memory-mapped <faq-storage-memory-mapped-files>` and should
158-
constitute most of your MongoDB memory use. Therefore, it is unlikely
159-
that :program:`mongod` will ever use any swap space. The memory mapped
160-
files can simply be released from memory without going to swap or can be
161-
written back to the database files without needing to be swapped out to
162-
disk, as they are already backed by files.
163-
164-
.. _faq-fundamentals-working-set:
165-
166-
Must my working set size fit RAM?
167-
---------------------------------
168-
169-
Your working set should stay in memory to achieve good performance.
170-
Otherwise many random disk IO's will occur, and unless you are using
171-
SSD, this can be quite slow.
172-
173-
One area to watch specifically in managing the size of your working set
174-
is index access patterns. If you are inserting into indexes at random
175-
locations (as would happen with id's that are randomly
176-
generated by hashes), you will continually be updating the whole index.
177-
If instead you are able to create your id's in approximately ascending
178-
order (for example, day concatenated with a random id), all the updates
179-
will occur at the right side of the b-tree and the working set size for
180-
index pages will be much smaller.
181-
182-
It is fine if databases and thus virtual size are much larger than RAM.
183-
184-
.. todo Commenting out for now:
185-
186-
.. _faq-fundamentals-working-set-size:
187-
188-
How can I measure working set size?
189-
-----------------------------------
190-
191-
Measuring working set size can be difficult; even if it is much
192-
smaller than total RAM. If the database is much larger than RAM in
193-
total, all memory will be indicated as in use for the cache. Thus you
194-
need a different way to estimate the working set size.
195-
196-
One technique is to use the `eatmem.cpp
197-
<https://github.com/mongodb/mongo-snippets/blob/master/cpp/eatmem.cpp>`_.
198-
utility, which reserves a certain amount of system memory for itself.
199-
You can run the utility with a certain amount specified and see if
200-
the server continues to perform well. If not, the working set is
201-
larger than the total RAM minus the consumed RAM. The test will eject
202-
some data from the file system cache, which might take time to page
203-
back in after the utility is terminated.
204-
205-
Running eatmem.cpp continuously with a small percentage of total RAM,
206-
such as 20%, is a good technique to get an early warning if memory is
207-
too low. If disk I/O activity increases significantly, terminate
208-
eatmem.cpp to mitigate the problem for the moment until further steps
209-
can be taken.
210-
211-
In :term:`replica sets <replica set>`, if one server is underpowered
212-
the eatmem.cpp utility could help as an early warning mechanism for
213-
server capacity. Of course, the server must be receiving
214-
representative traffic to get an indication.
215-
216-
How do I calculate how much RAM I need for my application?
217-
----------------------------------------------------------
218-
219-
.. todo Improve this FAQ
220-
221-
The amount of RAM you need depends on several factors, including but not
222-
limited to:
223-
224-
- The relationship between :doc:`database storage </faq/storage>` and working set.
225-
226-
- The operating system's cache strategy for LRU (Least Recently Used)
227-
228-
- The impact of :doc:`journaling </administration/journaling>`
229-
230-
- The number or rate of page faults and other MMS gauges to detect when
231-
you need more RAM
232-
233-
MongoDB makes no choices regarding what data is loaded into memory from
234-
disk. It simply :ref:`memory maps <faq-storage-memory-mapped-files>` all
235-
its data files and relies on the operating system to cache data. The OS
236-
typically evicts the least-recently-used data from RAM when it runs low
237-
on memory. For example if indexes are accessed more frequently than
238-
documents then indexes will more likely stay in RAM, but it depends on
239-
your particular usage.
240-
241-
To calculate how much RAM you need, you must calculate your working set
242-
size, i.e., the portion of your data that is frequently accessed. This
243-
depends on your access patterns, what indexes you have, and the size of
244-
your documents. To calculate working set size, see :ref:`faq-fundamentals-working-set`.
245-
246-
If page faults are infrequent, your
247-
working set fits in RAM. If fault rates rise higher than that, you risk
248-
performance degradation. This is less critical with SSD drives than
249-
with spinning disks.
250-
251-
How do I read memory statistics in the UNIX ``top`` command
252-
-----------------------------------------------------------
253-
254-
Because :program:`mongod` uses :ref:`memory-mapped files
255-
<faq-storage-memory-mapped-files>`, the memory statistics in ``top``
256-
require interpretation in a special way. On a large database, ``VSIZE``
257-
(virtual bytes) tends to be the size of the entire database. If the
258-
:program:`mongod` doesn't have other processes running, ``RSIZE``
259-
(resident bytes) is the total memory of the machine, as this counts
260-
file system cache contents.
261-
262-
The ``vmstat`` command is also useful for determining
263-
memory use. On Macintosh computers, the command is ``vm_stat``.
264-
265149
How do I configure the cache size?
266150
----------------------------------
267151

0 commit comments

Comments
 (0)