Skip to content

Commit

Permalink
DEV: Update bench.rb for core changes (discourse#8670)
Browse files Browse the repository at this point in the history
- Use new api key rake task
- Switch to header-based API auth
- Stop hard-coding topic id
  • Loading branch information
davidtaylorhq authored and SamSaffron committed Jan 8, 2020
1 parent a8fbf7c commit fd6fbaa
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
26 changes: 18 additions & 8 deletions script/bench.rb
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def port_available?(port)
run("bundle exec ruby script/profile_db_generator.rb")

puts "Getting api key"
api_key = `bundle exec rake api_key:get_or_create_master[bench]`.split("\n")[-1]
api_key = `bundle exec rake api_key:create_master[bench]`.split("\n")[-1]

def bench(path, name)
puts "Running apache bench warmup"
Expand Down Expand Up @@ -225,22 +225,32 @@ def bench(path, name)
end

puts "Starting benchmark..."
append = "?api_key=#{api_key}&api_username=admin1"
headers = { 'Api-Key' => api_key,
'Api-Username' => "admin1" }

# asset precompilation is a dog, wget to force it
run "wget http://127.0.0.1:#{@port}/ -o /dev/null -O /dev/null"

redirect_response = `curl -s -I "http://127.0.0.1:#{@port}/t/i-am-a-topic-used-for-perf-tests"`
if redirect_response !~ /301 Moved Permanently/
raise "Unable to locate topic for perf tests"
end

topic_url = redirect_response.match(/^location: .+(\/t\/i-am-a-topic-used-for-perf-tests\/.+)$/i)[1].strip

tests = [
["categories", "/categories"],
["home", "/"],
["topic", "/t/i-am-a-topic-used-for-perf-tests/179"]
["topic", topic_url]
# ["user", "/u/admin1/activity"],
]

tests.concat(tests.map { |k, url| ["#{k}_admin", "#{url}#{append}"] })
tests.concat(tests.map { |k, url| ["#{k}_admin", "#{url}", headers] })

tests.each do |_, path, headers_for_path|
header_string = headers_for_path&.map { |k, v| "-H \"#{k}: #{v}\"" }&.join(" ")

tests.each do |_, path|
if `curl -s -I "http://127.0.0.1:#{@port}#{path}"` !~ /200 OK/
if `curl -s -I "http://127.0.0.1:#{@port}#{path}" #{header_string}` !~ /200 OK/
raise "#{path} returned non 200 response code"
end
end
Expand Down Expand Up @@ -311,12 +321,12 @@ def get_mem(pid)

if @mem_stats
puts
puts open("http://127.0.0.1:#{@port}/admin/memory_stats#{append}").read
puts open("http://127.0.0.1:#{@port}/admin/memory_stats", headers).read
end

if @dump_heap
puts
puts open("http://127.0.0.1:#{@port}/admin/dump_heap#{append}").read
puts open("http://127.0.0.1:#{@port}/admin/dump_heap", headers).read
end

if @result_file
Expand Down
2 changes: 1 addition & 1 deletion script/profile_db_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def create_admin(seq)
end

def ensure_perf_test_topic_has_right_title!
t = Topic.find(179)
t = Topic.where(archetype: :regular).last
t.title = "I am a topic used for perf tests"
t.save! if t.title_changed?
end
Expand Down

0 comments on commit fd6fbaa

Please sign in to comment.