DEV: Drop puma from `script/bench.rb`, default to Unicorn (#26898)

This commit updates `script/bench.rb` to only support Unicorn as the web
server. We don't intend to run Puma in production anytime soon so it is
pointless for us to maintain Puma related code.
This commit is contained in:
Alan Guo Xiang Tan 2024-05-07 12:27:29 +08:00 committed by GitHub
parent 0b947b6aab
commit 1dc31f242c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 14 additions and 30 deletions

View File

@ -37,7 +37,6 @@ opts =
ENV["DISCOURSE_DUMP_HEAP"] = "1" ENV["DISCOURSE_DUMP_HEAP"] = "1"
end end
o.on("-m", "--memory_stats") { @mem_stats = true } o.on("-m", "--memory_stats") { @mem_stats = true }
o.on("-u", "--unicorn", "Use unicorn to serve pages as opposed to puma") { @unicorn = true }
o.on( o.on(
"-c", "-c",
"--concurrency [NUM]", "--concurrency [NUM]",
@ -207,32 +206,22 @@ begin
run("bundle exec rake assets:precompile") run("bundle exec rake assets:precompile")
end end
pid = ENV["UNICORN_PORT"] = @port.to_s
if @unicorn ENV["UNICORN_WORKERS"] = @unicorn_workers.to_s
ENV["UNICORN_PORT"] = @port.to_s
ENV["UNICORN_WORKERS"] = @unicorn_workers.to_s
FileUtils.mkdir_p(File.join("tmp", "pids"))
unicorn_pid = spawn("bundle exec unicorn -c config/unicorn.conf.rb")
while ( FileUtils.mkdir_p(File.join("tmp", "pids"))
unicorn_master_pid = pid = spawn("bundle exec unicorn -c config/unicorn.conf.rb")
`ps aux | grep "unicorn master" | grep -v "grep" | awk '{print $2}'`.strip.to_i
) == 0
sleep 1
end
while `ps -f --ppid #{unicorn_master_pid} | grep worker | awk '{ print $2 }'`.split("\n") while (
.map(&:to_i) unicorn_master_pid =
.size != @unicorn_workers.to_i `ps aux | grep "unicorn master" | grep -v "grep" | awk '{print $2}'`.strip.to_i
sleep 1 ) == 0
end sleep 1
end
unicorn_pid while `pgrep -P #{unicorn_master_pid}`.split("\n").map(&:to_i).size != @unicorn_workers.to_i
else sleep 1
spawn("bundle exec puma -p #{@port} -e production") end
end
sleep 1 while port_available? @port
puts "Starting benchmark..." puts "Starting benchmark..."
@ -296,12 +285,7 @@ begin
puts "Your Results: (note for timings- percentile is first, duration is second in millisecs)" puts "Your Results: (note for timings- percentile is first, duration is second in millisecs)"
if @unicorn puts "Unicorn: (workers: #{@unicorn_workers})"
puts "Unicorn: (workers: #{@unicorn_workers})"
else
# TODO we want to also bench puma clusters
puts "Puma: (single threaded)"
end
puts "Include env: #{@include_env}" puts "Include env: #{@include_env}"
puts "Iterations: #{@iterations}, Best of: #{@best_of}" puts "Iterations: #{@iterations}, Best of: #{@best_of}"
puts "Concurrency: #{@concurrency}" puts "Concurrency: #{@concurrency}"