-
Type: Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
-
Labels:None
Mongoid 3.1.6
Rails 3.2.21
MongoDB 2.4.9
We're seeing strange performance issues with find() vs where().first:
$ rails c 2.1.5 :001 > Benchmark.ms { User.find('5091e4beccbce30200000006') } => 7.95 2.1.5 :002 > Benchmark.ms { User.find('5091e4beccbce30200000006') } => 0.27599999999999997 2.1.5 :003 > Benchmark.ms { User.find('5091e4beccbce30200000006') } => 0.215 2.1.5 :004 > exit
$ rails c 2.1.5 :001 > Benchmark.ms { User.where(id: '5091e4beccbce30200000006').first } => 7.779999999999999 2.1.5 :002 > Benchmark.ms { User.where(id: '5091e4beccbce30200000006').first } => 4.84 2.1.5 :003 > Benchmark.ms { User.where(id: '5091e4beccbce30200000006').first } => 5.297 2.1.5 :004 > exit
These both appear to be firing off the same queries. Can someone explain why we're seeing such a huge difference in performance?
Configuration:
production: sessions: default: uri: <%= REDACTED %> options: consistency: :strong safe: true max_retries: 1 retry_interval: 0 options: identity_map_enabled: true
Also asked this question on StackOverflow: http://stackoverflow.com/questions/29784093/strange-performance-issues-with-where-vs-find