diff options
author | bogdanvlviv <bogdanvlviv@gmail.com> | 2018-12-04 23:24:23 +0200 |
---|---|---|
committer | bogdanvlviv <bogdanvlviv@gmail.com> | 2019-02-08 13:27:30 +0000 |
commit | dda9452314bb904a3e2c850bd23f118eb80e3356 (patch) | |
tree | 707c1e6908f12057f7059780828b4e681a440ee8 /activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb | |
parent | b67d5c6dedbf033515a96a95d24d085bf99a0d07 (diff) | |
download | rails-dda9452314bb904a3e2c850bd23f118eb80e3356.tar.gz rails-dda9452314bb904a3e2c850bd23f118eb80e3356.tar.bz2 rails-dda9452314bb904a3e2c850bd23f118eb80e3356.zip |
Fix elapsed time calculations
I've found a few places in Rails code base where I think it makes sense
to calculate elapsed time more precisely by using
`Concurrent.monotonic_time`:
- Fix calculation of elapsed time in `ActiveSupport::Cache::MemoryStore#prune`
- Fix calculation of elapsed time in
`ActiveRecord::ConnectionAdapters::ConnectionPool::Queue#wait_poll`
- Fix calculation of elapsed time in
`ActiveRecord::ConnectionAdapters::ConnectionPool#attempt_to_checkout_all_existing_connections`
- Fix calculation of elapsed time in `ActiveRecord::ConnectionAdapters::Mysql2Adapter#explain`
See
https://docs.ruby-lang.org/en/2.5.0/Process.html#method-c-clock_gettime
https://blog.dnsimple.com/2018/03/elapsed-time-with-ruby-the-right-way
Related to 7c4542146f0dde962205e5a90839349631ae60fb
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb index 7b69a63f6e..569c146f92 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb @@ -166,9 +166,9 @@ module ActiveRecord def explain(arel, binds = []) sql = "EXPLAIN #{to_sql(arel, binds)}" - start = Time.now + start = Concurrent.monotonic_time result = exec_query(sql, "EXPLAIN", binds) - elapsed = Time.now - start + elapsed = Concurrent.monotonic_time - start MySQL::ExplainPrettyPrinter.new.pp(result, elapsed) end |