No commit activity in last 3 years
No release in over 3 years
Benchmark your API endpoints and get the results fast ! This gem leverages the power of ApacheBench, but can be configured with another benchmark tool
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

~> 2.7
~> 1.0
>= 5.0, ~> 5.0
 Project Readme

RailsApiBenchmark

Work in progress, you can use it like this, see Important

Usage

Run it with:

rails api:benchmark

Display your configuration with:

rails api:benchmark:config

Example output:

{
  "concurrency": 2,
  "host": "localhost:5000",
  "nb_requests": 1000,
  "results_folder": "benchmark",
  "auth_header": "Authorization: Token token=benchToken",
  "curl_cmd": "curl -H \"%{auth_header}\" http://%{host}%{route}",
  "bench_cmd": "ab -n %{nb_requests} -c %{concurrency} -g plot.tsv -H \"%{auth_header}\" http://%{host}%{route}",
  "server_cmd": "bundle exec puma",
  "env_vars": {
    "RAILS_MAX_THREADS": "2",
    "RAILS_ENV": "production"
  },
  "regexps": [
    {
      "key": "response_time",
      "name": "Average time per request (ms)",
      "regexp": "(?-mix:Time\\s+per\\s+request:\\s+([0-9.]*).*\\(mean\\))"
    },
    {
      "key": "req_per_sec",
      "name": "Requests per second (#)",
      "regexp": "(?-mix:Requests\\s+per\\s+second:\\s+([0-9.]*).*\\(mean\\))"
    }
  ],
  "routes": [
    {
      "name": "candidates_per_25",
      "route": "/candidates",
      "method": "get",
      "title": "GET /candidates",
      "description": "Get first page of candidates (default 25 per page)"
    }
  ]
}

Important

  • Only JSON responses are supported yet
  • Only GET requests are supported yet
  • Configuration is not validated

Installation

  • Install gnuplot
  • Install ApacheBench

For ubuntu:

sudo apt-get install gnuplot
sudo apt-get install apache2-utils
  • Add this line to your application's Gemfile:
gem 'rails_api_benchmark'
  • And then execute:
bundle
  • Provide necessary configuration in initializer, generate it with:
rails g rails_api_benchmark:config
  • Next, add this to your Rakefile:
require 'rails_api_benchmark/benchmark_tasks'

You can now run:

rails api:benchmark

Screenshots

The README is the benchmark index, the page you’ll see in benchmark/ folder. It lists all the routes configured to be benchmarked:

Benchmark Index

Results are listed in a summary table to allow fast-spotting of slowdowns:

Benchmark Summary

Result page for a single route with gnuplot:

Benchmark Results

Contributing

Contributions are welcome

License

The gem is available as open source under the terms of the MIT License.

TODO

  • POST requests handling
  • Add simplecov to permit controller coverage for example
  • Document configuration template file