DEPRECATED - 建议将此工具用于MongoDB版本< = 2.6
Dex是一个MongoDB性能调优工具,可将查询与查询集合中的可用索引进行比较,并根据简单的启发式方法生成索引建议。目前,您必须为数据库提供连接URI。
Dex使用您提供的URI作为确定何时推荐索引的有用方法。在实际构建理想推荐时,Dex不会考虑现有索引。
目前,Dex仅推荐完整索引,而不是部分索引。如果找不到一个索引,Dex会忽略查询可能使用的部分索引,以支持更好的索引。 Dex根据经验建议使用部分排序的索引:
您的索引字段顺序应首先回答:
请注意,您的数据基数可能需要与建议的索引不同的顺序。
不支持Windows。
在日志文件上运行Dex并向相应的数据库提供URI(具有auth凭证,如果有)。
> dex -f my/mongod/data/path/mongodb.log mongodb://myUser:myPass@myHost:12345/myDb
或者,在填充的MongoDB system.profile集合上运行Dex。建议您运行db.setProfilingLevel(1),并等待在数据库上运行一组代表性的查询/操作。然后运行db.setProfilingLevel(0)以停止分析。然后,运行Dex:
> dex -p mongodb://myUser:myPass@myHost:12345/myDb
注意:由于Dex主要关注非索引查询,因此Dex输出不应受分析级别2生成的其他数据的影响。但是,Dex可能需要更长时间才能运行。
Dex支持按特定集合和数据库过滤分析。请注意,当您打算分析多个数据库时,必须为admin数据库提供连接URI。
> 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
Dex还支持按查询执行时间过滤分析。提供-s / - slowms参数以规定最小时间(毫秒)。在不到指定时间内完成的查询将不会被分析。
> 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不会处理完整日志文件或system.profile集合中的任何现有内容。相反,Dex会在记录/分析条目时评估条目。在监视模式下运行时,使用键盘中断(Ctrl + C)终止Dex。
使用监视模式实时获取运行信息。
示例:
> dex -w -f my/mongod/data/path/mongodb.log mongodb://myUser:myPass@myHost:12345/myDb
请注意,Dex仍会缓存其建议,因此每个唯一的建议只会打印一次。
使用-w / - watch with -p / - profile来监视system.profile集合时,必须通过提供形式为-n“[db_name]。*的命名空间参数将焦点过滤到一个数据库。 "例如:
> dex -w -p -n "myDb.*" mongodb://myUser:myPass@myHost:12345/myDb
此外,如果未启用性能分析,Dex将在其操作期间启用配置文件级别1。
-t / - timeout - 仅限日志文件(-f)模式。用于在几分钟后截断Dex操作。如果您的数据库生成了非常大的日志文件,您可能只需要dex 1-3分钟即可获得可用信息。
--nocheck - 不检查数据库中的现有索引。这意味着Dex将推荐所有查询的索引,甚至索引索引。
usage: dex [uri] (-f <logfile_path> | -p) [<options>] Scans a provided MongoDB log file or profile collection and uses the provided URI to compare queries found in the logfile or profile collection to the indexes available in the database, recommending indexes for those queries which are not indexed. Recommended for MongoDB version 2.2.0 or later. Options: -h, --help show this help message and exit -f LOGFILE_PATH, --file LOGFILE_PATH path to a MongoDB log file. If provided, the file will be searched for queries. -p, --profile flag to examine the MongoDB system.profile collection. If set, the profile collection will be searched for queries. URI is required for profile mode. -w, --watch instructs Dex to watch the system.profile or log (depending on which -p/-f is specified) for entries, rather than processing existing content. Upon keyboard interrupt (Ctrl+C) watch terminates and the accumulated output is provided. When using watch mode and profile mode together, you must target a specific database using -n "dbname.*" -n NAMESPACES, --namespace NAMESPACES a MongoDB namespace (db.collection). Can be provided multiple times. This option creates a filter, and queries not in the provided namespace(s) will not be analyzed. Format: -n ('db.collection' | '*' | 'db.*' | 'collection'). '*.*' and '*.collection' are redundant but also supported. An asterisk is shorthand for 'all' --actual regexes are not supported. Note that -n '*' is equivalent to not providing a -n argument. -s SLOWMS, --slowms SLOWMS minimum query execution time for analysis, in milliseconds. Analogous to MongoDB's SLOW_MS value. Queries that complete in fewer milliseconds than this value will will not be analyzed. Default is 0. -t TIMEOUT, --timeout TIMEOUT Maximum Dex time in minutes. Default is 0 (no timeout).Applies to logfile (-f) mode only. --nocheck if provided, Dex will recommend indexes without checkingthe specified database to see if they exist. This meansDex may recommend an index that's already been created -v, --verbose enables provision of additional output information.
Dex旨在理解mongod 2.0.4或更高版本的日志和配置文件集合。
图书馆:* pyyaml * pymongo * dargparse
> pip install dex
要运行Dex的单元测试套件,必须在27017上启动一个mongodb服务器.Dex将使用创建dex_test数据库并在测试完成时将其删除。
> python -m dex.test.test
对于每次运行,Dex提供:* runStats - 已解析日志或配置文件的统计信息* runStats.linesRead - 发送给Dex的条目数(日志或配置文件)。 * runStats.linesAnalyzed - Dex成功提取查询和尝试推荐的条目数。 * runStats.linesWithRecommendations - 提示并可能从索引建议中获益的行数。 * runStats.dexTime - Dex的时间启动。 * runStats.logSource - 处理日志文件的路径。空-p / - 配置文件模式。 * runStats.timeRange - 传递给Dex的时间范围。包括读取的所有行。 * runStats.timedOut - 如果Dex操作按-t / - timeout标志超时,则为True。 * runStats.timeoutInMinutes - 如果timedOut为true,则包含时间。 Dex以a的形式为每个唯一查询提供信息和统计信息。建议包括:*结果 - 包括索引建议的查询报告列表。
Dex返回一组查询报告作为结果。每个查询报告都针对由“queryMask”标识的唯一查询。每份报告包括:
样品:
Dex在监视(-w)模式下提供运行时输出。每隔30秒,将使用更新的统计信息打印完整的建议列表。
电子邮件support@mongolab.com