Mongodb会输出大量的日志消息,但请不要使用 --quiet选项(该选项会隐藏部分日志信息)。保持日志级别为默认值通常不错,此时日志中
部署MongoDB的生产服务器,给出如下相关建议:
1)推荐RAID配置
RAID(Redundant Array of Independent Disk,独立磁盘冗余阵列)是一种可以让我们把多块磁盘当做单独一块磁盘来使用的技术。可使用它来提高磁盘的可靠性或者性能,或二者兼有。一组使用RAID技术的磁盘被称作RAID磁盘阵列。
RAID根据性能的不同,存在着多种配置方式,通常兼顾了速度与容错性。下列是几种最常见的配置方式:
推荐使用RAID10,它比RAID0更安全,也能解决RAID1的性能问题。在副本集的基础上,再使用RAID1有些浪费,从而可选择RAID0。
不要用RAID5,它会非常非常慢。
2)虚拟化
a)禁止内存过度分配
内存过度分配(memory overcommitting)的设置值决定了当进程向操作系统请求过度内存是应采取的策略。基于这一设置,内核可能会为进程分配内存,哪怕那些内存当前是不可用的(期望的结果是,当进程用到这段内存时它已变为可用的)。这种内核向进程许诺不存在的内存的行为,就叫做内存过度分配。这一特性使得Mongodb无法很好的运作。
vm.overcomit_memory的值可能为0(让内核来猜测过度分配的大小),可能为1(满足所有内存分配请求),可能为2(分配的虚拟地址空间最多不超过交换空间与一小部分过度分配的和)。将此值设为2所代表的意义最为复杂,同时也是最佳选择。运行以下命令将此值设为2:
$ echo 2>/proc/sys/vm/overcommit_memory
更改这一设置后,无需重启Mongodb.
在此目录下,/proc/sys/vm/overcommit_memory
该文件指定了内核针对内存分配的策略,其值可以是0、1、2。
0, 表示内核将检查是否有足够的可用内存供应用进程使用;如果有足够的可用内存,内存申请允许;否则,内存申请失败,并把错误返回给应用进程。
1, 表示内核允许分配所有的物理内存,而不管当前的内存状态如何。
2, 表示内核允许分配超过所有物理内存和交换空间总和的内存(参照overcommit_ratio)。
缺省设置:0
3) 在查阅文档中,对Linux下proc里关于磁盘性能的参数有涉及,如下:
mongodb的mmap不调用fsync强刷到磁盘,操作系统也是会帮我们自动刷到磁盘的,linux有个dirty_writeback_centisecs参数用于定义脏数据在内存停留的时间(默认为500,即5秒),过了这个timeout时间就会被系统刷到磁盘上。在这个自动刷的过程中是会阻塞所有的IO操作的,如果要刷的数据特别多的话,容易产生一些长耗时的操作,例如有些使用mmap的程序每隔一段时间就会出现有超时操作,一般的优化手段是考虑修改系统参数dirty_writeback_centisecs,加快脏页刷写频率来减少长耗时。mongodb是定时强刷,不会有此问题。
在此目录下,/proc/sys/vm/dirty_writeback_centisecs
这个参数控制内核的脏数据刷新进程pdflush的运行间隔。单位是 1/100 秒。缺省数值是500,也就是 5 秒。如果你的系统是持续地写入动作,那么实际上还是降低这个数值比较好,这样可以把尖峰的写操作削平成多次写操作。设置方法如下:
echo "100" > /proc/sys/vm/dirty_writeback_centisecs
如果你的系统是短期地尖峰式的写操作,并且写入数据不大(几十M/次)且内存有比较多富裕,那么应该增大此数值:
echo "1000" > /proc/sys/vm/dirty_writeback_centisecs
4)日志
mongodb默认将日志发送至stdout(标准输出,通常为终端)。大多初始化脚本会使用–logpath选项,将日志发送至文件。如在同一台机器上有多个MongoDB实例(比如说一个mongod和一个mongos),注意保证各实例的日志分别存放在单独的文件中。确保知道的日志的存放位置,并拥有文件的读访问权限。
Mongodb会输出大量的日志消息,但请不要使用 --quiet选项(该选项会隐藏部分日志信息)。保持日志级别为默认值通常不错,此时日志中有足够的信息进行基本调试(如耗时过长或者启动异常的原因等),但日志占用的空间并不大。调试应用某特定问题时,可使用一些选项从日志中获取更多信息。
首先,在重启Mongodb时,可通过在参数中附加数目更多的“v”(即-v、-vv、-vvv、-vvvv或-vvvvv),或运行如下setParameter命令,完成日志级别(loglevel)的更改。
>db.adminCommand({"setParameter":1,"logLevel":3});
记得将日志级别重设为0,否则日志中会存在过多不必要的内容。可将日志级别调高至5,这时mongod会在日志中记录几乎所有的操作,包括每一个请求所处理的内容。由于mongod将所有内容都写入了日志文件,因此可产生大量的磁盘读写操作(IO),从而拖慢一个忙碌的系统。如需即时看到正在进行的所有操作,打开分析器不失为更好的方法:
MongoDB默认记录耗时超过100毫秒的查询信息。如100毫秒不适用于应用,可通过setProfilingLevel 命令来更改此阈值:
> // 只记录耗时超过500毫秒的查询操作
> db.setProfilingLevel(1,500)
{"was":0,"slowms":100,"ok":1}
>db.setProfilingLevel(0)
{"was":1,"slowms":500,"ok":1}
上述第二条指令将关闭分析器,,但第一条指令中以毫秒为单位的值将继续作为所有数据库中日志记录的阈值而生效。也可以用-slowms 选项重启MongoDB来更改这一阈值。
最后,设置一个计划任务以便每天或每周分割(rotate)日志文件。如使用–logpath 选项启动MongoDB,向进程发送一个SIGUSR1 信号即使其对日志进行分割。也可以使用logRotate命令以达到相同目的:
>db.adminCommand({"logRotate":1})
如不是通过 --logpath 选项启动的MongoDB,则不能对日志进行分割。
5) 关闭数据库文件的 atime
禁止系统对文件的访问时间更新会有效提高文件读取的性能。这个可以通过在/etc/fstab 文件中增加 noatime 参数来实现。例如:
/dev/xvdb /data ext4 noatime 0 0
修改完文件后重新 mount就可以:
# mount -o remount /data
6)禁止 NUMA
在一个使用NUMA技术的多处理器Linux 系统上,你应该禁止NUMA的使用。MongoDB在NUMA环境下运行性能有时候会可能变慢,特别是在进程负载很高的情况下。
------------------------------------------分割线------------------------------------------
CentOS 6 使用 yum 安装MongoDB及服务器端配置
Ubuntu 13.04下安装MongoDB2.4.3
MongoDB入门必读(概念与实战并重)
Ubunu 14.04下MongoDB的安装指南
《MongoDB 权威指南》(MongoDB: The Definitive Guide)英文文字版[PDF]
Nagios监控MongoDB分片集群服务实战
基于CentOS 6.5操作系统搭建MongoDB服务
MongoDB 的详细介绍:请点这里
MongoDB 的下载地址:请点这里
本文永久更新链接地址:

MySQL index cardinality has a significant impact on query performance: 1. High cardinality index can more effectively narrow the data range and improve query efficiency; 2. Low cardinality index may lead to full table scanning and reduce query performance; 3. In joint index, high cardinality sequences should be placed in front to optimize query.

The MySQL learning path includes basic knowledge, core concepts, usage examples, and optimization techniques. 1) Understand basic concepts such as tables, rows, columns, and SQL queries. 2) Learn the definition, working principles and advantages of MySQL. 3) Master basic CRUD operations and advanced usage, such as indexes and stored procedures. 4) Familiar with common error debugging and performance optimization suggestions, such as rational use of indexes and optimization queries. Through these steps, you will have a full grasp of the use and optimization of MySQL.

MySQL's real-world applications include basic database design and complex query optimization. 1) Basic usage: used to store and manage user data, such as inserting, querying, updating and deleting user information. 2) Advanced usage: Handle complex business logic, such as order and inventory management of e-commerce platforms. 3) Performance optimization: Improve performance by rationally using indexes, partition tables and query caches.

SQL commands in MySQL can be divided into categories such as DDL, DML, DQL, DCL, etc., and are used to create, modify, delete databases and tables, insert, update, delete data, and perform complex query operations. 1. Basic usage includes CREATETABLE creation table, INSERTINTO insert data, and SELECT query data. 2. Advanced usage involves JOIN for table joins, subqueries and GROUPBY for data aggregation. 3. Common errors such as syntax errors, data type mismatch and permission problems can be debugged through syntax checking, data type conversion and permission management. 4. Performance optimization suggestions include using indexes, avoiding full table scanning, optimizing JOIN operations and using transactions to ensure data consistency.

InnoDB achieves atomicity through undolog, consistency and isolation through locking mechanism and MVCC, and persistence through redolog. 1) Atomicity: Use undolog to record the original data to ensure that the transaction can be rolled back. 2) Consistency: Ensure the data consistency through row-level locking and MVCC. 3) Isolation: Supports multiple isolation levels, and REPEATABLEREAD is used by default. 4) Persistence: Use redolog to record modifications to ensure that data is saved for a long time.

MySQL's position in databases and programming is very important. It is an open source relational database management system that is widely used in various application scenarios. 1) MySQL provides efficient data storage, organization and retrieval functions, supporting Web, mobile and enterprise-level systems. 2) It uses a client-server architecture, supports multiple storage engines and index optimization. 3) Basic usages include creating tables and inserting data, and advanced usages involve multi-table JOINs and complex queries. 4) Frequently asked questions such as SQL syntax errors and performance issues can be debugged through the EXPLAIN command and slow query log. 5) Performance optimization methods include rational use of indexes, optimized query and use of caches. Best practices include using transactions and PreparedStatemen

MySQL is suitable for small and large enterprises. 1) Small businesses can use MySQL for basic data management, such as storing customer information. 2) Large enterprises can use MySQL to process massive data and complex business logic to optimize query performance and transaction processing.

InnoDB effectively prevents phantom reading through Next-KeyLocking mechanism. 1) Next-KeyLocking combines row lock and gap lock to lock records and their gaps to prevent new records from being inserted. 2) In practical applications, by optimizing query and adjusting isolation levels, lock competition can be reduced and concurrency performance can be improved.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Dreamweaver Mac version
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

SublimeText3 Linux new version
SublimeText3 Linux latest version

WebStorm Mac version
Useful JavaScript development tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.