mongodb 索引和查询分析器—dex
dex 介绍 mongodb索引和查询分析器dex,是一种MongoDB的性能调整工具,比较MongoDB的日志文件和索引条目并给出索引建议。目前,必须提供一个连接数据库的URI。 dex只建议完整的索引,而不是部分索引。不支持Windows平台。 dex 工作原理 dex在运行过程中主要
dex 介绍
mongodb索引和查询分析器dex,是一种MongoDB的性能调整工具,比较MongoDB的日志文件和索引条目并给出索引建议。目前,必须提供一个连接数据库的URI。 dex只建议完整的索引,而不是部分索引。不支持Windows平台。dex 工作原理
dex在运行过程中主要会进行下面三个步骤: 1. 解析query 2.?通过已存在的索引对当前query进行判断 3.?如果发现索引不当,就推荐合适的索引第一步:解析query
Dex会对查询query进行解析,分成下面几大类
- EQUIV?– 普通按数值进行的查询,比如:{a: 1}
- SORT?– sort操作,比如: .sort({a: 1})
- RANGE?– 范围查询,比如:Specifically: ‘$ne’, ‘$gt’, ‘$lt’, ‘$gte’, ‘$lte’, ‘$in’, ‘$nin’, ‘$all’, ‘$not’
-
UNSUPPORTED
- 组合式查询,比如:$and, $or, $nor
- 除了RANGE之外的嵌套查询
第二步:判断当前索引情况
有两个标准来找出查询所需的索引。
- Coverage (none, partial, full)?- Coverage表示索引的情况,有括号中的三个值。none表示完全无索引覆盖。full表示query中的字段都能找到索引。partial表示none和full之间的情况。
- Order (ideal or not)?- Order是用于判断索引的顺序是否理想。理想的索引顺序应该是: Equivalence ○ Sort ○ Range 值得注意的是,对地理位置索引只会进行分析,但是不会提出改进建议。
第三步:推荐合适的索引
通过上面两步,我们能够对一个查询可能使用索引的情况有一个了解。Dex会生成一个此查询的最佳索引。如果这个索引不存在,并且查询情况不包括上面提到的UNSUPPORTED,那么Dex就会做出相应的索引优化建议。
dex 使用
常见用法
指定日志文件和提供必要的验证,如果启用了验证和数据库
> dex -f my/mongod/data/path/mongodb.log mongodb://myUser:myPass@myHost:12345/myDb
或是开启db.setProfilingLevel(1),分析后再关闭profiling,db.setProfilingLevel(0)
> dex -p mongodb://myUser:myPass@myHost:12345/myDb
通过db或collection过滤
dex支持通过指定特定的db或collection来过滤分析。如果打算分析多个数据库,必须提供一个连接的URI到admin数据库。> dex -f my/mongod/data/path/mongodb.log -n "myFirstDb.collectionOne" mongodb://myUser:myPass@myHost:12345/myFirstDb > dex -p -n "*.collectionOne" mongodb://myUser:myPass@myHost:12345/admin > dex -f my/mongod/data/path/mongodb.log -n "myFirstDb.*" -n "mySecondDb.*" mongodb://myUser:myPass@myHost:12345/admin
通过查询时间(millis)过滤
dex还支持通过指定查询执行时间来进行过滤,小于指定时间不分析。-s/--slowms参数来指定时间。单位是millis。> dex -f my/mongod/data/path/mongodb.log -s 400 > dex -p -n "*.collectionOne" mongodb://myUser:myPass@myHost:12345/admin --slowms 1000
监视模式
通过指定?-w/--watch参数来实时获取当前信息。> dex -w -f my/mongod/data/path/mongodb.log mongodb://myUser:myPass@myHost:12345/myDb
> dex -w -p -n "myDb.*" mongodb://myUser:myPass@myHost:12345/myDb
其他有用的选项
-t/--timeout - Logfile (-f) ?针对比较大的日志文件,截取一部分。单位分钟。 --nocheck ?忽略现有的索引,对所有的查询进行索引建议。环境需求
mongod 2.0.4或以上版本 依赖库有:- pyyaml
- pymongo
- dargparse
dex 安装
# easy_install pip # pip install dex
结果输出说明
- runStats - 分析日志或profile数据统计段
- runStats.linesRead - 多少条数母(日志或profile)发送到Dex.
- runStats.linesAnalyzed -多少条数目dex成功提取查询,并试图给出建议的数量。
- runStats.linesWithRecommendations - The number of lines that prompted and could potentially benefit from an index recommendation.
- runStats.dexTime - The time Dex was initiated.
- runStats.logSource - Path to logfile processed. Null for -p/--profile mode.
- runStats.timeRange - The range of times passed to Dex. Includes all lines read.
- runStats.timedOut - True if the Dex operation times out per the -t/--timeout flag.
- runStats.timeoutInMinutes - If timedOut is true, this contains the time. Dex provides information and statistics for each unique query in the form of a. A recommendation includes:
- results - 查询报告,包含给出的索引建议。
?标准输出
Dex 返回的查询报告数组作为结果。每个查询报告是一个唯一的查询,标记为 'queryMask'.。每个报告包含:- queryMask - 查询模式, with values masked ($query for query component, $orderby for sort component)
- namespace - The MongoDB namespace in which to create the index, in the form "db.collection"
- stats - specific query statistics aggregated from each query occurrence.
- stats.count - The total number of queries that occurred.
- stats.avgTimeMillis - The average time this query currently takes.
- stats.totalTimeMillis - The sum amount of time consumed by all of the queries that match the queryMask.
- recommendation - A fully-formed recommendation object.
- recommendation.index - The index recommended.
- recommendation.namespace - The recommendation namespace.
- recommendation.shellCommand - A helpful string for creating the index in the MongoDB shell.
实例如下

原文地址:mongodb 索引和查询分析器—dex, 感谢原作者分享。

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

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

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

Hot Topics

2024 is the first year of AI mobile phones. More and more mobile phones integrate multiple AI functions. Empowered by AI smart technology, our mobile phones can be used more efficiently and conveniently. Recently, the Galaxy S24 series released at the beginning of the year has once again improved its generative AI experience. Let’s take a look at the detailed function introduction below. 1. Generative AI deeply empowers Samsung Galaxy S24 series, which is empowered by Galaxy AI and brings many intelligent applications. These functions are deeply integrated with Samsung One UI6.1, allowing users to have a convenient intelligent experience at any time, significantly improving the performance of mobile phones. Efficiency and convenience of use. The instant search function pioneered by the Galaxy S24 series is one of the highlights. Users only need to press and hold

.NET 4.0 is used to create a variety of applications and it provides application developers with rich features including: object-oriented programming, flexibility, powerful architecture, cloud computing integration, performance optimization, extensive libraries, security, Scalability, data access, and mobile development support.

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

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

When developing an e-commerce website, I encountered a difficult problem: how to provide users with personalized product recommendations. Initially, I tried some simple recommendation algorithms, but the results were not ideal, and user satisfaction was also affected. In order to improve the accuracy and efficiency of the recommendation system, I decided to adopt a more professional solution. Finally, I installed andres-montanez/recommendations-bundle through Composer, which not only solved my problem, but also greatly improved the performance of the recommendation system. You can learn composer through the following address:

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).

Detailed explanation of MongoDB efficient backup strategy under CentOS system This article will introduce in detail the various strategies for implementing MongoDB backup on CentOS system to ensure data security and business continuity. We will cover manual backups, timed backups, automated script backups, and backup methods in Docker container environments, and provide best practices for backup file management. Manual backup: Use the mongodump command to perform manual full backup, for example: mongodump-hlocalhost:27017-u username-p password-d database name-o/backup directory This command will export the data and metadata of the specified database to the specified backup directory.

PiNetwork is about to launch PiBank, a revolutionary mobile banking platform! PiNetwork today released a major update on Elmahrosa (Face) PIMISRBank, referred to as PiBank, which perfectly integrates traditional banking services with PiNetwork cryptocurrency functions to realize the atomic exchange of fiat currencies and cryptocurrencies (supports the swap between fiat currencies such as the US dollar, euro, and Indonesian rupiah with cryptocurrencies such as PiCoin, USDT, and USDC). What is the charm of PiBank? Let's find out! PiBank's main functions: One-stop management of bank accounts and cryptocurrency assets. Support real-time transactions and adopt biospecies
