zoukankan      html  css  js  c++  java
  • MongoDB 查看chunk块大小

    使用mongo shell连到mongos
    执行命令:AllChunkInfo("dbname.cellname",true)

    点击(此处)折叠或打开

    AllChunkInfo = function(ns, est){

    var chunks = db.getSiblingDB("config").chunks.find({"ns" : ns}).sort({min:1}); //this will return all chunks for the ns ordered by min

    //some counters for overall stats at the end

    var totalChunks = 0;

    var totalSize = 0;

    var totalEmpty = 0;

     print("ChunkID,Shard,ChunkSize,ObjectsInChunk"); // header row

    // iterate over all the chunks, print out info for each

    chunks.forEach(

    function printChunkInfo(chunk) {

    var db1 = db.getSiblingDB(chunk.ns.split(".")[0]); // get the database we will be running the command against later

    var key = db.getSiblingDB("config").collections.findOne({_id:chunk.ns}).key; // will need this for the dataSize call

    // dataSize returns the info we need on the data, but using the estimate option to use counts is less intensive

    var dataSizeResult = db1.runCommand({datasize:chunk.ns, keyPattern:key, min:chunk.min, max:chunk.max, estimate:est});

    // printjson(dataSizeResult); // uncomment to see how long it takes to run and status

    print(chunk._id+","+chunk.shard+","+dataSizeResult.size+","+dataSizeResult.numObjects);

    totalSize += dataSizeResult.size;

    totalChunks++;

    if (dataSizeResult.size == 0) { totalEmpty++ }; //count empty chunks for summary

     }

    )

    print("***********Summary Chunk Information***********");

    print("Total Chunks: "+totalChunks);

    print("Average Chunk Size (bytes): "+(totalSize/totalChunks));

    print("Empty Chunks: "+totalEmpty);

    print("Average Chunk Size (non-empty): "+(totalSize/(totalChunks-totalEmpty)));

  • 相关阅读:
    菜鸟学python之程序初体验
    菜鸟学python之大数据的初认识
    js获取本地ip地址和外网IP地址
    Js中foreach()用法及使用的坑
    模拟实现Promise,探究Promise原理
    搞懂JS的事件循环(Event Loop)和宏任务/微任务
    NodeJS 中的 LRU 缓存(CLOCK-2-hand)实现
    设计模式在前端项目中的应用
    JS 中一些高效的魔法运算符
    Js中如何克隆对象?
  • 原文地址:https://www.cnblogs.com/xibuhaohao/p/11321532.html
Copyright © 2011-2022 走看看