MongoDB调优利器:掌握性能分析工具mongostat

文章目录

一、mongostat定义

mongostat是MongoDB自带的性能分析工具,用于检测mongodb的运行状态。

复制代码
Suwie/ # mongostat --help
Usage:
mongostat <options> <polling interval in seconds>
Monitor basic MongoDB server statistics.
See http://docs.mongodb.org/manual/reference/program/mongostat/ for more information.
general options:
--help print usage
--version print the tool version and exit
verbosity options:
-v, --verbose=<level> more detailed log output (include multiple times for more verbosity, e.g. -vvvvv, or specify a numeric value, e.g. --verbose=N)
--quiet hide all log output
connection options:
-h, --host=<hostname> mongodb host to connect to (setname/host1,host2 for replica sets)
--port=<port> server port (can also use --host hostname:port)
ssl options:
--ssl connect to a mongod or mongos that has ssl enabled
--sslCAFile=<filename> the .pem file containing the root certificate chain from the certificate authority
--sslPEMKeyFile=<filename> the .pem file containing the certificate and key
--sslPEMKeyPassword=<password> the password to decrypt the sslPEMKeyFile, if necessary
--sslCRLFile=<filename> the .pem file containing the certificate revocation list
--sslAllowInvalidCertificates bypass the validation for server certificates
--sslAllowInvalidHostnames bypass the validation for server name
--sslFIPSMode use FIPS mode of the installed openssl library
authentication options:
-u, --username=<username> username for authentication
-p, --password=<password> password for authentication
--authenticationDatabase=<database-name> database that holds the users credentials
--authenticationMechanism=<mechanism> authentication mechanism to use
stat options:
--noheaders dont output column names
-n, --rowcount=<count> number of stats lines to print (0 for indefinite)
--discover discover nodes and display stats for all
--http use HTTP instead of raw db connection
--all all optional fields
--json output as JSON rather than a formatted table

举例说明:

10秒数据,每2秒钟输出

mongostat -h 192.168.10.22 --port 27018 --rowcount 10 2

100秒数据,每5秒输出

mongostat -h 192.168.10.22 --port 27018 -n 100 5

以json格式输出

mongostat -h 192.168.10.22 --port 27018 -n 600 10 --json

输出如下:

二 、输出详解

字段名称 解释描述
insert 每秒插入次数
query 每秒查询次数
update 每秒更新次数
delete 每秒删除次数
getmore 每秒执行getmore次数
command 每秒的命令数,除了插入、查找、更新、删除命令统计外,还统计了别的命令
flushes 对于WiredTiger引擎来说,是指checkpoint的触发次数在一个轮询间隔期间,对于MMAPv1 引擎来说,是指每秒执行fsync将数据写入硬盘的次数。 一般flushes都是0,间断性会是1, 通过计算两个1之间的间隔时间,可以大致了解多长时间flush一次。flush开销是很大的,如果频繁的flush,就需要排查一下原因了[每秒执行fsync将数据写入硬盘的次数]
mapped 所的被mmap的数据量
vsize 虚拟内存使用量(在mongostat最后一次调用的总数据)
res 物理内存使用量(在mongostat最后一次调用的总数据)vsize一般不会有大的变动, res会慢慢的上升,如果res经常突然下降,就需要排查一下是否存在其他的程序正在消费内存
faults 每秒访问失败数,与内存swap有关
qrw 客户端读写等待队列数量,高并发时,一般队列值会升高
arw 客户端读写活跃个数
net_in 网络带宽压力,MongoDB实例的网络进流量
net_out 网络带宽压力,MongoDB实例的网络出流量
conn 打开连接的总数,是qr,qw,ar,aw的总和,MongoDB为每一个连接创建一个线程,线程的创建与释放也会有开销,所以尽量要适当配置连接数的启动参数maxIncomingConnections
time 时间戳

注1:正常情况mongostat输出used部分不建议超出80%,当内存used超过80%时,说明内存压力过大,进而会引起SQL查询性能下降。(现象:正常的SQL变成慢查询)这个时候,就需要考虑升级内存,缓解内存压力!

注2:dirty是cachesize里的脏页,写入量或者QPS比较高的情况,这个比例会增大。

其他说明:

  • q t|r|w #当Mongodb接收到太多的命令而数据库被锁住无法执行完成,它会将命令加入队列。这一栏显示了总共、读、写3个队列的长度,都为0的话表示mongo毫无压力。高并发时,一般队列值会升高。
  • qr #客户端等待从MongoDB实例读数据的队列长度
  • qw #客户端等待从MongoDB实例写入数据的队列长度
  • ar #执行读操作的活跃客户端数量
  • aw #执行写操作的活客户端数量
相关推荐
杜子不疼.14 分钟前
Spring AI 与向量数据库:构建企业级 RAG 智能问答系统
数据库·人工智能·spring
山峰哥18 分钟前
Python爬虫实战:从零构建高效数据采集系统
开发语言·数据库·爬虫·python·性能优化·架构
_OP_CHEN1 小时前
【C++数据结构进阶】从B + 树 / B * 树到数据库索引:B树的进化之路与 MySQL 实战解析
数据结构·数据库·b树·mysql·innodb·b+树·mylsam
云老大TG:@yunlaoda3607 小时前
华为云国际站代理商TaurusDB的成本优化体现在哪些方面?
大数据·网络·数据库·华为云
TG:@yunlaoda360 云老大7 小时前
华为云国际站代理商GeminiDB的企业级高可用具体是如何实现的?
服务器·网络·数据库·华为云
QQ14220784499 小时前
没有这个数据库账户,难道受到了sql注入式攻击?
数据库·sql
残 风9 小时前
pg兼容mysql框架之语法解析层(openHalo开源项目解析)
数据库·mysql·开源
勇往直前plus9 小时前
MyBatis/MyBatis-Plus类型转换器深度解析:从基础原理到自定义实践
数据库·oracle·mybatis
cyhysr10 小时前
sql将表字段不相关的内容关联到一起
数据库·sql
九皇叔叔10 小时前
MySQL 数据库 MVCC 机制
数据库·mysql