Home Database Mysql Tutorial MongoDB 内存使用

MongoDB 内存使用

Jun 07, 2016 pm 04:30 PM
mongodb use Memory

都说 MongoDB 是个内存大户,但是怎么知道它到底用了多少内存呢? 先 ps 一下看看。 $ ps aux|grep mongodmongo 26994 9.0 20.0 797264324 13243052 ? Sl May16 117:03 /path/to/mongodb/bin/mongod 总共 760G 多的虚拟内存,但是物理内存就只有 12.6G 。这

都说 MongoDB 是个内存大户,但是怎么知道它到底用了多少内存呢?

先 ps 一下看看。

$ ps aux|grep mongod
mongo    26994  9.0 20.0 797264324 13243052 ?  Sl   May16 117:03 /path/to/mongodb/bin/mongod
Copy after login

总共 760G 多的虚拟内存,但是物理内存就只有 12.6G 。这个机器可是有 64G 内存的哦,这看起来 MongoDB 完全没用多少内存嘛。

再看看 free 的结果。

$ free -m
             total       used       free     shared    buffers     cached
Mem:         64544      64279        265          0        134      60413
-/+ buffers/cache:       3731      60813
Swap:        31999          0      31999
Copy after login

内存倒是占得差不多了,基本都是 cached ,也就是文件系统缓存。MongoDB 是通过 mmap 方式让操作系统来处理持久化和缓存的。每个数据文件都直接映射到某个虚拟内存地址。访问的时候如果这一页不在内存中,系统就会尝试把这一页加载进来。这些内存都是算进 cache 里的。在 mongodb 的官方文档里有这样一个说法,top 或 ps 里的 RSIZE 段显示的是机器的全部内存大小,因为 mongodb 会尽可能占用全部内存。但是事实上,这些缓存并没有算在里面。因此在 top 或 ps 中是看不出 MongoDB 的实际内存使用情况的。而 free 虽然可以看到系统的内存使用情况,但是没法确定这些内存里究竟有多少真的是 MongoDB 使用的。

还好有人做了 vmtouch 这个工具。可以检查文件在缓存中的情况,另外也可以把文件直接加载进缓存或者踢出去。只需要对 MongoDB 的所有数据文件检查一下缓存加载情况,就可以知道 MongoDB 到底缓存了多少数据了。

$ vmtouch -m4G /path/to/mongodb/data/
           Files: 256
     Directories: 3
  Resident Pages: 15465901/100219772  58G/382G  15.4%
         Elapsed: 4.072 seconds
Copy after login

这里 -m4G 是 vmtouch 检查的文件大小限制。MongoDB 的数据文件比较大,通常会超过默认的 500M。这样看来,缓存用了 58G,这还差不多。Resident Pages 左侧的数字是页的数量,页的数量乘以文件系统页大小才是内存使用量。页的大小可以通过

getconf PAGESIZE 
Copy after login

查看,通常是 4096,也就是 4KB。

MongoDB 在 NUMA 的机器上运行,并且内存被固定到一个 node 的时候,会有一个警告

WARNING: You are running on a NUMA machine. 
We suggest launching mongod like this to avoid performance problems: 
numactl –interleave=all mongod [other options]
Copy after login

也许是认为,这种情况下只能用上一个节点的内存。但 MongoDB 的缓存是由操作系统管理的。NUMA 似乎对此并没有影响。而内存不太小的时候 MongoDB 本身很难用掉一个节点的内存。这种情况下,是否开启 numactl –interleave=all 作用已经不大了。能做的也许只能是加内存,sharding,或者换 ssd 了。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Sources say Samsung Electronics and SK Hynix will commercialize stacked mobile memory after 2026 Sources say Samsung Electronics and SK Hynix will commercialize stacked mobile memory after 2026 Sep 03, 2024 pm 02:15 PM

According to news from this website on September 3, Korean media etnews reported yesterday (local time) that Samsung Electronics and SK Hynix’s “HBM-like” stacked structure mobile memory products will be commercialized after 2026. Sources said that the two Korean memory giants regard stacked mobile memory as an important source of future revenue and plan to expand "HBM-like memory" to smartphones, tablets and laptops to provide power for end-side AI. According to previous reports on this site, Samsung Electronics’ product is called LPWide I/O memory, and SK Hynix calls this technology VFO. The two companies have used roughly the same technical route, which is to combine fan-out packaging and vertical channels. Samsung Electronics’ LPWide I/O memory has a bit width of 512

It is reported that Samsung Electronics has confirmed investment in the 1cnm DRAM memory production line of Pyeongtaek P4 factory and aims to put it into operation in June next year. It is reported that Samsung Electronics has confirmed investment in the 1cnm DRAM memory production line of Pyeongtaek P4 factory and aims to put it into operation in June next year. Aug 12, 2024 pm 04:31 PM

According to news from this site on August 12, Korean media ETNews reported that Samsung Electronics has internally confirmed its investment plan to build a 1cnm DRAM memory production line at the Pyeongtaek P4 factory. The production line is targeted to be put into operation in June next year. Pyeongtaek P4 is a comprehensive semiconductor production center divided into four phases. In the earlier planning, the first phase was for NAND flash memory, the second phase was for logic foundry, and the third and fourth phases were for DRAM memory. Samsung has introduced DRAM production equipment in the first phase of P4, but has shelved the second phase of construction. 1cnm DRAM is the sixth-generation 20~10nm memory process, and each company's 1cnm (or corresponding 1γnm) products have not yet been officially released. Korean media reported that Samsung Electronics plans to start 1cnm memory production at the end of this year. ▲Samsung Pyeongtaek

It is reported that SK Hynix has started the expansion of M16 wafer fab, aiming to increase the company's DRAM memory production capacity by about 18% It is reported that SK Hynix has started the expansion of M16 wafer fab, aiming to increase the company's DRAM memory production capacity by about 18% Aug 14, 2024 pm 08:19 PM

According to news from this site on August 14, comprehensive Korean media "Seoul Economic Daily" (29th last month) and "Chosun Ilbo" (13th this month) reported that SK Hynix has ordered key equipment from upstream equipment companies with the goal of improving M16 crystal HBM and general DRAM memory production capacity of round factories. Note from this site: SK Hynix’s M16 wafer fab is located in Icheon, Gyeonggi Province, South Korea. It currently has a DRAM production capacity of approximately 100,000 12-inch wafers per month. ▲Two Korean media reports on the specific expansion of SK Hynix’s Icheon campus are slightly different: "Seoul Economic Daily" believes that it is at least 70,000 wafers per month, and also mentioned 80,000 wafers per month; "Chosun Ilbo" It is considered to be 80,000 to 100,000 wafers per month. Analyst agency Omdia previously estimated that SK Hynix’s DRAM memory production

MSI introduces the advantages of CAMM2 DDR5 memory for desktop computers: faster speed, lower latency, and more novel design MSI introduces the advantages of CAMM2 DDR5 memory for desktop computers: faster speed, lower latency, and more novel design Aug 16, 2024 pm 07:52 PM

This website reported on August 16 that all major manufacturers have basically launched their own CAMM2 memory. For example, MSI, ASRock, and ASUS also announced special Intel motherboards supporting CAMM2 memory at the Taipei Computex in June. As desktop computers begin to support CAMM2 memory, MSI officially released a video today to introduce the advantages of this platform. Compared with traditional SO-DIMM memory modules, CAMM2 memory has shorter traces, which brings higher signal integrity, faster speed, lower latency, and cooler and updated design. In addition, the advantage of CAMM2 is that it only needs to use one PMIC (each module in SO-DIMM has its own PMIC), thereby achieving the lowest power consumption and heat generation

How to configure MongoDB automatic expansion on Debian How to configure MongoDB automatic expansion on Debian Apr 02, 2025 am 07:36 AM

This article introduces how to configure MongoDB on Debian system to achieve automatic expansion. The main steps include setting up the MongoDB replica set and disk space monitoring. 1. MongoDB installation First, make sure that MongoDB is installed on the Debian system. Install using the following command: sudoaptupdatesudoaptinstall-ymongodb-org 2. Configuring MongoDB replica set MongoDB replica set ensures high availability and data redundancy, which is the basis for achieving automatic capacity expansion. Start MongoDB service: sudosystemctlstartmongodsudosys

How to ensure high availability of MongoDB on Debian How to ensure high availability of MongoDB on Debian Apr 02, 2025 am 07:21 AM

This article describes how to build a highly available MongoDB database on a Debian system. We will explore multiple ways to ensure data security and services continue to operate. Key strategy: ReplicaSet: ReplicaSet: Use replicasets to achieve data redundancy and automatic failover. When a master node fails, the replica set will automatically elect a new master node to ensure the continuous availability of the service. Data backup and recovery: Regularly use the mongodump command to backup the database and formulate effective recovery strategies to deal with the risk of data loss. Monitoring and Alarms: Deploy monitoring tools (such as Prometheus, Grafana) to monitor the running status of MongoDB in real time, and

SK Hynix: Seven major U.S. technology giants have expressed their intention to customize HBM memory SK Hynix: Seven major U.S. technology giants have expressed their intention to customize HBM memory Aug 20, 2024 pm 04:43 PM

According to news from this site on August 20, according to Korean media MK, Ryu Seong-soo, SK Hynix’s vice president in charge of HBM memory business, said at the SK Group’s 2024 Icheon Forum yesterday local time that M7 technology giants have expressed their hope that SK Hynix Intention to develop customized HBM products for it. Note on this site: M7 stands for Magnificent7, which refers to the seven major technology giants in the US stock market: Apple, Microsoft, Alphabet (Google), Tesla, Nvidia, Amazon and Meta. RyuSeong-soo mentioned that he continued to work on weekends, communicating with M7 companies on the phone, and running around to meet the needs of these companies to integrate engineering resources within SK hynix and supply chain companies across Korea. this

Navicat's method to view MongoDB database password Navicat's method to view MongoDB database password Apr 08, 2025 pm 09:39 PM

It is impossible to view MongoDB password directly through Navicat because it is stored as hash values. How to retrieve lost passwords: 1. Reset passwords; 2. Check configuration files (may contain hash values); 3. Check codes (may hardcode passwords).

See all articles