Skip to content
Merged
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,7 @@ cookbooks

# Vite
/vite.config.mts.timestamp-*.mjs

# Autoscaling simulation output
/scaling-graph.csv
/scaling-graph.png
21 changes: 5 additions & 16 deletions app/services/autoscale_servers_service.rb
Original file line number Diff line number Diff line change
@@ -1,27 +1,16 @@
# Script to generate graph:
# require "csv"
# Time.zone = "America/New_York"
# time = Time.local(2022, 10, 31)
# data = []
# while time < Time.local(2022, 11, 4)
# data << [time, AutoscaleServersService.scaling_target_for(time)]
# time += 15.minutes
# end
# CSV.open("scaling-graph.csv", "w") do |csv|
# csv << %w[Time Servers]
# data.each { |row| csv << row }
# end
# To simulate the effect of autoscaling as a CSV file:
# bin/rails runner script/generate_simulated_autoscaling_graph.rb

class AutoscaleServersService < CivilService::Service
USERS_PER_INSTANCE = ENV.fetch("AUTOSCALE_USERS_PER_INSTANCE", "40").to_i
MIN_INSTANCES = ENV.fetch("AUTOSCALE_MIN_INSTANCES", "1").to_i
MIN_INSTANCES = ENV.fetch("AUTOSCALE_MIN_INSTANCES", "2").to_i
MIN_INSTANCES_FOR_SIGNUP_OPENING = ENV.fetch("AUTOSCALE_MIN_INSTANCES_FOR_SIGNUP_OPENING", "2").to_i
MAX_INSTANCES = ENV.fetch("AUTOSCALE_MAX_INSTANCES", "8").to_i
MAX_INSTANCES = ENV.fetch("AUTOSCALE_MAX_INSTANCES", "10").to_i
SIGNUP_OPENING_LOOKAHEAD_TIME = ENV.fetch("AUTOSCALE_SIGNUP_OPENING_LOOKAHEAD_HOURS", "48").to_i.hours
SIGNUP_OPENING_RAMP_UP_LOOKAHEAD_TIME = ENV.fetch("AUTOSCALE_SIGNUP_OPENING_RAMP_UP_LOOKAHEAD_HOURS", "2").to_i.hours
SIGNUP_OPENING_FULL_THROTTLE_LOOKAHEAD_TIME =
ENV.fetch("AUTOSCALE_SIGNUP_OPENING_FULL_THROTTLE_LOOKAHEAD_HOURS", "1").to_i.hours
SIGNUP_OPENING_DECAY_TIME = ENV.fetch("AUTOSCALE_SIGNUP_OPENING_DECAY_TIME", "1").to_i.hours
SIGNUP_OPENING_DECAY_TIME = ENV.fetch("AUTOSCALE_SIGNUP_OPENING_DECAY_TIME", "6").to_i.hours
SIGNUP_OPENING_LOOKBACK_TIME = ENV.fetch("AUTOSCALE_SIGNUP_OPENING_LOOKBACK_TIME", "6").to_i.hours

def self.scaling_target_for_signup_opening(convention)
Expand Down
13 changes: 13 additions & 0 deletions script/generate_simulated_autoscaling_graph.gnuplot
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
set terminal png size 1200,600
set output 'scaling-graph.png'
set datafile separator ','
set xdata time
set timefmt '%Y-%m-%d %H:%M:%S'
set format x '%I:%M%p'
set xlabel 'Time'
set ylabel 'Servers'
set title 'Autoscaling Servers'
set autoscale yfix
set yrange [0:*]
set offsets 0,0,graph 0.1,0
plot 'scaling-graph.csv' skip 1 using 1:2 with lines notitle
23 changes: 23 additions & 0 deletions script/generate_simulated_autoscaling_graph.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require "csv"

Time.use_zone "America/New_York" do
time = Time.zone.local(2025, 11, 24, 12)
data = []
while time < Time.zone.local(2025, 11, 25, 12)
data << [time, AutoscaleServersService.scaling_target_for(time)]
time += 15.minutes
end

puts "Writing simulated autoscaling data to scaling-graph.csv"

CSV.open("scaling-graph.csv", "w") do |csv|
csv << %w[Time Servers]
data.each { |row| csv << row }
end

puts "Plotting graph to scaling-graph.png"

system <<~SH
gnuplot -c ./script/generate_simulated_autoscaling_graph.gnuplot
SH
end
Loading