Skip to content

Instantly share code, notes, and snippets.

@MakarovCode
MakarovCode / application_controller.rb
Last active March 14, 2025 09:22
Heroku dynos autoscaler with redis and sidekiq
# app/controllers/application_controller.rb
# Base controller for a Rails app integrated with Heroku Autoscaler.
# Tracks web response times and stores them in Redis for autoscaling decisions.
# Usage: Works with Heroku::Autoscaler to scale the 'web' dyno based on average response time.
# Requirements: 'redis' gem, REDIS_URL env variable set (e.g., via Heroku Redis add-on).
require 'json'
class ApplicationController < ActionController::Base
# Hook to measure response time for every action in the app