From 39307661aa350027ef52579f75785db986a5f029 Mon Sep 17 00:00:00 2001 From: Benjamin Fleischer Date: Tue, 31 May 2016 00:24:24 -0500 Subject: [PATCH] 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 } ] } --- .travis.yml | 2 +- Gemfile | 5 +++++ test/benchmark/app.rb | 14 +++++++++++++- test/benchmark/fixtures.rb | 6 +++--- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8cb26c8e6..6031591f2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,7 +13,7 @@ rvm: jdk: - oraclejdk8 -install: bundle install --path=vendor/bundle --retry=3 --jobs=3 +install: bundle install --path=vendor/bundle --retry=3 --jobs=3 --without bench cache: directories: - vendor/bundle diff --git a/Gemfile b/Gemfile index 35557ef05..cbadf9380 100644 --- a/Gemfile +++ b/Gemfile @@ -39,6 +39,11 @@ gem 'tzinfo-data', platforms: (@windows_platforms + [:jruby]) group :bench do # https://github.com/rails-api/active_model_serializers/commit/cb4459580a6f4f37f629bf3185a5224c8624ca76 gem 'benchmark-ips', require: false, group: :development + gem 'oj' + gem 'oj_mimic_json' + gem 'redis', require: false + gem 'readthis', require: false + gem 'hiredis', require: false end group :test do diff --git a/test/benchmark/app.rb b/test/benchmark/app.rb index bc0d3689a..bae3e2982 100644 --- a/test/benchmark/app.rb +++ b/test/benchmark/app.rb @@ -36,7 +36,19 @@ class BenchmarkApp < Rails::Application config.cache_classes = true # CONFIG: CACHE_ON={on,off} config.action_controller.perform_caching = ENV['CACHE_ON'] != 'off' - config.action_controller.cache_store = ActiveSupport::Cache.lookup_store(:memory_store) + # config.action_controller.cache_store = ActiveSupport::Cache.lookup_store(:memory_store) + require 'redis' + require 'readthis' + require 'oj' + Readthis.serializers << ::Oj + + ENV['REDIS_URL'] = 'redis://localhost:6379/5' + config.action_controller.cache_store = :readthis_store, { + expires_in: 2.weeks.to_i, + marshal: ::Oj, + namespace: 'cache', + redis: { url: ENV.fetch('REDIS_URL'), driver: :hiredis } + } config.active_support.test_order = :random config.secret_token = 'S' * 30 diff --git a/test/benchmark/fixtures.rb b/test/benchmark/fixtures.rb index c91e102d4..8bf11b511 100644 --- a/test/benchmark/fixtures.rb +++ b/test/benchmark/fixtures.rb @@ -48,13 +48,13 @@ class CachingHasOneRelationshipSerializer < HasOneRelationshipSerializer Rails.configuration.serializers << CachingHasOneRelationshipSerializer class CachingHasManyRelationshipSerializer < HasManyRelationshipSerializer - cache expires_in: 1.day, skip_digest: true + cache expires_in: 1.day.to_i, skip_digest: true end Rails.configuration.serializers << CachingHasManyRelationshipSerializer # see https://github.com/rails-api/active_model_serializers/pull/1690/commits/68715b8f99bc29677e8a47bb3f305f23c077024b#r60344532 class CachingPrimaryResourceSerializer < ActiveModel::Serializer - cache key: 'primary_resource', expires_in: 0.1, skip_digest: true + cache key: 'primary_resource', expires_in: 1.day.to_i, skip_digest: true attributes :id, :title, :body @@ -89,7 +89,7 @@ class FragmentCachingHasManyRelationshipSerializer < HasManyRelationshipSerializ # see https://github.com/rails-api/active_model_serializers/pull/1690/commits/68715b8f99bc29677e8a47bb3f305f23c077024b#r60344532 class FragmentCachingPrimaryResourceSerializer < ActiveModel::Serializer - cache key: 'primary_resource', expires_in: 0.1, skip_digest: true + cache key: 'primary_resource', expires_in: 1.day.to_i, skip_digest: true attributes :id, :title, :body