Skip to content

Low perfomance of local_cache's read_entry and write_entry #42611

@hoangtuyb96

Description

@hoangtuyb96

Steps to reproduce

Here's script to reproduce the low performance.
https://gist.github.com/hoangtuyb96/5e9a16969ccac2e416a88e0c17cc8e5d

Procedure:

  • Save it ( i.e as cache.rb )
  • Change the database's information
  • Run it
    • To benchmark in specific rails version: run cache.rb path_of_cache specific_rails_version

Related PR in rails 6.1.0:

Expected behavior

The performance in rails 6.0.x and 6.1.0 should be equal.

Actual behavior

When i ran above script, i got this result.

In rails 6.0.x

== Benchmarking read_entry code and write_entry code in rails 6.0.4
Warming up --------------------------------------
fetch in rails 6.0.4    12.563k i/100ms
write in rails 6.0.4     8.000  i/100ms
Calculating -------------------------------------
fetch in rails 6.0.4    123.118k (± 4.6%) i/s -    615.587k in   5.011083s
write in rails 6.0.4     84.463  (± 3.6%) i/s -    424.000  in   5.028694s

In rails 6.1.0

== Benchmarking read_entry code and write_entry code in rails 6.1.0
Warming up --------------------------------------
fetch in rails 6.1.0    33.000  i/100ms
write in rails 6.1.0     4.000  i/100ms
Calculating -------------------------------------
fetch in rails 6.1.0    322.163  (± 8.1%) i/s -      1.617k in   5.057517s
write in rails 6.1.0     43.771  (± 9.1%) i/s -    220.000  in   5.086859s

I saw a serious speed degradation.

System configuration

Ruby version: 2.7.2

Rails version: 6.0.x and 6.1.0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions