Module erlperf_job

Job runner, taking care of init/done, workers added and removed.

Copyright © (C) 2019-2022, Maxim Fedorov

Behaviours: gen_server.

Description

Job runner, taking care of init/done, workers added and removed. Works just like a simple_one_for_one supervisor (children are temporary runners). There are two benchmarking modes: continuous (activated by setting non-zero concurrency), and sample-based (activated manually and deactivated after runner does requested amount of iterations).

Job is defined with 4 functions (code map):

Data Types

callable()

callable() = mfargs() | [mfargs()] | function() | fun((term()) -> term()) | string()

code_map()

code_map() = #{runner := callable(), init => callable(), init_runner => callable(), done => callable()}

exec()

exec() = #exec{name = atom(), source = [string()], binary = binary(), init = fun(() -> term()), init_runner = fun((term()) -> term()), runner = {fun((term()) -> term()), non_neg_integer()}, sample_runner = {fun((non_neg_integer(), term()) -> term()), non_neg_integer()}, done = fun((term()) -> term())}

handle()

handle() = {module(), non_neg_integer()}

mfargs()

mfargs() = {module(), atom(), [term()]}

server_ref()

server_ref() = gen_server:server_ref()

state()

state() = #erlperf_job_state{exec = exec(), init_result = term(), workers = [pid()], sample_workers = #{pid() => {pid(), reference()}}}

Function Index

concurrency/1
handle/1 Returns the sampling handle for the job.
handle_call/3
handle_cast/2
handle_info/2
init/1
measure/2 Executes the runner SampleCount times, returns time in microseconds it took to execute.
sample/1 Returns the current sample for the job, or undefined if the job has stopped.
set_concurrency/2 Change concurrency setting for this job.
source/1 Returns the source code that was generated for this job.
start/1 Starts the benchmark instance.
start_link/1 Starts the benchmark instance and links it to caller.
terminate/2

Function Details

concurrency/1

concurrency(JobId::server_ref()) -> Concurrency::non_neg_integer()

handle/1

handle(JobId::server_ref()) -> handle()

Returns the sampling handle for the job.

handle_call/3

handle_call(X1::term(), From::{pid(), reference()}, Erlperf_job_state::state()) -> {reply, term(), state()}

handle_cast/2

handle_cast(Request, State) -> any()

handle_info/2

handle_info(X1::term(), Erlperf_job_state::state()) -> {noreply, state()}

init/1

init(Exec) -> any()

measure/2

measure(JobId::server_ref(), SampleCount::non_neg_integer()) -> TimeUs::non_neg_integer() | already_started

Executes the runner SampleCount times, returns time in microseconds it took to execute. Similar to timer:tc. Has less overhead compared to continuous benchmarking, therefore can be used even for very fast functions.

sample/1

sample(X1::handle()) -> non_neg_integer() | undefined

Returns the current sample for the job, or undefined if the job has stopped.

set_concurrency/2

set_concurrency(JobId::server_ref(), Concurrency::non_neg_integer()) -> ok

Change concurrency setting for this job. Does not reset counting.

source/1

source(JobId::handle()) -> [string()]

Returns the source code that was generated for this job.

start/1

start(Code::code_map()) -> {ok, pid()} | {error, term()}

Starts the benchmark instance. Job starts with no workers, use set_concurrency/2 to start some.

start_link/1

start_link(Code::code_map()) -> {ok, pid()} | {error, term()}

Starts the benchmark instance and links it to caller. Job starts with no workers, use set_concurrency/2 to start some.

terminate/2

terminate(Reason::term(), Erlperf_job_state::state()) -> ok


Generated by EDoc