serverStatus 输出几百个字段,上线以后到底该盯哪些?每个计数器的口径是什么?这篇每个指标做一个已知的操作,对着增量验证。
做了:insert_many 1,000 个文档(1 次调用)、find_one 500 次、update_one 200 次、delete_one 100 次、ping 50 次
opcounters 的增量: {'opcounters.insert': 1000, 'opcounters.query': 500, 'opcounters.update': 200, 'opcounters.delete': 100, 'opcounters.getmore': 0, 'opcounters.command': 51}
连续两次 serverStatus,中间什么都不做: opcounters.command 增量 = 1(所以上面 51 = 50 次 ping + 最后那次 serverStatus 自己)
insert 记的是文档数(insert_many 的 1 个命令记了 1,000)计数器是累计值,要看增量;insert 记文档数,serverStatus 自己也会让 command 加 1。
做了:find {k < 10}(1 次)、update_many {k: 1}(1 次)、delete_many {k: 2}(1 次)
metrics.document 增量: {'metrics.document.returned': 90, 'metrics.document.inserted': 0, 'metrics.document.updated': 9, 'metrics.document.deleted': 9}
opcounters 增量: {'opcounters.query': 1, 'opcounters.update': 1, 'opcounters.delete': 1}metrics.document 是服务端处理的文档数(returned 90、updated 9、deleted 9),与 opcounters 的命令数不是一回事。
k = 7,没有 k 索引(全表扫描): 扫描索引键 0,扫描文档 49,891,返回 499 k = 7,有 k 索引: 扫描索引键 499,扫描文档 499,返回 499 只要 k(覆盖查询): 扫描索引键 499,扫描文档 0,返回 499
queryExecutor.scanned 是扫描的索引键、scannedObjects 是扫描的文档;加索引后从 49,891 个文档变成 499,覆盖查询为 0。
connections 基线: {'current': 5, 'available': 209710, 'totalCreated': 8, 'active': 4}
再开 20 个客户端并各 ping 一次: {'current': 65, 'available': 209650, 'totalCreated': 68, 'active': 24}
每个客户端对象占 3 个连接(一个操作连接 + 驱动的 2 个监控连接)
这 20 个客户端 close 之后 0.5 秒: {'current': 24, 'available': 209691, 'totalCreated': 68, 'active': 23}
close 之后 3.5 秒: {'current': 3, 'available': 209712, 'totalCreated': 68, 'active': 2}
返回了 24,941 个文档:network.bytesOut 增加 3,550,481 字节,bytesIn 增加 324 字节,numRequests 增加 3每个 pymongo 客户端对象占 3 个连接,close 之后连接释放不是立刻的;network.bytesOut 随返回数据量增长。
基线: {'bytes currently in the cache': 8474078, 'maximum bytes configured': 268435456, 'tracked dirty bytes in the cache': 50345, 'pages read into cache': 41, 'bytes read into cache': 2565180, 'bytes written from cache': 7465170}
写入 10 万个 1 KB 文档(约 100 MB)后: {'bytes currently in the cache': 60021792, 'maximum bytes configured': 268435456, 'tracked dirty bytes in the cache': 7805931, 'pages read into cache': 41, 'bytes read into cache': 2565180, 'bytes written from cache': 109527741}
重启后(缓存是空的): {'bytes currently in the cache': 53515, 'maximum bytes configured': 268435456, 'tracked dirty bytes in the cache': 10652, 'pages read into cache': 21, 'bytes read into cache': 76900, 'bytes written from cache': 31214}
读完 100,000 个文档后: {'bytes currently in the cache': 113895114, 'maximum bytes configured': 268435456, 'tracked dirty bytes in the cache': 10652, 'pages read into cache': 914, 'bytes read into cache': 104557054, 'bytes written from cache': 31214}
pages read into cache 增加 893;bytes currently in the cache 增加 113,841,599 字节写入后缓存涨到约 60 MB,重启后清空,读一遍后涨到约 114 MB;pages read into cache 反映从磁盘读入。
reads:延迟增加 22,430 μs,操作数增加 2,000 → 平均 11.2 μs writes:延迟增加 35,340 μs,操作数增加 2,000 → 平均 17.7 μs commands:延迟增加 626 μs,操作数增加 1 → 平均 626.0 μs (做了 2,000 次 insert_one 和 2,000 次 find_one;commands 多出的 1 个操作是 b 那次 serverStatus 自己)
累计延迟除以操作数得平均延迟:reads 11.2 μs、writes 17.7 μs。