Skip to content

WIP: Benchmark with cache that supports read-multi #1786

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 13 additions & 1 deletion test/benchmark/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions test/benchmark/fixtures.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down