我正在從Rails控制檯執行腳本;該腳本抓取MySQL數據庫,創建約500萬個MongoDB文檔。嚴重寫入MongoDB導致Rails服務器流量被阻塞
我注意到,運行rails server
當腳本運行時,任何請求的響應必須等待數千MOPED輸出的線路,例如:
MOPED: 127.0.0.1:27017 UPDATE database=survey_app_development collection=mongo_surveys selector={"_id"=>"509043ec2c5f64685b62c5b3", "questions._id"=>"509043ec2c5f64685b62c5b5"} update={"$set"=>{"questions.1.response"=>{"_id"=>"509043ec2c5f64685b62c5bd", "data"=>{"datepicker"=>"10/21/2011", "response"=>1319216400}, "comment"=>nil}}} flags=[] (0.0000ms)
MOPED: 127.0.0.1:27017 UPDATE database=survey_app_development collection=mongo_surveys selector={"_id"=>"509043ec2c5f64685b62c5b3", "questions._id"=>"509043ec2c5f64685b62c5b6"} update={"$set"=>{"questions.2.response"=>{"_id"=>"509043ec2c5f64685b62c5be", "data"=>{"response"=>"Morning"}, "comment"=>nil}}} flags=[] (0.0000ms)
MOPED: 127.0.0.1:27017 UPDATE database=survey_app_development collection=mongo_surveys selector={"_id"=>"509043ec2c5f64685b62c5b3", "questions._id"=>"509043ec2c5f64685b62c5b7"} update={"$set"=>{"questions.3.response"=>{"_id"=>"509043ec2c5f64685b62c5bf", "data"=>{"0"=>"yes", "1"=>"no", "2"=>"no", "3"=>"no"}, "comment"=>""}}} flags=[] (0.0000ms)
MOPED: 127.0.0.1:27017 UPDATE database=survey_app_development collection=mongo_surveys selector={"_id"=>"509043ec2c5f64685b62c5b3", "questions._id"=>"509043ec2c5f64685b62c5b8"} update={"$set"=>{"questions.4.response"=>{"_id"=>"509043ec2c5f64685b62c5c0", "data"=>{"response"=>"outdoor"}, "comment"=>""}}} flags=[] (0.0000ms)
MOPED: 127.0.0.1:27017 UPDATE database=survey_app_development collection=mongo_surveys selector={"_id"=>"509043ec2c5f64685b62c5b3", "questions._id"=>"509043ec2c5f64685b62c5b9"} update={"$set"=>{"questions.5.response"=>{"_id"=>"509043ec2c5f64685b62c5c1", "data"=>{"response"=>"5"}, "comment"=>nil}}} flags=[] (0.0000ms)
MOPED: 127.0.0.1:27017 UPDATE database=survey_app_development collection=mongo_surveys selector={"_id"=>"509043ec2c5f64685b62c5b3", "questions._id"=>"509043ec2c5f64685b62c5ba"} update={"$set"=>{"questions.6.response"=>{"_id"=>"509043ec2c5f64685b62c5c2", "data"=>{"response"=>"attest"}, "comment"=>nil}}} flags=[] (1.0002ms)
如果我讓腳本執行足夠長的時間(與導軌服務器上運行),任何HTTP請求的結果:
[2012-10-30 16:24:44] ERROR Java heap space
[2012-10-30 16:25:12] ERROR Java heap space
[2012-10-30 16:26:11] ERROR Java heap space
所以,我的問題是:有沒有阻止這種行爲的設置?另外,在寫入MongoDB時,我是否應該期望服務器流量受到阻礙?
我使用Mongoid,的Rails 3.2和的JRuby 1.7.0,的MongoDB 2.2.0
它現在全部是本地的......我在腳本執行時正在做前端開發。不過,我預計10k併發用戶將所有數據寫入MongoDB時都會出現類似的行爲。 – rthbound
你運行的是哪個版本的mongo? (運行'mongo --version') –
v2.2.0(編輯問題反映) – rthbound