Skip to content

Commit 126e771

Browse files
committed
Benchmark with cache that supports read-multi
bin/bench -r 5 Benchmark results: { "commit_hash": "617c8a7", "version": "0.10.0", "rails_version": "4.2.6", "benchmark_run[environment]": "2.2.3p173", "runs": [ { "benchmark_type[category]": "caching on: caching serializers: gc off", "benchmark_run[result][iterations_per_second]": 669.362, "benchmark_run[result][total_allocated_objects_per_iteration]": 1341 }, { "benchmark_type[category]": "caching on: fragment caching serializers: gc off", "benchmark_run[result][iterations_per_second]": 628.208, "benchmark_run[result][total_allocated_objects_per_iteration]": 1433 }, { "benchmark_type[category]": "caching on: non-caching serializers: gc off", "benchmark_run[result][iterations_per_second]": 1008.955, "benchmark_run[result][total_allocated_objects_per_iteration]": 1230 }, { "benchmark_type[category]": "caching off: caching serializers: gc off", "benchmark_run[result][iterations_per_second]": 605.704, "benchmark_run[result][total_allocated_objects_per_iteration]": 1341 }, { "benchmark_type[category]": "caching off: fragment caching serializers: gc off", "benchmark_run[result][iterations_per_second]": 560.369, "benchmark_run[result][total_allocated_objects_per_iteration]": 1433 }, { "benchmark_type[category]": "caching off: non-caching serializers: gc off", "benchmark_run[result][iterations_per_second]": 868.604, "benchmark_run[result][total_allocated_objects_per_iteration]": 1230 } ] }
1 parent b9e7dc5 commit 126e771

File tree

4 files changed

+23
-5
lines changed

4 files changed

+23
-5
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ rvm:
1313
jdk:
1414
- oraclejdk8
1515

16-
install: bundle install --path=vendor/bundle --retry=3 --jobs=3
16+
install: bundle install --path=vendor/bundle --retry=3 --jobs=3 --without bench
1717
cache:
1818
directories:
1919
- vendor/bundle

Gemfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ gem 'tzinfo-data', platforms: (@windows_platforms + [:jruby])
3939
group :bench do
4040
# https://github.com/rails-api/active_model_serializers/commit/cb4459580a6f4f37f629bf3185a5224c8624ca76
4141
gem 'benchmark-ips', require: false, group: :development
42+
gem 'oj'
43+
gem 'oj_mimic_json'
44+
gem 'redis', require: false
45+
gem 'readthis', require: false
46+
gem 'hiredis', require: false
4247
end
4348

4449
group :test do

test/benchmark/app.rb

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,20 @@ class BenchmarkApp < Rails::Application
3636
config.cache_classes = true
3737
# CONFIG: CACHE_ON={on,off}
3838
config.action_controller.perform_caching = ENV['CACHE_ON'] != 'off'
39-
config.action_controller.cache_store = ActiveSupport::Cache.lookup_store(:memory_store)
39+
# config.action_controller.cache_store = ActiveSupport::Cache.lookup_store(:memory_store)
40+
require 'redis'
41+
require 'readthis'
42+
require 'oj'
43+
Readthis.serializers << ::Oj
44+
45+
ENV['REDIS_URL'] = 'redis://localhost:6379/5'
46+
config.action_controller.cache_store = :readthis_store, {
47+
expires_in: 2.weeks.to_i,
48+
marshal: ::Oj,
49+
namespace: 'cache',
50+
redis: { url: ENV.fetch('REDIS_URL'), driver: :hiredis }
51+
}
52+
4053

4154
config.active_support.test_order = :random
4255
config.secret_token = 'S' * 30

test/benchmark/fixtures.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ class CachingHasOneRelationshipSerializer < HasOneRelationshipSerializer
4848
Rails.configuration.serializers << CachingHasOneRelationshipSerializer
4949

5050
class CachingHasManyRelationshipSerializer < HasManyRelationshipSerializer
51-
cache expires_in: 1.day, skip_digest: true
51+
cache expires_in: 1.day.to_i, skip_digest: true
5252
end
5353
Rails.configuration.serializers << CachingHasManyRelationshipSerializer
5454

5555
# see https://github.com/rails-api/active_model_serializers/pull/1690/commits/68715b8f99bc29677e8a47bb3f305f23c077024b#r60344532
5656
class CachingPrimaryResourceSerializer < ActiveModel::Serializer
57-
cache key: 'primary_resource', expires_in: 0.1, skip_digest: true
57+
cache key: 'primary_resource', expires_in: 1.day.to_i, skip_digest: true
5858

5959
attributes :id, :title, :body
6060

@@ -89,7 +89,7 @@ class FragmentCachingHasManyRelationshipSerializer < HasManyRelationshipSerializ
8989

9090
# see https://github.com/rails-api/active_model_serializers/pull/1690/commits/68715b8f99bc29677e8a47bb3f305f23c077024b#r60344532
9191
class FragmentCachingPrimaryResourceSerializer < ActiveModel::Serializer
92-
cache key: 'primary_resource', expires_in: 0.1, skip_digest: true
92+
cache key: 'primary_resource', expires_in: 1.day.to_i, skip_digest: true
9393

9494
attributes :id, :title, :body
9595

0 commit comments

Comments
 (0)