rails/rails — Issue #3558: Rails.cache.read_multi really slow
Author: joevandyk
Created: 2011-11-08 01:13:57+00:00
State: open

James Golick reported this on twitter:

irb(main):061:0> puts Benchmark.measure { $memcached.get(keys) }
0.000000 0.000000 0.000000 ( 0.001995)
=> nil
irb(main):062:0> puts Benchmark.measure { Rails.cache.read_multi(*keys) }
0.010000 0.010000 0.020000 ( 0.044255)
=> nil
irb(main):063:0> puts Benchmark.measure { Rails.cache.read_multi(*keys) }
0.000000 0.000000 0.000000 ( 0.043445)
=> nil
irb(main):064:0> puts Benchmark.measure { $memcached.get(keys) }
0.000000 0.000000 0.000000 ( 0.001753)
=> nil
irb(main):065:0> puts Benchmark.measure { Rails.cache.read_multi(*keys) }
0.010000 0.000000 0.010000 ( 0.066122)

Huge performance penalty for using Rails.cache.read_multi. This might be because read_multi converts everything to an ActiveSupport::Cache::Entry object and checks to see if each returned value is expired?