2011-08-09 6 views
2

私が構築している分析システムのバックエンドとしてMongoDBを使用したいと思います。 MongoDBを使用する主な利点の1つは、組み込みのmap reduceです。 私たちは "中規模のデータ"規模なので、Hadoopのオーバーヘッドはまだ必要ありません。テスト目的のためにMongoDB map-reduceが遅くなり、メモリ不足になる

私はタイプEC2ラージインスタンス上のuser_idのインデックスを持つ

{ 
user_id: xxxx, 
thing_id:xxxx, 
time: xxx 
} 

50万行を挿入します。その単一インスタンスmongodb(シャードされていない)。

db.user_thing_like.find({user_id: 37104857}) 

は1秒未満です。

しかし、私はユーザーエントリの数を数えたいと思っていたmapreduceは一晩中にメモリ不足のエラーで返されました。私が何かしなければならないか、mongo dbは私がやりたいことに対して正しいツールではありません。

私はMongo DBを初めて使用しており、助けていただければ幸いです。事前に感謝

ERROR:

Tue Aug 9 13:15:58 uncaught exception: map reduce failed:{ 
     "assertion" : "invoke failed: JS Error: out of memory nofile_b:2", 
     "assertionCode" : 9004, 
     "errmsg" : "db assertion failure", 
     "ok" : 0 
} 

のMapReduce QUERY:

db.user_thing_like.mapReduce(map, reduce, {out: "tmp_test"}, {query: {"user_id" : 37104857 }}); 

MAPとreduce:

map = function() { 
    for (var key in this) { 
     emit(key.user_id, {count: 1}); 
    } 
}; 

reduce = function (key, emits) { 
    total = 0; 
    for (var i in emits) { 
     total += emits[i].count; 
    } 
    return {"count": total}; 
} 

--- --- UPDATE

を私が実現それはmapreduc私が使用した構文では、私のクエリフィルターは考慮されていませんでした。

ここで正しいmapreduceクエリがあります。

db.runCommand({mapreduce: "user_thing_like", map: map, reduce: reduce, out: "tmp_test", query: {"user_id" : 37104857 }}); 

答えて

1
map = function() { 
     emit(this.user_id, {count: 1}); 
    } 
}; 

また、マニュアルから、MapReduceのためのソートキーとしてuser_idを指定しよう:

sort : <sorts the input objects using this key. Useful for optimization, like sorting by the emit key for fewer reduces>] 
+0

解決済み。 db.runCommand({mapreduce: "user_thing_like"、map:map、reduce:reduce、 "tmp_test"、query:{"user_id":37104857}}); – lordOfChaos

0

私はMapReduceのは、私が使用されている構文で、私のクエリフィルタを考慮していなかったことに気づきました。

ここで正しいmapreduceクエリがあります。

db.runCommand({mapreduce: "user_thing_like", map: map, reduce: reduce, out: "tmp_test", query: {"user_id" : 37104857 }}); 
+0

この種類のコメントは、元の質問に含める必要があります。質問の答えとしては提供されません。これらのコメントをあなたの質問に移しました。 – Leopd

関連する問題