cache: replace memcache with redis.

Drop memcache. Use redis for all caching instead.
This commit is contained in:
evazion
2019-08-22 23:15:34 -05:00
parent 2e407fa476
commit dfe2b831a3
8 changed files with 30 additions and 46 deletions

View File

@@ -4,7 +4,6 @@ gem 'dotenv-rails', :require => "dotenv/rails-now"
gem "rails", "~> 5.2"
gem "pg"
gem "dalli", :platforms => :ruby
gem "delayed_job"
gem "delayed_job_active_record"
gem "simple_form"

View File

@@ -118,7 +118,6 @@ GEM
safe_yaml (~> 1.0.0)
crass (1.0.4)
daemons (1.3.1)
dalli (2.7.10)
delayed_job (4.1.7)
activesupport (>= 3.0, < 5.3)
delayed_job_active_record (4.1.3)
@@ -458,7 +457,6 @@ DEPENDENCIES
capistrano3-unicorn
cityhash
daemons
dalli
delayed_job
delayed_job_active_record
diff-lcs

View File

@@ -48,7 +48,7 @@ fi
apt-get update
apt-get -y install apt-transport-https
apt-get -y install zlib1g-dev libglib2.0-dev
apt-get -y install $LIBSSL_DEV_PKG build-essential automake libxml2-dev libxslt-dev ncurses-dev sudo libreadline-dev flex bison ragel memcached libmemcached-dev git curl libcurl4-openssl-dev sendmail-bin sendmail nginx ssh coreutils ffmpeg mkvtoolnix
apt-get -y install $LIBSSL_DEV_PKG build-essential automake libxml2-dev libxslt-dev ncurses-dev sudo libreadline-dev flex bison ragel redis git curl libcurl4-openssl-dev sendmail-bin sendmail nginx ssh coreutils ffmpeg mkvtoolnix
apt-get -y install libpq-dev postgresql-client
apt-get -y install liblcms2-dev $LIBJPEG_TURBO_DEV_PKG libexpat1-dev libgif-dev libpng-dev libexif-dev

View File

@@ -129,11 +129,6 @@ module Danbooru
300
end
# List of memcached servers
def memcached_servers
%w(127.0.0.1:11211)
end
# After a post receives this many comments, new comments will no longer bump the post in comment/index.
def comment_threshold
40
@@ -786,6 +781,7 @@ module Danbooru
end
def redis_url
"redis://localhost:6379"
end
end

View File

@@ -10,11 +10,6 @@ services:
image: redis:latest
ports:
- "6379:6379"
memcached:
image: memcached:alpine
ports:
- "11211:11211"
command: memcached
archives:
image: r888888888/archives
command: sleep 1d
@@ -39,7 +34,6 @@ services:
- RO_DATABASE_URL
- DEBUG
- ARCHIVE_DATABASE_URL
- DANBOORU_MEMCACHED_SERVERS
- DANBOORU_AWS_SQS_ARCHIVE_URL
- DANBOORU_PIXIV_LOGIN
- DANBOORU_PIXIV_PASSWORD
@@ -65,6 +59,5 @@ services:
- "3000:3000"
depends_on:
- db
- memcached
- archives
- redis

View File

@@ -0,0 +1,26 @@
Rails.application.configure do
if Rails.env.test?
cache_config = [:memory_store, { size: 32.megabytes }]
else
cache_config = [
:redis_cache_store,
{
url: Danbooru.config.redis_url,
namespace: nil,
connect_timeout: 30, # default: 20 seconds
write_timeout: 0.2, # default: 1 second
read_timeout: 0.2, # default: 1 second
reconnect_attempts: 0, # default: 0
error_handler: ->(method:, returning:, exception:) {
DanbooruLogger.log(exception, method: method, returning: returning)
}
}
]
end
cache_store = ActiveSupport::Cache.lookup_store(cache_config)
config.cache_store = cache_store
config.action_controller.cache_store = cache_store
Rails.cache = cache_store
end

View File

@@ -1,28 +0,0 @@
Rails.application.configure do
begin
if Rails.env.test?
config.cache_store = :memory_store, { size: 32.megabytes }
config.action_controller.cache_store = :memory_store, { size: 32.megabytes }
Rails.cache = ActiveSupport::Cache.lookup_store(Rails.application.config.cache_store)
else
config.cache_store = :dalli_store, Danbooru.config.memcached_servers, { namespace: Danbooru.config.safe_app_name }
config.action_controller.cache_store = :dalli_store, Danbooru.config.memcached_servers, { namespace: Danbooru.config.safe_app_name }
Rails.cache = ActiveSupport::Cache.lookup_store(Rails.application.config.cache_store)
Rails.cache.dalli.alive!
end
rescue Dalli::RingError => e
puts "-" * 40
puts "WARNING! MEMCACHE SERVER NOT FOUND! You will experience performance degradation."
puts e.to_s
puts "-- BEGIN STACKTRACE --"
e.backtrace.each do |line|
puts line
end
puts "-- END STACKTRACE --"
puts "-" * 40
config.cache_store = :memory_store, { size: 32.megabytes }
Rails.cache = ActiveSupport::Cache.lookup_store(Rails.application.config.cache_store)
end
end

View File

@@ -27,7 +27,7 @@ read VLAN_IP_ADDR
echo "* Installing packages..."
apt-get update
apt-get -y install libssl-dev build-essential automake libxml2-dev libxslt-dev ncurses-dev sudo libreadline-dev flex bison ragel memcached libmemcached-dev git curl libcurl4-openssl-dev sendmail-bin sendmail nginx ssh coreutils ffmpeg mkvtoolnix
apt-get -y install libssl-dev build-essential automake libxml2-dev libxslt-dev ncurses-dev sudo libreadline-dev flex bison ragel redis git curl libcurl4-openssl-dev sendmail-bin sendmail nginx ssh coreutils ffmpeg mkvtoolnix
apt-get -y install libpq-dev postgresql-client
apt-get -y install liblcms2-dev libjpeg-turbo8-dev libexpat1-dev libgif-dev libpng-dev libexif-dev