DEV: Improve/Fix script/bench.rb (#19646)

1. Fix bug where we were not waiting for all unicorn workers to start up
before running benchmarks.

2. Fix a bug where headers were not used when benchmarking. Admin
benchmarks were basically running as anon user.

3. Disable rate limits when in profile env. We're pretty much going to
hit the rate limit every time as a normal user.

4. Benchmark against topic with a fixed posts count of 100. Previously profiling script was just randomly creating posts
and we would benchmark against a topic with a fixed posts count of 30.
Sometimes, the script fails because no topics with a posts count of 30
exists.

5. Benchmarks are not run against a normal user on top of anon and
admin.

6. Add script option to select tests that should be run.
This commit is contained in:
Alan Guo Xiang Tan
2022-12-30 07:25:11 +08:00
committed by GitHub
parent 63debd6d33
commit 0da79561c3
4 changed files with 136 additions and 50 deletions

24
lib/tasks/profile.rake Normal file
View File

@@ -0,0 +1,24 @@
# frozen_string_literal: true
desc "generate a user api key for given user in profiling environment"
task "user_api_key:create", [:username] => :environment do |task, args|
raise "user_api_key:create rake task is only meant for the profiling env" if ENV["RAILS_ENV"] != "profile"
raise "Supply a username for the key" if !args[:username]
user = User.find_by_username(args[:username])
raise "'#{args[:username]}' is not a valid username" if !user
application_name = 'perf test application'
user_api_key = UserApiKey.where(application_name: application_name).destroy_all
user_api_key = UserApiKey.create!(
application_name: application_name,
client_id: '1234',
scopes: ['read'].map { |name| UserApiKeyScope.new(name: name) },
user_id: user.id
)
puts user_api_key.key
end