搜尋
首頁資料庫mysql教程mongodb 索引和查询分析器—dex

mongodb 索引和查询分析器—dex

Jun 07, 2016 pm 04:37 PM
dexmmongodb介紹分析器查詢索引

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
当使用-w/--watch和-p/--profile监视system.profile集合时,必须指定单一的库。
> dex -w -p -n "myDb.*" mongodb://myUser:myPass@myHost:12345/myDb
如果未启用profiling,dex将启用级别1的profiling。

其他有用的选项

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

实例如下

dex
陳述
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
在MySQL中使用視圖的局限性是什麼?在MySQL中使用視圖的局限性是什麼?May 14, 2025 am 12:10 AM

mysqlviewshavelimitations:1)他們不使用Supportallsqloperations,限制DatamanipulationThroughViewSwithJoinsOrsubqueries.2)他們canimpactperformance,尤其是withcomplexcomplexclexeriesorlargedatasets.3)

確保您的MySQL數據庫:添加用戶並授予特權確保您的MySQL數據庫:添加用戶並授予特權May 14, 2025 am 12:09 AM

porthusermanagementinmysqliscialforenhancingsEcurityAndsingsmenting效率databaseoperation.1)usecReateusertoAddusers,指定connectionsourcewith@'localhost'or@'%'。

哪些因素會影響我可以在MySQL中使用的觸發器數量?哪些因素會影響我可以在MySQL中使用的觸發器數量?May 14, 2025 am 12:08 AM

mysqldoes notimposeahardlimitontriggers,butacticalfactorsdeterminetheireffactective:1)serverConfiguration impactactStriggerGermanagement; 2)複雜的TriggerSincreaseSySystemsystem load; 3)largertablesslowtriggerperfermance; 4)highConconcConcrencerCancancancancanceTigrignecentign; 5); 5)

mysql:存儲斑點安全嗎?mysql:存儲斑點安全嗎?May 14, 2025 am 12:07 AM

Yes,it'ssafetostoreBLOBdatainMySQL,butconsiderthesefactors:1)StorageSpace:BLOBscanconsumesignificantspace,potentiallyincreasingcostsandslowingperformance.2)Performance:LargerrowsizesduetoBLOBsmayslowdownqueries.3)BackupandRecovery:Theseprocessescanbe

mySQL:通過PHP Web界面添加用戶mySQL:通過PHP Web界面添加用戶May 14, 2025 am 12:04 AM

通過PHP網頁界面添加MySQL用戶可以使用MySQLi擴展。步驟如下:1.連接MySQL數據庫,使用MySQLi擴展。 2.創建用戶,使用CREATEUSER語句,並使用PASSWORD()函數加密密碼。 3.防止SQL注入,使用mysqli_real_escape_string()函數處理用戶輸入。 4.為新用戶分配權限,使用GRANT語句。

mysql:blob和其他無-SQL存儲,有什麼區別?mysql:blob和其他無-SQL存儲,有什麼區別?May 13, 2025 am 12:14 AM

mysql'sblobissuitableForStoringBinaryDataWithInareLationalDatabase,而ilenosqloptionslikemongodb,redis和calablesolutionsolutionsolutionsoluntionsoluntionsolundortionsolunsonstructureddata.blobobobissimplobisslowdeperformberbutslowderformandperformancewithlararengedata;

mySQL添加用戶:語法,選項和安全性最佳實踐mySQL添加用戶:語法,選項和安全性最佳實踐May 13, 2025 am 12:12 AM

toaddauserinmysql,使用:createUser'username'@'host'Indessify'password'; there'showtodoitsecurely:1)choosethehostcarecarefullytocon trolaccess.2)setResourcelimitswithoptionslikemax_queries_per_hour.3)usestrong,iniquepasswords.4)Enforcessl/tlsconnectionswith

MySQL:如何避免字符串數據類型常見錯誤?MySQL:如何避免字符串數據類型常見錯誤?May 13, 2025 am 12:09 AM

toAvoidCommonMistakeswithStringDatatatPesInMysQl,CloseStringTypenuances,chosethirtightType,andManageEngencodingAndCollat​​ionsEttingSefectery.1)usecharforfixed lengengtrings,varchar forvariable-varchar forbariaible length,andtext/blobforlargerdataa.2 seterters seterters seterters

See all articles

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

SecLists

SecLists

SecLists是最終安全測試人員的伙伴。它是一個包含各種類型清單的集合,這些清單在安全評估過程中經常使用,而且都在一個地方。 SecLists透過方便地提供安全測試人員可能需要的所有列表,幫助提高安全測試的效率和生產力。清單類型包括使用者名稱、密碼、URL、模糊測試有效載荷、敏感資料模式、Web shell等等。測試人員只需將此儲存庫拉到新的測試機上,他就可以存取所需的每種類型的清單。

SublimeText3 英文版

SublimeText3 英文版

推薦:為Win版本,支援程式碼提示!

SublimeText3 Linux新版

SublimeText3 Linux新版

SublimeText3 Linux最新版

VSCode Windows 64位元 下載

VSCode Windows 64位元 下載

微軟推出的免費、功能強大的一款IDE編輯器

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)