Solid Cache and Queue as default backends and more | This Week in Rails
https://world.hey.com/this.week.in.rails/solid-cache-and-queue-as-default-backends-and-more-5619d94c
Add Solid Cache (and get ready for Solid Queue) by dhh · Pull Request #52790 · rails/rails · GitHub
railtilesに関する変更です
solid_cache gemがRails 8系のデフォルトに追加されました
--skip-solid オプションを指定するとスキップすることができます
https://github.com/rails/solid_cache を見てみましょう
概要はこちらですね
Solid Cache is a database-backed Active Support cache store that let's you keep a much larger cache than is typically possible with traditional memory-only Redis or Memcached stores. This is thanks to the speed of modern SSD drives, which make the access-time penalty of using disk vs RAM insignificant for most caching purposes. Simply put, you're now usually better off keeping a huge cache on disk rather than a small cache in memory.
Solid Cache は、データベースでバックアップされた Active Support キャッシュ ストアで、従来のメモリのみの Redis または Memcached ストアで通常可能なものよりもはるかに大きなキャッシュを保持できます。これは、最新の SSD ドライブの速度のおかげで、ほとんどのキャッシュ目的では、ディスクと RAM の使用によるアクセス時間のペナルティは重要ではありません。簡単に言えば、メモリ内の小さなキャッシュよりも、ディスク上に巨大なキャッシュを保持する方が通常は効果的です。
config/database.yml と config/solid_cache.yml を設定すれば使えるようです
code:config/database.yml
production:
primary: &primary_production
<<: *default
database: app_production
username: app
password: <%= ENV"APP_DATABASE_PASSWORD" %>
cache:
<<: *primary_production
database: app_production_cache
migrations_paths: db/cache_migrate
code:config/solid_cache.yml
default:
store_options: &default_store_options
max_age: <%= 60.days.to_i %>
namespace: <%= Rails.env %>
size_estimate_samples: 1000
development: &development
database: development_cache
store_options:
<<: *default_store_options
max_size: <%= 256.gigabytes %>
production: &production
databases: production_cache1, production_cache2
store_options:
<<: *default_store_options
max_entries: <%= 256.gigabytes %>
このほかにもDBコネクションに関する設定などがありますが、詳しくはリポジトリのREADMEを参照してください
Add Solid Queue alongside Solid Cache by dhh · Pull Request #52804 · rails/rails · GitHub
railtilesに関する変更です
solid_queue gemがRails 8系のデフォルトに追加されました
Solid Queueについては過去の回でも紹介しています
Rails guides facelift, two new official gems and more! | This Week in Rails#65ff8bd24492e80000c29963
https://github.com/rails/solid_queue
SolidQueue解体新書 - メドピア開発者ブログにて詳しく解説されているのでそちらもぜひご参照ください
SolidQueueは以下の3種類の「アクター」により構成されています。
- Dispatcher: Jobの実行タイミング管理や同時実行可能数制限などを担当
- Worker: 実行待ちJobをポーリング的に取得し処理を実行する
- Supervisor: 設定内容に基づき上記2つを起動させ稼働状況の監視をする
このようにそれぞれの役割が明確に分かれているため、「比較的処理が軽量なDispatcherは1つだけ立ち上げ、Workerは複数立ち上げる」のような調整が柔軟にできるようになっています。