我发誓在一个小时之内,mongo的查询从每行0.3毫秒变为每行100毫秒以上。在那段时间里,我将零数据添加到了mongo中,并且我没有更改数据库,gem文件或rails控制器 - 只是更改视图中的一些CSS。没有什么会谈到数据库。Mongo Mapper&Rails - 突然查询时间超过100毫秒
下面是一些例子输出:
MONGODB (121.1ms) creative_development['admins'].find({:_id=>BSON::ObjectId('518b762e89651a0389000013')}).limit(-1)
MONGODB (121.6ms) creative_development['$cmd'].find({"count"=>"customers", "query"=>{:merchant_id=>"518b762e89651a0389000013"}, "fields"=>nil}).limit(-1)
MONGODB (249.7ms) creative_development['customers'].find({:merchant_id=>"518b762e89651a0389000013"}).limit(40).sort([["first_name", "asc"]])
MONGODB (244.8ms) creative_development['customers'].find({:merchant_id=>"518b762e89651a0389000013"}).limit(40).sort([["first_name", "asc"]])
Rendered shared/_header.html.erb (0.2ms)
MONGODB (121.5ms) creative_development['companies'].find({:_id=>"0"}).limit(-1)
MONGODB (131.2ms) creative_development['jobs'].find({:customer_id=>BSON::ObjectId('51b7890a9727912430000022')})
MONGODB (122.1ms) creative_development['jobs'].find({:customer_id=>BSON::ObjectId('51b7890a9727912430000022')})
MONGODB (120.9ms) creative_development['companies'].find({:_id=>"0"}).limit(-1)
下面是它看起来像以前一样:
MONGODB (0.4ms) creative_development['customers'].find({:_id=>BSON::ObjectId('51ddf5969727913cf8000424')}).limit(-1)
MONGODB (0.4ms) creative_development['admins'].find({:_id=>BSON::ObjectId('51ddbd6b972791243d0000f1')}).limit(-1)
MONGODB (0.4ms) creative_development['jobtypes'].find({:_id=>BSON::ObjectId('51ddcff69727912dfe000001')}).limit(-1)
MONGODB (0.4ms) creative_development['jobpriorities'].find({:_id=>BSON::ObjectId('51a7d01289651a3b100000e5')}).limit(-1)
MONGODB (0.4ms) creative_development['customers'].find({:_id=>BSON::ObjectId('51e4a6c797279171bc000004')}).limit(-1)
MONGODB (0.5ms) creative_development['admins'].find({:_id=>BSON::ObjectId('51ddbd6b972791243d0000f1')}).limit(-1)
MONGODB (0.4ms) creative_development['jobtypes'].find({:_id=>BSON::ObjectId('519bff2e89651a32af000001')}).limit(-1)
MONGODB (0.4ms) creative_development['jobpriorities'].find({:_id=>BSON::ObjectId('51b782db972791212c0000e6')}).limit(-1)
MONGODB (0.4ms) creative_development['customers'].find({:_id=>BSON::ObjectId('51e7448997279123e6000001')}).limit(-1)
MONGODB (0.3ms) creative_development['admins'].find({:_id=>BSON::ObjectId('51ddbd6b972791243d0000f1')}).limit(-1)
MONGODB (0.3ms) creative_development['jobtypes'].find({:_id=>BSON::ObjectId('519bff1389651a32d800002b')}).limit(-1)
查询:
@all_customers = Customer.where(:merchant_id => session[:admin_id].to_s)
respond_to do |format|
format.html do # index.html.erb
@all_customers = @all_customers.sort([sort_column,sort_direction]).paginate(:per_page => 40, :page => params[:page])
end
的分类部分:
def sort_column
Customer.column_names.include?(params[:sort]) ? params[:sort] : "first_name"
end
def sort_direction
%w[asc desc].include?(params[:direction]) ? params[:direction] : "asc"
end
这里是在Heroku在同一个页面,相同的登录,相同的DB数据:
2013-07-28T03:59:31.829330+00:00 app[web.1]: Processing by CustomersController#index as HTML
2013-07-28T03:59:31.832789+00:00 app[web.1]: MONGODB (2.7ms) live-heroku['admins'].find({:_id=>BSON::ObjectId('51b0388697279164a4000001')}).limit(-1)
2013-07-28T03:59:31.839820+00:00 app[web.1]: MONGODB (4.5ms) live-heroku['$cmd'].find({"count"=>"customers", "query"=>{:merchant_id=>"518b762e89651a0389000013"}, "fields"=>nil}).limit(-1)
2013-07-28T03:59:31.896128+00:00 app[web.1]: MONGODB (55.7ms) live-heroku['customers'].find({:merchant_id=>"518b762e89651a0389000013"}).limit(40).sort([["first_name", "asc"]])
2013-07-28T03:59:31.951921+00:00 app[web.1]: MONGODB (13.8ms) live-heroku['customers'].find({:merchant_id=>"518b762e89651a0389000013"}).limit(40).sort([["first_name", "asc"]])
2013-07-28T03:59:32.126152+00:00 app[web.1]: MONGODB (7.7ms) live-heroku['admins'].find({:_id=>BSON::ObjectId('518b762e89651a0389000013')}).limit(-1)
2013-07-28T03:59:32.127529+00:00 app[web.1]: Rendered shared/_header.html.erb (9.7ms)
2013-07-28T03:59:32.146588+00:00 app[web.1]: MONGODB (14.2ms) live-heroku['companies'].find({:_id=>"0"}).limit(-1)
2013-07-28T03:59:32.151084+00:00 app[web.1]: MONGODB (2.4ms) live-heroku['jobs'].find({:customer_id=>BSON::ObjectId('51b7890a9727912430000022')})
2013-07-28T03:59:32.191671+00:00 app[web.1]: MONGODB (2.4ms) live-heroku['jobs'].find({:customer_id=>BSON::ObjectId('51b7890a9727912430000022')})
2013-07-28T03:59:32.233914+00:00 app[web.1]: MONGODB (9.8ms) live-heroku['companies'].find({:_id=>"0"}).limit(-1)
2013-07-28T03:59:32.238298+00:00 app[web.1]: MONGODB (2.2ms) live-heroku['jobs'].find({:customer_id=>BSON::ObjectId('51b78a4e97279123fd000255')})
的Heroku是从蒙戈实验室实例拉动。
我的本地环境(S):
的MacBook今年航空(Haswell的CPU,酷睿i5)和一台Mac Mini大约2012
在这两种环境中 - 蒙戈性能为0.2〜0.5毫秒本地。然后,突然间,真的没有数据库更改,没有宝石升级,Rails应用程序没有控制器或模型更改,他们只是吓坏了。
有一件事我可以想象 - 我在过去的几天内对他们两人进行了酿造更新。然而 - 无论在哪种情况下,冲泡更新后性能都不会立即下降。我并没有在脑中“时间戳”它,但是在冲泡更新和放慢速度之间存在巨大的时间间隔(小时)。在空气的情况下,这是几天。 Mac Mini我记不清楚了。
有没有人有任何关于为什么Mongo会突然就像这样吓坏了?
您是否尝试过使用'.explain()'在您的查询从控制台查看发生了什么? –