Skip to content

Commit 03f0128

Browse files
authored
Merge pull request #11131 from neinteractiveliterature/adjust-scaling-plan
Adjust scaling plan
2 parents 1262efc + 6f9648d commit 03f0128

File tree

4 files changed

+45
-16
lines changed

4 files changed

+45
-16
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,7 @@ cookbooks
103103

104104
# Vite
105105
/vite.config.mts.timestamp-*.mjs
106+
107+
# Autoscaling simulation output
108+
/scaling-graph.csv
109+
/scaling-graph.png

app/services/autoscale_servers_service.rb

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,16 @@
1-
# Script to generate graph:
2-
# require "csv"
3-
# Time.zone = "America/New_York"
4-
# time = Time.local(2022, 10, 31)
5-
# data = []
6-
# while time < Time.local(2022, 11, 4)
7-
# data << [time, AutoscaleServersService.scaling_target_for(time)]
8-
# time += 15.minutes
9-
# end
10-
# CSV.open("scaling-graph.csv", "w") do |csv|
11-
# csv << %w[Time Servers]
12-
# data.each { |row| csv << row }
13-
# end
1+
# To simulate the effect of autoscaling as a CSV file:
2+
# bin/rails runner script/generate_simulated_autoscaling_graph.rb
143

154
class AutoscaleServersService < CivilService::Service
165
USERS_PER_INSTANCE = ENV.fetch("AUTOSCALE_USERS_PER_INSTANCE", "40").to_i
17-
MIN_INSTANCES = ENV.fetch("AUTOSCALE_MIN_INSTANCES", "1").to_i
6+
MIN_INSTANCES = ENV.fetch("AUTOSCALE_MIN_INSTANCES", "2").to_i
187
MIN_INSTANCES_FOR_SIGNUP_OPENING = ENV.fetch("AUTOSCALE_MIN_INSTANCES_FOR_SIGNUP_OPENING", "2").to_i
19-
MAX_INSTANCES = ENV.fetch("AUTOSCALE_MAX_INSTANCES", "8").to_i
8+
MAX_INSTANCES = ENV.fetch("AUTOSCALE_MAX_INSTANCES", "10").to_i
209
SIGNUP_OPENING_LOOKAHEAD_TIME = ENV.fetch("AUTOSCALE_SIGNUP_OPENING_LOOKAHEAD_HOURS", "48").to_i.hours
2110
SIGNUP_OPENING_RAMP_UP_LOOKAHEAD_TIME = ENV.fetch("AUTOSCALE_SIGNUP_OPENING_RAMP_UP_LOOKAHEAD_HOURS", "2").to_i.hours
2211
SIGNUP_OPENING_FULL_THROTTLE_LOOKAHEAD_TIME =
2312
ENV.fetch("AUTOSCALE_SIGNUP_OPENING_FULL_THROTTLE_LOOKAHEAD_HOURS", "1").to_i.hours
24-
SIGNUP_OPENING_DECAY_TIME = ENV.fetch("AUTOSCALE_SIGNUP_OPENING_DECAY_TIME", "1").to_i.hours
13+
SIGNUP_OPENING_DECAY_TIME = ENV.fetch("AUTOSCALE_SIGNUP_OPENING_DECAY_TIME", "6").to_i.hours
2514
SIGNUP_OPENING_LOOKBACK_TIME = ENV.fetch("AUTOSCALE_SIGNUP_OPENING_LOOKBACK_TIME", "6").to_i.hours
2615

2716
def self.scaling_target_for_signup_opening(convention)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
set terminal png size 1200,600
2+
set output 'scaling-graph.png'
3+
set datafile separator ','
4+
set xdata time
5+
set timefmt '%Y-%m-%d %H:%M:%S'
6+
set format x '%I:%M%p'
7+
set xlabel 'Time'
8+
set ylabel 'Servers'
9+
set title 'Autoscaling Servers'
10+
set autoscale yfix
11+
set yrange [0:*]
12+
set offsets 0,0,graph 0.1,0
13+
plot 'scaling-graph.csv' skip 1 using 1:2 with lines notitle
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
require "csv"
2+
3+
Time.use_zone "America/New_York" do
4+
time = Time.zone.local(2025, 11, 24, 12)
5+
data = []
6+
while time < Time.zone.local(2025, 11, 25, 12)
7+
data << [time, AutoscaleServersService.scaling_target_for(time)]
8+
time += 15.minutes
9+
end
10+
11+
puts "Writing simulated autoscaling data to scaling-graph.csv"
12+
13+
CSV.open("scaling-graph.csv", "w") do |csv|
14+
csv << %w[Time Servers]
15+
data.each { |row| csv << row }
16+
end
17+
18+
puts "Plotting graph to scaling-graph.png"
19+
20+
system <<~SH
21+
gnuplot -c ./script/generate_simulated_autoscaling_graph.gnuplot
22+
SH
23+
end

0 commit comments

Comments
 (0)