mongoDB の 1 インスタンス中の DB の数によって、起動時間がどのように変わるかを確認した

mongoDB に大量のデータベースを作成したとき、起動時間がやたらとかかってしまったため、どんな傾向があるかを確認してみた。



#mongoDB バージョン

    Linux 版 3.0.4　（engine=WiredTiger, compressor=指定なし(default:snappy)）
    Linux 版 2.6.9

						
#確認方法

    1DB 1コレクションとしてデータを登録(1件 or 14400件)	
    mongoDBを停止して、time コマンドで mongoDB の起動時間を測定 (1回のみ)


#登録データフォーマット

    {
        "h" : {
            "t" : 1,
            "o" : 9,
            "n" : "hostname0001",
            "i" : "item0001"
        },
        "d" : [
            {
                "p" : "parameter1",
                "v" : 1.1
            },
            {
                "p" : "parameter2",
                "v" : 2.2
            },
            {
                "p" : "parameter3",
                "v" : 3.3
            }
        ]
    }



# mongo shell で登録

    for(var i = 0; i < 1600; i++){
        dbname = 'hoge' + i;
        db.getMongo().getDB(dbname).getCollection("hogehoge").insert([
            {"h":{"t":1,"o":9,"n":"hostname0001","i":"item0001"},"d":[{"p":"parameter1","v":1.1},{"p":"parameter2","v":2.2},{"p":"parameter3","v":3.3}]}
        ])
    }



#定義ファイル

    (3.0.4)
    #http://docs.mongodb.org/manual/reference/configuration-options/
    systemLog:
    #    verbosity: 0                                                #type:integer; default:0
    #    component:
    #        accessControl:
    #            verbosity: 0                                        #type:integer; default:0
    #        command:
    #            verbosity: 0                                        #type:integer; default:0
    #        control:
    #            verbosity: 0                                        #type:integer; default:0
    #        geo:
    #            verbosity: 0                                        #type:integer; default:0
    #        index:
    #            verbosity: 0                                        #type:integer; default:0
    #        network:
    #            verbosity: 0                                        #type:integer; default:0
    #        query:
    #            verbosity: 0                                        #type:integer; default:0
    #        replication:
    #            verbosity: 0                                        #type:integer; default:0
    #        sharding:
    #            verbosity: 0                                        #type:integer; default:0
    #        storage:
    #            verbosity: 0                                        #type:integer; default:0
    #            journal:
    #                verbosity: 0                                    #type:integer; default:0
    #        write:
    #            verbosity: 0                                        #type:integer; default:0
        quiet: true                                                 #type:boolean
    #    traceAllExceptions:                                         #type:boolean
    #    syslogFacility: user                                        #type:string; default:user
                                                                    #type:string ex) /mongo/log/mongod.log
        path: "/data/log/mongod.log"
    #    logAppend: false                                            #type:boolean; default:false
        logAppend: true                                             #type:boolean; default:false
    #    logRotate: rename                                           #type:string; default:rename
        destination: file                                           #type:string
    #    timeStampFormat: iso8601-local                              #type:string; default:iso8601-local
    processManagement:
    #    pidFilePath: "/var/run/mongod.pid"                          #type:string
            fork: true                                                  #type:boolean; default:false
    net:
                                                                    #type:integer
        port: 23456
    #    bindIp:                                                     #type:string; default:All interfaces
    #    maxIncomingConnections: 65536                               #type:integer; default:65536
    #    wireObjectCheck: true                                       #type:boolean; default:true
    #    http:
    #        enabled: false                                          #type:boolean; default:false
    #        JSONPEnabled: false                                     #type:boolean; default:false
    #        RESTInterfaceEnabled: true                              #type:boolean; default:false
    #    unixDomainSocket:
    #        enabled: false                                          #type:boolean; default:false
    #        pathPrefix: /tmp                                        #type:string; default:/tmp
    #    ipv6: false                                                 #type:boolean; default:false
    #    ssl:
    #        sslOnNormalPorts:                                       #type:boolean
    #        mode:                                                   #type:string
    #        PEMKeyFile:                                             #type:string
    #        PEMKeyPassword:                                         #type:string
    #        clusterFile:                                            #type:string
    #        clusterPassword:                                        #type:string
    #        CAFile:                                                 #type:string
    #        CRLFile:                                                #type:string
    #        allowConnectionsWithoutCertificates:                    #type:boolean
    #        allowInvalidCertificates:                               #type:boolean
    #        allowInvalidHostnames:                                  #type:boolean
    #        FIPSMode:                                               #type:boolean
    #setParameter:
    #    notablescan: 0                                              #type:none default:0 Don't run production mongod instances with notablescan
    #security:
    #    keyFile: "/mongo/keyfile"                                   #type:string
    #    clusterAuthMode: keyFile                                    #type:string; default:keyFile
    #    authorization: disabled                                     #type:string; default:disabled
    #    sasl:
    #        hostName:                                               #type:string
    #        serviceName:                                            #type:string
    #        saslauthdSocketPath:                                    #type:string
    #    javascriptEnabled: true                                     #type:boolean; default:true
    #operationProfiling:
    #    slowOpThresholdMs: 100                                      #type:integer; default:100
    #    mode: off                                                   #type:string; default:off
    storage:
                                                                    #type: database path ex) /mongo/db
        dbPath: "/data/db"
    #    directoryPerDB: false                                       #type:string; default:false
        directoryPerDB: true                                        #type:string; default:false
    #    indexBuildRetry: true                                       #type:boolean; default:true
        journal:
            enabled: true                                           #type:boolean; default:true
    #    syncPeriodSecs: 60                                          #type:number; default:60
    #    engine: mmapv1                                              #type:string(mmapv1|wiredTiger); default:mmapv1
        engine: wiredTiger                                          #type:string(mmapv1|wiredTiger); default:mmapv1
        mmapv1:
    #        preallocDataFiles: true                                 #type:boolean; default:true
    #        quota:
    #            enforced: false                                     #type:boolean; default:false
    #            maxFilesPerDB: 8                                    #type:integer; default:8
    #        journal:
    #           debugFlags:                                          #type:integer
    #            commitIntervalMs: 100                               #type:number; default:100
    #        smallFiles: false                                       #type:boolean; default:false
    #        nsSize: 16                                              #type:integer; default:16
            nsSize: 1                                                #type:integer; default:16
    #    wiredTiger:
    #        engineConfig:
    #            cacheSizeGB: 1                                      #type:none; default:the maximum of half of physical RAM or 1 gigabyte
    #            directoryForIndexes: false                          #type:boolean; defalut:false
    #            statisticsLogDelaySecs: 0                           #type:none; default:0
    #        collectionConfig:
    #            blockCompressor: snappy                             #type:none|snappy|zlib; default:snappy
    #        indexConfig:
    #            prefixCompression: true                             #type:none; default:true
    #    repairPath:                                                 #type:string
    #replication:
    #    oplogSizeMB:                                                #type:integer
    #    replSetName:                                                #type:string
    #    secondaryIndexPrefetch: all                                 #type:string; default:all
    #sharding:
    #    clusterRoll:                                                #type:string
    #    archiveMovedChunks:                                         #type:boolean
    #auditLog:
    #    destination:                                                #type:string
    #    format:                                                     #type:string
    #    path:                                                       #type:string
    #    filter:                                                     #type:string representation of a document
    #snmp:
    #    subagent:                                                   #type:boolean
    #    master:                                                     #type:boolean


    (2.6.9)
    #http://docs.mongodb.org/manual/reference/configuration-options/
    systemLog:
    #    verbosity:                                                  #type:integer
        quiet: true                                                 #type:boolean
    #    traceAllExceptions: false                                   #type:boolean
    #    syslogFacility: user                                        #type:string; default:user
                                                                    #type:string ex) /mongo/log/mongod.log
        path: "/data/log/mongod.log"
    #    logAppend: false                                            #type:boolean; default:false
        logAppend: true                                             #type:boolean; default:false
        destination: file                                           #type:string
    #    timeStampFormat: iso8601-local                              #type:string; default:iso8601-local
    processManagement:
    #    pidFilePath: "/var/run/mongod.pid"                          #type:string
        fork: true                                                  #type:boolean; default:false
    net:
                                                                    #type:integer
        port: 23456
    #    bindIp:                                                     #type:string; default:All interfaces
    #    maxIncomingConnections: 1000000                             #type:integer; default:1000000
    #    wireObjectCheck: true                                       #type:boolean; default:true
    #    http:
    #        enabled: false                                          #type:boolean; default:false
    #        JSONPEnabled: false                                     #type:boolean; default:false
    #        RESTInterfaceEnabled: true                              #type:boolean; default:false
    #    unixDomainSocket:
    #        enabled: false                                          #type:boolean; default:false
    #        pathPrefix: /tmp                                        #type:string; default:/tmp
    #    ipv6: false                                                 #type:boolean; default:false
    #    ssl:
    #        sslOnNormalPorts:                                       #type:boolean
    #        mode:                                                   #type:string
    #        PEMKeyFile:                                             #type:string
    #        PEMKeyPassword:                                         #type:string
    #        clusterFile:                                            #type:string
    #        clusterPassword:                                        #type:string
    #        CAFile:                                                 #type:string
    #        CRLFile:                                                #type:string
    #        weakCertificateValidation:                              #type:boolean
    #        allowInvalidCertificates:                               #type:boolean
    #        FIPSMode:                                               #type:boolean
    #setParameter:
    #    notablescan: 0                                              #type:none; default:0 Don't run production mongod instances with notablescan
    #security:
    #    keyFile: "/mongo/keyfile"                                   #type:string
    #    clusterAuthMode: keyFile                                    #type:string; default:keyFile
    #    authorization: disabled                                     #type:string; default:disabled
    #    sasl:
    #        hostName:                                               #type:string
    #        serviceName:                                            #type:string
    #        saslauthdSocketPath:                                    #type:string
    #    javascriptEnabled: true                                     #type:boolean; default:true
    #operationProfiling:
    #    slowOpThresholdMs: 100                                      #type:integer; default:100
    #    mode: off                                                   #type:string; default:off
    storage:
                                                                    #type:string ex) /mongo/db
        dbPath: "/data/db"
    #    directoryPerDB: false                                       #type:boolean; default:false
        directoryPerDB: true                                        #type:boolean; default:false
    #    indexBuildRetry: true                                       #type:boolean; default:true
    #    preallocDataFiles: true                                     #type:boolean; default:true
    #    nsSize: 16                                                  #type:integer; default:16
        nsSize: 1                                                   #type:integer; default:16
    #    quota:
    #        enforced: false                                         #type:boolean; default:false
    #        maxFilesPerDB: 8                                        #type:integer; default:8
    #    smallFiles: false                                            #type:boolean; default:false
    #    syncPeriodSecs: 60                                          #type:integer; default:60
    #    repairPath:                                                 #type:string
        journal:
            enabled: true                                           #type:boolean; default:true
    #        debugFlags:                                             #type:integer
    #        commitIntervalMs: 100                                   #type:number; default:100
    #auditLog:
    #    destination:                                                #type:string
    #    format:                                                     #type:string
    #    path:                                                       #type:string
    #    filter:                                                     #type:string representation of a document




#結果

**起動時間(秒)**

(データ数=1 の場合)

| mongoDB バージョン | 100 | 200 | 400 | 800 | 1600 |
|:-:|:-:|:-:|:-:|:-:|:-:|
|3.0.4|0.326|0.367|0.467|0.708|1.554|
|2.6.9|0.201|0.525|2.530|16.685|47.501|



(データ数=14400 の場合)

| mongoDB バージョン | 100 | 200 | 400 | 800 | 1600 |
|:-:|:-:|:-:|:-:|:-:|:-:|
|3.0.4|2.117|3.501|7.594|12.555|26.343|
|2.6.9|1.650|5.317|14.132|34.836|75.537|



#気付き

停止・起動を 2 回、3 回と繰り返すと、初回と比べて起動時間が全く違ったもの（いい方に）に
なったことがあったので、1 発の測定とした。

mongoDB 3.x となって、起動時間も大幅に好転しているようだ。

数百程度の DB 数であれば起動時間もそれほど問題ないように見えるが、百台後半になると、
起動も相当の時間がかかるようだ。