@@ -4,7 +4,8 @@ FAQ: MongoDB Fundamentals
4
4
5
5
.. default-domain:: mongodb
6
6
7
- This document answers basic questions about MongoDB.
7
+ This document addresses basic high level questions about MongoDB and
8
+ it's use.
8
9
9
10
If you don't find the answer you're looking for, check
10
11
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
17
18
What kind of database is MongoDB?
18
19
---------------------------------
19
20
20
- MongoDB is :term:`document`-oriented DBMS. Think of MySQL but with
21
+ MongoDB is :term:`document`\ -oriented DBMS. Think of MySQL but with
21
22
:term:`JSON`-like objects comprising the data model, rather than RDBMS
22
23
tables. Significantly, MongoDB supports neither joins nor transactions.
23
24
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
145
146
to fit the application's working data set in RAM will achieve the best
146
147
performance.
147
148
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
-
265
149
How do I configure the cache size?
266
150
----------------------------------
267
151
0 commit comments