Skip to content

Commit a0c63a9

Browse files
committed
Split the autoscale simulation script out to a separate file
1 parent b65c358 commit a0c63a9

File tree

4 files changed

+42
-13
lines changed

4 files changed

+42
-13
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: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,5 @@
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
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)