Home Database Mysql Tutorial Mongodb使用小结

Mongodb使用小结

Jun 07, 2016 pm 04:34 PM
mongodb use discuss question

以下讨论的问题,有一个前提,就是要保存的数据大于内存容量。否则你可无视之。。。 索引占用的空间有时候超出你的想象。 即使集合中只有一个默认的索引 _id, 1 亿条记录,索引占用超过 5G 。如果内存不足以保存索引,赶紧加内存吧 ~~~ 查询或者更新的速度,

        以下讨论的问题,有一个前提,就是要保存的数据大于内存容量。否则你可无视之。。。

        索引占用的空间有时候超出你的想象。即使集合中只有一个默认的索引_id, 1亿条记录,索引占用超过5G。如果内存不足以保存索引,赶紧加内存吧~~~

Mongodb使用小结

         查询或者更新的速度,有时候与文档数量的关系并不大。我在网上看到的最多的是,mongodb的速度与文档数量有关,与文档所占用空间的关系谈的人不多。我尝试在一台16G的机器上,添加100w文档,索引占用的空间大概100M不到。每个文档大小大概为50k, 100w的数据量大概占用的磁盘空间是50G,然后随机的update或者find_one100w个文档,update操作不会改变原有记录大小。原本以为才这点数据,mongodb应该像火箭一样飞起来,结果出乎意料,速度慢的要死,每秒大概只能更新50条记录左右,通过iostat或者mongostat查询,你会发现磁盘像疯了一样的转,好像吃了*,停也停不下来。想想我在sqlite中,100w记录量,查询的速度都比这要快。为什么会这么慢?mongodb也不过如此,可能还不如自己写的程序来的快?真的吗?

        了解一些b-tree的知识对使用mongodb或者其他关系数据库有好处。但索引不是万能,别以为充分利用了索引就以为mongodb会像火箭一样飞起来,有时候他会比蜗牛爬的还慢。应该根据业务需求,充分考虑数据在磁盘上保存的顺序和索引的关系,合理的设计索引。以前在学sqlserver的时候,书上说主键很重要,因为数据在磁盘上保存的顺序就是按主键的顺序来的,好像一本新华字典,书上的字按拼音的顺序保存,虽然我们也可以按部首去查询某个字,但要像获取所有”a”开头的汉字,总比获取所有“亻”的汉字要快的多。

        如果热点数据在内存中,查询与更新操作非常快,亿级数据,单实例不分片,每妙能处理上千次查询或者更新操作。否则,你的磁盘会转个不停,而且非常慢。即使充分使用了索引,因为数据不在内存中,操作系统需要先卸载部分数据腾出内存空间(如果内存不够的话)去映射磁盘上的数据。这个过程磁盘会疯一样的转。

         Mongodb的内存管理是交给操作系统的,即使mongodb重启,系统可能并不会立即释放系统cache,这个时候,如果热点数据还没有被系统卸载掉,查询的速度还是非常快的。这常常会给人以假象,mongodb快。。

        总之,索引与热点数据有多大,就给mongodb分配多大的内存。如果主要是保存数据,那么只要磁盘足够大,mongodb都可以把数据塞进去。

         Last: good luck…

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

Repo: How To Revive Teammates
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

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)

What software is crystaldiskmark? -How to use crystaldiskmark? What software is crystaldiskmark? -How to use crystaldiskmark? Mar 18, 2024 pm 02:58 PM

CrystalDiskMark is a small HDD benchmark tool for hard drives that quickly measures sequential and random read/write speeds. Next, let the editor introduce CrystalDiskMark to you and how to use crystaldiskmark~ 1. Introduction to CrystalDiskMark CrystalDiskMark is a widely used disk performance testing tool used to evaluate the read and write speed and performance of mechanical hard drives and solid-state drives (SSD). Random I/O performance. It is a free Windows application and provides a user-friendly interface and various test modes to evaluate different aspects of hard drive performance and is widely used in hardware reviews

How to download foobar2000? -How to use foobar2000 How to download foobar2000? -How to use foobar2000 Mar 18, 2024 am 10:58 AM

foobar2000 is a software that can listen to music resources at any time. It brings you all kinds of music with lossless sound quality. The enhanced version of the music player allows you to get a more comprehensive and comfortable music experience. Its design concept is to play the advanced audio on the computer The device is transplanted to mobile phones to provide a more convenient and efficient music playback experience. The interface design is simple, clear and easy to use. It adopts a minimalist design style without too many decorations and cumbersome operations to get started quickly. It also supports a variety of skins and Theme, personalize settings according to your own preferences, and create an exclusive music player that supports the playback of multiple audio formats. It also supports the audio gain function to adjust the volume according to your own hearing conditions to avoid hearing damage caused by excessive volume. Next, let me help you

Which version is generally used for mongodb? Which version is generally used for mongodb? Apr 07, 2024 pm 05:48 PM

It is recommended to use the latest version of MongoDB (currently 5.0) as it provides the latest features and improvements. When selecting a version, you need to consider functional requirements, compatibility, stability, and community support. For example, the latest version has features such as transactions and aggregation pipeline optimization. Make sure the version is compatible with the application. For production environments, choose the long-term support version. The latest version has more active community support.

How to use Baidu Netdisk app How to use Baidu Netdisk app Mar 27, 2024 pm 06:46 PM

Cloud storage has become an indispensable part of our daily life and work nowadays. As one of the leading cloud storage services in China, Baidu Netdisk has won the favor of a large number of users with its powerful storage functions, efficient transmission speed and convenient operation experience. And whether you want to back up important files, share information, watch videos online, or listen to music, Baidu Cloud Disk can meet your needs. However, many users may not understand the specific use method of Baidu Netdisk app, so this tutorial will introduce in detail how to use Baidu Netdisk app. Users who are still confused can follow this article to learn more. ! How to use Baidu Cloud Network Disk: 1. Installation First, when downloading and installing Baidu Cloud software, please select the custom installation option.

The difference between nodejs and vuejs The difference between nodejs and vuejs Apr 21, 2024 am 04:17 AM

Node.js is a server-side JavaScript runtime, while Vue.js is a client-side JavaScript framework for creating interactive user interfaces. Node.js is used for server-side development, such as back-end service API development and data processing, while Vue.js is used for client-side development, such as single-page applications and responsive user interfaces.

How to use NetEase Mailbox Master How to use NetEase Mailbox Master Mar 27, 2024 pm 05:32 PM

NetEase Mailbox, as an email address widely used by Chinese netizens, has always won the trust of users with its stable and efficient services. NetEase Mailbox Master is an email software specially created for mobile phone users. It greatly simplifies the process of sending and receiving emails and makes our email processing more convenient. So how to use NetEase Mailbox Master, and what specific functions it has. Below, the editor of this site will give you a detailed introduction, hoping to help you! First, you can search and download the NetEase Mailbox Master app in the mobile app store. Search for "NetEase Mailbox Master" in App Store or Baidu Mobile Assistant, and then follow the prompts to install it. After the download and installation is completed, we open the NetEase email account and log in. The login interface is as shown below

BTCC tutorial: How to bind and use MetaMask wallet on BTCC exchange? BTCC tutorial: How to bind and use MetaMask wallet on BTCC exchange? Apr 26, 2024 am 09:40 AM

MetaMask (also called Little Fox Wallet in Chinese) is a free and well-received encryption wallet software. Currently, BTCC supports binding to the MetaMask wallet. After binding, you can use the MetaMask wallet to quickly log in, store value, buy coins, etc., and you can also get 20 USDT trial bonus for the first time binding. In the BTCCMetaMask wallet tutorial, we will introduce in detail how to register and use MetaMask, and how to bind and use the Little Fox wallet in BTCC. What is MetaMask wallet? With over 30 million users, MetaMask Little Fox Wallet is one of the most popular cryptocurrency wallets today. It is free to use and can be installed on the network as an extension

Where is the database created by mongodb? Where is the database created by mongodb? Apr 07, 2024 pm 05:39 PM

The data of the MongoDB database is stored in the specified data directory, which can be located in the local file system, network file system or cloud storage. The specific location is as follows: Local file system: The default path is Linux/macOS:/data/db, Windows: C:\data\db. Network file system: The path depends on the file system. Cloud Storage: The path is determined by the cloud storage provider.

See all articles