Class: RubybenchRunner::RailsRunner
Constant Summary
Constants inherited
from BaseRunner
BaseRunner::COPY_FOLDERS, BaseRunner::DEFAULT_OPTS, BaseRunner::HELPERS_VERSION_FILE
Instance Attribute Summary
Attributes inherited from BaseRunner
#opts, #repo_path, #script_url
Instance Method Summary
collapse
Methods inherited from BaseRunner
#bundle_install, #check_dependencies, #copy_helpers, #create_tmpdir, #dest_dir, #download_script, #initialize, #print_results, #process_results, #run, #run_benchmarks, #script_full_path, #script_name, #script_path, #write_gemfile
Instance Method Details
#benchmark_name ⇒ Object
64
65
66
|
# File 'lib/rubybench_runner/rails_runner.rb', line 64
def benchmark_name
@benchmark_name ||= "Rails"
end
|
#command ⇒ Object
3
4
5
6
7
8
9
|
# File 'lib/rubybench_runner/rails_runner.rb', line 3
def command
command = "RAILS_ENV=production #{super}"
if require_db?
command = "DATABASE_URL=#{database_url} #{command}"
end
command
end
|
#database_url ⇒ Object
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/rubybench_runner/rails_runner.rb', line 11
def database_url
return @db_url if @db_url
raw_config = RubybenchRunner::Configurations.new
config = OpenStruct.new(raw_config[opts.db.to_sym])
url = "#{opts.db}://#{config.user}"
url += ":#{config.password}" if config.password
url += "@"
if config.host && config.port
url += "#{config.host}:#{config.port}"
end
url += "/#{config.dbname}"
with_prep_statement = opts.wps == true
url += "?prepared_statements=#{with_prep_statement}"
@db_url = url
end
|
#gemfile_content ⇒ Object
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/rubybench_runner/rails_runner.rb', line 68
def gemfile_content
@gemfile_content ||= " source 'https://rubygems.org'\n\n gem 'rails', path: '\#{@repo_path}'\n\n gem 'mysql2', '0.5.2'\n gem 'pg', '1.1.4'\n gem 'benchmark-ips', '~> 2.7.2'\n gem 'redis', '~> 4.1.2'\n gem 'puma', '~> 3.12.1'\n GEMFILE\nend\n"
|
#require_db? ⇒ Boolean
86
87
88
89
|
# File 'lib/rubybench_runner/rails_runner.rb', line 86
def require_db?
filename = @script_url.split("/")[-1]
filename.match?(/activerecord|scaffold/)
end
|
#save_dir ⇒ Object
82
83
84
|
# File 'lib/rubybench_runner/rails_runner.rb', line 82
def save_dir
@save_dir ||= File.join(dest_dir, "rails")
end
|
#setup_db ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/rubybench_runner/rails_runner.rb', line 27
def setup_db
return if !require_db?
log("Checking database...")
config = RubybenchRunner::Configurations.new(mysql_map: true)
if opts.db == "postgres"
require 'pg'
conn_config = config["postgres"]
rubybench_db = conn_config[:dbname]
conn_config[:dbname] = "postgres"
conn = PG.connect(conn_config)
begin
res = conn.exec("SELECT 1 FROM pg_database WHERE datname = '#{rubybench_db}'")
if !res.first
conn.exec("CREATE DATABASE #{rubybench_db}")
log("Created PostgreSQL database with the name '#{rubybench_db}'")
end
ensure
conn.close
end
elsif opts.db == "mysql2"
require 'mysql2'
conn_config = config["mysql2"]
rubybench_db = conn_config[:database]
conn_config[:database] = "mysql"
client = Mysql2::Client.new(conn_config)
begin
res = client.query("SHOW DATABASES LIKE '#{rubybench_db}'")
if !res.first
client.query("CREATE DATABASE #{rubybench_db}")
log("Created MySQL database with the name '#{rubybench_db}'")
end
ensure
client.close
end
end
end
|