Class: RailsApiBenchmark::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_api_benchmark.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Default values, INSANE. Must be refactored Maybe create a yaml or json file to import for default values



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
# File 'lib/rails_api_benchmark.rb', line 19

def initialize
  self.concurrency = 2
  self.nb_requests = 1000
  self.server_cmd = 'bundle exec puma'
  self.bench_cmd = 'ab -n %{nb_requests} -c %{concurrency} -g plot.tsv' \
              ' -H "%{auth_header}" http://%{host}%{route}'
  self.curl_cmd = 'curl -H "%{auth_header}" http://%{host}%{route}'
  self.results_folder = 'benchmark'
  self.summary = true
  self.regexps = [
    {
      key: :response_time,
      name: 'Average time per request (ms)',
      regexp: /Time\s+per\s+request:\s+([0-9.]*).*\(mean\)/
    }, {
      key: :req_per_sec,
      name: 'Requests per second (#)',
      regexp: /Requests\s+per\s+second:\s+([0-9.]*).*\(mean\)/
    }
  ]
  self.env_vars = {
    'RAILS_MAX_THREADS' => '2',
    'RAILS_ENV' => 'production',
    'SSL_DISABLE' => 'true',
    'SECRET_KEY_BASE' => 'a1b2c3',
    'PORT' => '5000'
  }
  self.routes = []
  self.host = 'localhost:5000'
end

Instance Attribute Details

#auth_headerObject

Returns the value of attribute auth_header.



13
14
15
# File 'lib/rails_api_benchmark.rb', line 13

def auth_header
  @auth_header
end

#bench_cmdObject

Returns the value of attribute bench_cmd.



13
14
15
# File 'lib/rails_api_benchmark.rb', line 13

def bench_cmd
  @bench_cmd
end

#concurrencyObject

Returns the value of attribute concurrency.



13
14
15
# File 'lib/rails_api_benchmark.rb', line 13

def concurrency
  @concurrency
end

#curl_cmdObject

Returns the value of attribute curl_cmd.



13
14
15
# File 'lib/rails_api_benchmark.rb', line 13

def curl_cmd
  @curl_cmd
end

#env_varsObject

Returns the value of attribute env_vars.



13
14
15
# File 'lib/rails_api_benchmark.rb', line 13

def env_vars
  @env_vars
end

#hostObject

Returns the value of attribute host.



13
14
15
# File 'lib/rails_api_benchmark.rb', line 13

def host
  @host
end

#nb_requestsObject

Returns the value of attribute nb_requests.



13
14
15
# File 'lib/rails_api_benchmark.rb', line 13

def nb_requests
  @nb_requests
end

#regexpsObject

Returns the value of attribute regexps.



13
14
15
# File 'lib/rails_api_benchmark.rb', line 13

def regexps
  @regexps
end

#results_folderObject

Returns the value of attribute results_folder.



13
14
15
# File 'lib/rails_api_benchmark.rb', line 13

def results_folder
  @results_folder
end

#routesObject

Returns the value of attribute routes.



13
14
15
# File 'lib/rails_api_benchmark.rb', line 13

def routes
  @routes
end

#server_cmdObject

Returns the value of attribute server_cmd.



13
14
15
# File 'lib/rails_api_benchmark.rb', line 13

def server_cmd
  @server_cmd
end

#summaryObject

Returns the value of attribute summary.



13
14
15
# File 'lib/rails_api_benchmark.rb', line 13

def summary
  @summary
end

Instance Method Details

#allObject



50
51
52
53
54
55
# File 'lib/rails_api_benchmark.rb', line 50

def all
  instance_variables.inject({}) do |h, v|
    var = v.to_s.sub('@', '')
    h.merge(var.to_sym => send(var))
  end
end