This repository has been archived by the owner on Apr 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
benchmark
executable file
·71 lines (59 loc) · 1.85 KB
/
benchmark
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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
63
64
65
66
67
68
69
70
71
#!/usr/bin/env ruby
# frozen_string_literal: true
# Benchmark script using derailed_benchmarks and a fake API.
require_relative '../config/boot'
require 'colorize'
require 'open3'
def bm_common_env
'RAILS_ENV=profiling SKIP_FILE_WRITE=1 EUROPEANA_API_URL=http://localhost:3014/api'
end
def bm_gems
puts 'Bundled gems'.bold
puts
stdout, _stderr, _status = Open3.capture3('bundle exec derailed bundle:mem')
puts stdout.split("\n").first.sub('TOP: ', '')
puts
end
def bm_objects(name, path)
puts "#{name}: Objects".bold
puts
cmd = %(#{bm_common_env} TEST_COUNT=10 PATH_TO_HIT="#{path}" bundle exec derailed exec perf:objects)
stdout, stderr, status = Open3.capture3(cmd)
fail "Unable to benchmark objects\n#{stderr}" unless status.success?
puts stdout.split("\n")[0..4].join("\n")
puts
end
def bm_ips(name, path)
puts "#{name}: IPS".bold
puts
cmd = %(#{bm_common_env} TEST_COUNT=1_000 PATH_TO_HIT="#{path}" bundle exec derailed exec perf:ips)
stdout, stderr, status = Open3.capture3(cmd)
fail "Unable to benchmark IPS\n#{stderr}" unless status.success?
puts stdout
puts
end
def bm_path(name, path)
bm_objects(name, path)
bm_ips(name, path)
end
def fake_api_dir
@fake_api_dir ||= File.expand_path('../spec/support/fake_api', __dir__)
end
def start_fake_api
_stdout, stderr, status = Open3.capture3("docker-compose -f #{fake_api_dir}/docker-compose.yml up -d")
fail "Unable to start Docker fake API\n#{stderr}" unless status.success?
end
def stop_fake_api
_stdout, stderr, status = Open3.capture3("docker-compose -f #{fake_api_dir}/docker-compose.yml down")
fail "Unable to stop Docker fake API\n#{stderr}" unless status.success?
end
def with_fake_api
start_fake_api
yield
stop_fake_api
end
with_fake_api do
bm_gems
bm_path('Search results page', '/en/search?q=')
bm_path('Record page', '/en/record/123/abc.html')
end