rubybench_runner 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +0 -5
- data/exe/rubybench_runner +1 -1
- data/lib/rubybench_runner/base_runner.rb +74 -4
- data/lib/rubybench_runner/configurations.rb +6 -11
- data/lib/rubybench_runner/dependencies_checker.rb +25 -16
- data/lib/rubybench_runner/rails_runner.rb +8 -42
- data/lib/rubybench_runner/version.rb +1 -1
- data/rubybench_runner.gemspec +1 -5
- metadata +3 -45
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 334483648fd77a009b7b9ba01e47f83ba9b078d1734260d85bc7f8a6c7e837de
|
4
|
+
data.tar.gz: 97b942643361581ef850ae4b2acf73e7bc2986c664ea9239232a0b8d5bd4e379
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a3a989c8eeaa9d260b976476a2d01185a40b4111f5d35172d3dff4a944237b4a61097af78c2a665ea4fa6a25ca85b05e2349a79f5f8cd628db0b5ebad9e7a100
|
7
|
+
data.tar.gz: 8b22f02267a6f54c14b2772dfb35a77d13351882d0bb14ebf031a54b1381a54dd36e2909f091390924889c82a1b0cb789332664cf3c9d77ae77c67f5b74a9512
|
data/Gemfile.lock
CHANGED
@@ -10,11 +10,9 @@ GEM
|
|
10
10
|
byebug (11.0.1)
|
11
11
|
jaro_winkler (1.5.2)
|
12
12
|
minitest (5.11.3)
|
13
|
-
mysql2 (0.5.2)
|
14
13
|
parallel (1.17.0)
|
15
14
|
parser (2.6.3.0)
|
16
15
|
ast (~> 2.4.0)
|
17
|
-
pg (1.1.4)
|
18
16
|
rainbow (3.0.0)
|
19
17
|
rake (10.5.0)
|
20
18
|
rubocop (0.71.0)
|
@@ -31,11 +29,8 @@ PLATFORMS
|
|
31
29
|
ruby
|
32
30
|
|
33
31
|
DEPENDENCIES
|
34
|
-
bundler (~> 2.0)
|
35
32
|
byebug
|
36
33
|
minitest (~> 5.0)
|
37
|
-
mysql2 (= 0.5.2)
|
38
|
-
pg (= 1.1.4)
|
39
34
|
rake (~> 10.0)
|
40
35
|
rubocop (~> 0.70)
|
41
36
|
rubybench_runner!
|
data/exe/rubybench_runner
CHANGED
@@ -25,7 +25,7 @@ OptionParser.new do |opts|
|
|
25
25
|
|
26
26
|
Available options:
|
27
27
|
BANNER
|
28
|
-
opts.on("--db=DB", "Select database to use for the benchmarks.
|
28
|
+
opts.on("--db=DB", "Select database to use for the benchmarks. Valid options are: `postgres` and `mysql`") do |v|
|
29
29
|
v = v.strip.downcase
|
30
30
|
pg_options = %w{pg postgres postgresql}
|
31
31
|
mysql_options = %w{mysql mysql2}
|
@@ -40,10 +40,10 @@ module RubybenchRunner
|
|
40
40
|
create_tmpdir
|
41
41
|
cleanup(before: true)
|
42
42
|
check_dependencies
|
43
|
-
download_script
|
44
43
|
write_gemfile
|
45
44
|
bundle_install
|
46
45
|
setup_db
|
46
|
+
download_script
|
47
47
|
run_benchmarks
|
48
48
|
process_results
|
49
49
|
print_results
|
@@ -112,12 +112,52 @@ module RubybenchRunner
|
|
112
112
|
end
|
113
113
|
|
114
114
|
def check_dependencies
|
115
|
-
return if opts.skip_dependencies_check
|
115
|
+
return if opts.skip_dependencies_check || !require_db?
|
116
|
+
|
117
|
+
if opts.db == "postgres"
|
118
|
+
require_gem 'pg'
|
119
|
+
elsif opts.db == "mysql2"
|
120
|
+
require_gem 'mysql2'
|
121
|
+
end
|
122
|
+
|
116
123
|
log("Checking dependencies...")
|
117
|
-
RubybenchRunner::DependenciesChecker.check
|
124
|
+
RubybenchRunner::DependenciesChecker.check(pg: opts.db == "postgres", mysql: opts.db == "mysql2")
|
118
125
|
end
|
119
126
|
|
120
127
|
def setup_db
|
128
|
+
return if !require_db?
|
129
|
+
|
130
|
+
log("Checking database...")
|
131
|
+
config = RubybenchRunner::Configurations.new(mysql_map: true)
|
132
|
+
if opts.db == "postgres"
|
133
|
+
conn_config = config["postgres"]
|
134
|
+
rubybench_db = conn_config[:dbname]
|
135
|
+
conn_config[:dbname] = "postgres"
|
136
|
+
conn = PG.connect(conn_config)
|
137
|
+
begin
|
138
|
+
res = conn.exec("SELECT 1 FROM pg_database WHERE datname = '#{rubybench_db}'")
|
139
|
+
if !res.first
|
140
|
+
conn.exec("CREATE DATABASE #{rubybench_db}")
|
141
|
+
log("Created PostgreSQL database with the name '#{rubybench_db}'")
|
142
|
+
end
|
143
|
+
ensure
|
144
|
+
conn.close
|
145
|
+
end
|
146
|
+
elsif opts.db == "mysql2"
|
147
|
+
conn_config = config["mysql2"]
|
148
|
+
rubybench_db = conn_config[:database]
|
149
|
+
conn_config[:database] = "mysql"
|
150
|
+
client = Mysql2::Client.new(conn_config)
|
151
|
+
begin
|
152
|
+
res = client.query("SHOW DATABASES LIKE '#{rubybench_db}'")
|
153
|
+
if !res.first
|
154
|
+
client.query("CREATE DATABASE #{rubybench_db}")
|
155
|
+
log("Created MySQL database with the name '#{rubybench_db}'")
|
156
|
+
end
|
157
|
+
ensure
|
158
|
+
client.close
|
159
|
+
end
|
160
|
+
end
|
121
161
|
end
|
122
162
|
|
123
163
|
def run_benchmarks
|
@@ -224,10 +264,40 @@ module RubybenchRunner
|
|
224
264
|
|
225
265
|
def normalize_url(url)
|
226
266
|
if url =~ /^(https?:\/\/github.com)/
|
227
|
-
url.sub($1, "https://raw.githubusercontent.com").sub("/blob", "")
|
267
|
+
url.sub($1, "https://raw.githubusercontent.com").sub("/blob/", "/")
|
228
268
|
else
|
229
269
|
url
|
230
270
|
end
|
231
271
|
end
|
272
|
+
|
273
|
+
# small hack for dynamically installing/requiring gems.
|
274
|
+
# some benchmarks don't require db at all
|
275
|
+
# so having mysql2 and pg in the gemspec file means
|
276
|
+
# everyone must have postgres and mysql installed on
|
277
|
+
# their machine in order to use this gem.
|
278
|
+
# this hack allows us to not require mysql/postgres
|
279
|
+
# until the user tries to run a benchmark that needs db.
|
280
|
+
# --
|
281
|
+
# source https://stackoverflow.com/a/36570445
|
282
|
+
|
283
|
+
def require_gem(gem_name)
|
284
|
+
require 'rubygems/commands/install_command'
|
285
|
+
Gem::Specification::find_by_name(gem_name)
|
286
|
+
rescue Gem::LoadError
|
287
|
+
log("Installing the '#{opts.db}' gem...")
|
288
|
+
install_gem(gem_name)
|
289
|
+
ensure
|
290
|
+
log("Using the '#{opts.db}' gem...")
|
291
|
+
require gem_name
|
292
|
+
end
|
293
|
+
|
294
|
+
def install_gem(gem_name)
|
295
|
+
cmd = Gem::Commands::InstallCommand.new
|
296
|
+
cmd.handle_options [gem_name]
|
297
|
+
|
298
|
+
cmd.execute
|
299
|
+
rescue Gem::SystemExitException => e
|
300
|
+
puts "FAILURE: #{e.exit_code} -- #{e.message}" if e.exit_code != 0
|
301
|
+
end
|
232
302
|
end
|
233
303
|
end
|
@@ -8,17 +8,17 @@ module RubybenchRunner
|
|
8
8
|
}
|
9
9
|
DEFAULTS = {
|
10
10
|
postgres: {
|
11
|
-
user:
|
11
|
+
user: nil,
|
12
12
|
dbname: "rubybench",
|
13
|
-
host:
|
14
|
-
port:
|
13
|
+
host: nil,
|
14
|
+
port: nil,
|
15
15
|
password: nil
|
16
16
|
},
|
17
17
|
mysql2: {
|
18
|
-
user:
|
18
|
+
user: nil,
|
19
19
|
dbname: "rubybench",
|
20
|
-
host:
|
21
|
-
port:
|
20
|
+
host: nil,
|
21
|
+
port: nil,
|
22
22
|
password: nil
|
23
23
|
},
|
24
24
|
config_version: CONFIG_VERSION
|
@@ -28,11 +28,6 @@ module RubybenchRunner
|
|
28
28
|
if !File.exists?(CONFIG_PATH)
|
29
29
|
File.write(CONFIG_PATH, YAML.dump(DEFAULTS))
|
30
30
|
end
|
31
|
-
|
32
|
-
if !config_changed?
|
33
|
-
puts "Error: You haven't configured how RubybenchRunner should connect to the database servers on your machine. Please update the #{CONFIG_PATH} file to have the right configurations."
|
34
|
-
exit 1
|
35
|
-
end
|
36
31
|
end
|
37
32
|
|
38
33
|
def [](key)
|
@@ -3,31 +3,40 @@ module RubybenchRunner
|
|
3
3
|
CURRENT_PG_VERSION = "9.6"
|
4
4
|
CURRENT_MYSQL_VERSION = "5.6.24"
|
5
5
|
|
6
|
-
class MissingDependency < StandardError; end
|
7
6
|
class DependenciesChecker
|
8
|
-
def self.check
|
9
|
-
check_pg
|
10
|
-
check_mysql
|
7
|
+
def self.check(pg:, mysql:)
|
8
|
+
check_pg if pg
|
9
|
+
check_mysql if mysql
|
11
10
|
end
|
12
11
|
|
13
12
|
def self.check_pg
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
13
|
+
config = RubybenchRunner::Configurations.new[:postgres]
|
14
|
+
config = config.merge(dbname: "postgres")
|
15
|
+
conn = PG.connect(config)
|
16
|
+
begin
|
17
|
+
output = conn.parameter_status("server_version")
|
18
|
+
output =~ /^([\d.]+) \(/
|
19
|
+
version = $1
|
20
|
+
if version != CURRENT_PG_VERSION
|
21
|
+
warn("PostgreSQL", version, CURRENT_PG_VERSION)
|
22
|
+
end
|
23
|
+
ensure
|
24
|
+
conn.close
|
19
25
|
end
|
20
|
-
rescue Errno::ENOENT
|
21
|
-
raise MissingDependency.new("Postgres doesn't seem to be installed on your system. Please install it and run the benchmarks again")
|
22
26
|
end
|
23
27
|
|
24
28
|
def self.check_mysql
|
25
|
-
|
26
|
-
|
27
|
-
|
29
|
+
config = RubybenchRunner::Configurations.new(mysql_map: true)[:mysql2]
|
30
|
+
config = config.merge(database: "mysql")
|
31
|
+
client = Mysql2::Client.new(config)
|
32
|
+
begin
|
33
|
+
version = client.info[:version]
|
34
|
+
if version != CURRENT_MYSQL_VERSION
|
35
|
+
warn("MySQL", version, CURRENT_MYSQL_VERSION)
|
36
|
+
end
|
37
|
+
ensure
|
38
|
+
client.close
|
28
39
|
end
|
29
|
-
rescue Errno::ENOENT
|
30
|
-
raise MissingDependency.new("MySQL doesn't seem to be installed on your system. Please install it and run the benchmarks again")
|
31
40
|
end
|
32
41
|
|
33
42
|
def self.warn(program, installed, recommended)
|
@@ -14,53 +14,14 @@ module RubybenchRunner
|
|
14
14
|
config = OpenStruct.new(raw_config[opts.db.to_sym])
|
15
15
|
url = "#{opts.db}://#{config.user}"
|
16
16
|
url += ":#{config.password}" if config.password
|
17
|
-
url += "
|
18
|
-
|
19
|
-
url += "#{config.host}:#{config.port}"
|
20
|
-
end
|
17
|
+
url += "@#{config.host}" if config.host
|
18
|
+
url += ":#{config.port}" if config.port
|
21
19
|
url += "/#{config.dbname}"
|
22
20
|
with_prep_statement = opts.wps == true
|
23
21
|
url += "?prepared_statements=#{with_prep_statement}"
|
24
22
|
@db_url = url
|
25
23
|
end
|
26
24
|
|
27
|
-
def setup_db
|
28
|
-
return if !require_db?
|
29
|
-
log("Checking database...")
|
30
|
-
config = RubybenchRunner::Configurations.new(mysql_map: true)
|
31
|
-
if opts.db == "postgres"
|
32
|
-
require 'pg'
|
33
|
-
conn_config = config["postgres"]
|
34
|
-
rubybench_db = conn_config[:dbname]
|
35
|
-
conn_config[:dbname] = "postgres"
|
36
|
-
conn = PG.connect(conn_config)
|
37
|
-
begin
|
38
|
-
res = conn.exec("SELECT 1 FROM pg_database WHERE datname = '#{rubybench_db}'")
|
39
|
-
if !res.first
|
40
|
-
conn.exec("CREATE DATABASE #{rubybench_db}")
|
41
|
-
log("Created PostgreSQL database with the name '#{rubybench_db}'")
|
42
|
-
end
|
43
|
-
ensure
|
44
|
-
conn.close
|
45
|
-
end
|
46
|
-
elsif opts.db == "mysql2"
|
47
|
-
require 'mysql2'
|
48
|
-
conn_config = config["mysql2"]
|
49
|
-
rubybench_db = conn_config[:database]
|
50
|
-
conn_config[:database] = "mysql"
|
51
|
-
client = Mysql2::Client.new(conn_config)
|
52
|
-
begin
|
53
|
-
res = client.query("SHOW DATABASES LIKE '#{rubybench_db}'")
|
54
|
-
if !res.first
|
55
|
-
client.query("CREATE DATABASE #{rubybench_db}")
|
56
|
-
log("Created MySQL database with the name '#{rubybench_db}'")
|
57
|
-
end
|
58
|
-
ensure
|
59
|
-
client.close
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
25
|
def benchmark_name
|
65
26
|
@benchmark_name ||= "Rails"
|
66
27
|
end
|
@@ -85,7 +46,12 @@ module RubybenchRunner
|
|
85
46
|
|
86
47
|
def require_db?
|
87
48
|
filename = @script_url.split("/")[-1]
|
88
|
-
filename.match?(/activerecord|scaffold/)
|
49
|
+
res = filename.match?(/activerecord|scaffold/)
|
50
|
+
if res && !opts.db
|
51
|
+
puts "This benchmark requires database to run. Please specify the `--db` option (see --help for details)"
|
52
|
+
exit 1
|
53
|
+
end
|
54
|
+
res
|
89
55
|
end
|
90
56
|
end
|
91
57
|
end
|
data/rubybench_runner.gemspec
CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.name = 'rubybench_runner'
|
9
9
|
spec.version = RubybenchRunner::VERSION
|
10
10
|
|
11
|
-
spec.summary = '
|
11
|
+
spec.summary = 'CLI tool to run rubybench.org benchmarks locally'
|
12
12
|
spec.homepage = 'https://github.com/ruby-bench/rubybench_runner'
|
13
13
|
spec.license = 'MIT'
|
14
14
|
spec.authors = ['Osama Sayegh']
|
@@ -23,10 +23,6 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
24
|
spec.require_paths = ['lib']
|
25
25
|
|
26
|
-
spec.add_development_dependency 'bundler', '~> 2.0'
|
27
|
-
spec.add_development_dependency 'pg', '1.1.4'
|
28
|
-
spec.add_development_dependency 'mysql2', '0.5.2'
|
29
|
-
|
30
26
|
spec.add_development_dependency 'byebug'
|
31
27
|
spec.add_development_dependency 'minitest', '~> 5.0'
|
32
28
|
spec.add_development_dependency 'rake', '~> 10.0'
|
metadata
CHANGED
@@ -1,57 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubybench_runner
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Osama Sayegh
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-06-
|
11
|
+
date: 2019-06-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: bundler
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '2.0'
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '2.0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: pg
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - '='
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: 1.1.4
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - '='
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: 1.1.4
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: mysql2
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - '='
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: 0.5.2
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - '='
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: 0.5.2
|
55
13
|
- !ruby/object:Gem::Dependency
|
56
14
|
name: byebug
|
57
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -196,5 +154,5 @@ requirements: []
|
|
196
154
|
rubygems_version: 3.0.3
|
197
155
|
signing_key:
|
198
156
|
specification_version: 4
|
199
|
-
summary:
|
157
|
+
summary: CLI tool to run rubybench.org benchmarks locally
|
200
158
|
test_files: []
|