/fn_load_tester

Helper tool to execute load tests against your functions, especially your GenServers, and calculate statistics of the test

Primary LanguageElixir

FnLoadTester

hex.pm hexdocs.pm Build Status

FnLoadTester is a helper tool to execute load tests against your functions, especially your GenServers, and calculate statistics of the test.

Installation

If available in Hex, the package can be installed by adding fn_load_tester to your list of dependencies in mix.exs:

def deps do
  [
    {:fn_load_tester, "~> 0.1.0", only: :dev}
  ]
end

Stats

FnLoadTester brings some basic statistics but it also gives you the possibility of adding your own statistics.

To Build a new Stats it is only necessary to use FnLoadTester.Stats and implement the callbacks:

  • calculate(list): the input is a list of times and the output has to be a number.

  • units(): The outpus has to be an atom which indicates the unit of the output of calculate:

    • :nanosecond
    • :microsecond
    • :millisecond
    • :second
  • title(): The output will be a string with the Title of the statistics.

      defmodule MyMaximum do
        use FnLoadTester.Stats
    
        def calculate(data), do: Enum.max(data)
        def units(), do: :nanosecond
        def title(), do: "My Maximum"
      end

In order to have more information, check the module FnLoadTester.Stats

Execution

In order to execute the load test you only have to specify the number of parallel clients that will execute the given function and the number of requests per client. The fourth argument (optional) is the statistics that will be calculated.

  iex> FnLoadTester.request(1, 100, fn -> MyGenServer.execute() end)
  Maximum:                104610  ns
  Minimum:                20123   ns
  Average:                26940   ns
  Percentile50:           21877   ns
  Percentile90:           36460   ns
  Percentile95:           50784   ns
  Percentile99:           104610  ns
  :ok
  iex> FnLoadTester.request(1, 100, fn -> MyGenServer.execute() end, [FnLoadTester.Stats.Maximum, FnLoadTester.Stats.Minimum])
  Maximum:                104610  ns
  Minimum:                20123   ns
  :ok

Test

mix test