2017-12-13 14 views
0

私は(小さい、256 MB)MongoDB 3.2.9サービスインスタンスをSwisscom CloudFoundryから使用しています。 DB全体が使用可能なRAMに収まる限り、いくらか受け入れ可能なクエリのパフォーマンスがあります。mongodbのクエリがとても遅いのはなぜですか(Swisscomクラウド上)?

ただし、私たちのDBがRAMに収まらない場合は、集計操作で非常に長いクエリ時間が発生しています。私たちはは、アクセスされたフィールドのインデックスを作成しましたが、それが助けにならない限り、私はそれを伝えることができます。

例の文書エントリ:

_id: 5a31... 
description: Object 
    location: "XYZ" 
    name: "ABC" 
    status: "A" 
    m_nr: null 
    k_nr: null 
    city: "QWE" 
    high_value: 17 
    right_value: 71 
more_data: Object 
    number: 101 
    interval: 1 
    next_date: "2016-01-16T00:00:00Z" 
    last_date: null 
    status: null 
classification: Object 
    priority_value: "?" 
    redundancy_value: "?" 
    active_value: "0" 

クエリ例:

db.getCollection('a').aggregate(
    [{ $sort: 
     {"description.location": 1} 
    }, 
    { $group: 
     {_id: "$description.location"} 
    }], 
    { explain: true } 
) 

は、このクエリは20Kのエントリーがあり、1K出力フィールドを生成DBに 25秒をとります。

このクエリの説明情報:

db.getCollection('a').aggregate([{ $group: {_id: "$description.location"} }], { explain: true }): 

{ 
    "waitedMS" : NumberLong(0), 
    "stages" : [ 
     { 
      "$cursor" : { 
       "query" : {}, 
       "fields" : { 
        "description.location" : 1, 
        "_id" : 0 
       }, 
       "queryPlanner" : { 
        "plannerVersion" : 1, 
        "namespace" : "Z.a", 
        "indexFilterSet" : false, 
        "parsedQuery" : { 
         "$and" : [] 
        }, 
        "winningPlan" : { 
         "stage" : "COLLSCAN", 
         "filter" : { 
          "$and" : [] 
         }, 
         "direction" : "forward" 
        }, 
        "rejectedPlans" : [] 
       } 
      } 
     }, 
     { 
      "$group" : { 
       "_id" : "$description.location" 
      } 
     } 
    ], 
    "ok" : 1.0 
} 

[UPDATE] db.a.getIndexes()出力:それは、コレクションのスキャンをやっているよう

/* 1 */ 
[ 
    { 
     "v" : 1, 
     "key" : { 
      "_id" : 1 
     }, 
     "name" : "_id_", 
     "ns" : "db.a" 
    }, 
    { 
     "v" : 1, 
     "key" : { 
      "description.location" : 1.0 
     }, 
     "name" : "description.location_1", 
     "ns" : "db.a" 
    } 
] 

答えて

2

が見えるが、あなたはdescription.locationにインデックスを追加しようとしています?

db.a.createIndex({"description.location" : 1}); 
+0

ありがとうございます - ありがとうございます - 「description.location」にインデックスがあります - なぜインデックスを使用していないのでしょうか? – Chris

+1

これをローカルで試してインデックスを使用していますが、 'db.a.getIndexes()'を実行して質問を出力に更新できますか? –

+0

はい、出力を更新して更新します。私もこれをローカルでテストしましたが、実際にインデックスを使用していました。したがって、私は、SwisscomクラウドにMongoDBの設定が特別なものがあるかどうか疑問に思っていました。別のスレッドで、 'security.javaScriptEnabled'設定を無効にしています:https://stackoverflow.com/questions/40179448/mongodb-cannot-run-map-reduce-without-the-js-engine/40290196 – Chris

関連する問題