我发誓,mongo 中的查询在一小时内从每行 0.3 毫秒增加到每行 > 100 毫秒。我在那段时间内向 mongo 添加了零数据,并且我没有对数据库、gem 文件或 rails 控制器进行任何更改 - 只是更改了视图中的一些 CSS。没有任何与数据库对话的东西。
这是一些示例输出:
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 上相同的页面、相同的登录名、相同的数据库数据:
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 正在从 Mongo Lab 实例中提取。
我的本地环境:
今年的 MacBook Air(Haswell CPU,i5)和大约 2012 年的 Mac Mini。
在这两种环境中 - Mongo 的性能在本地都是 0.2 ~ 0.5 ms。然后突然之间,在 Rails 应用程序中没有数据库更改,没有 gem 升级,没有控制器或模型更改,他们只是吓坏了。
我可以想象一件事 - 在过去的几天里,我对它们都进行了 brew 更新。但是 - 无论哪种情况,在 brew 更新后性能都没有立即下降。我没有在我的大脑中“加盖”它,但是在 brew 更新和减速之间有很大的间隔(小时)。在 Air 的情况下,它是几天。Mac Mini 我记不太清了。
有没有人知道为什么 Mongo 会突然像这样发疯?