Dune.Eval.Opts (dune v0.2.1) View Source
Defines the evaluation options for Dune, which restrict the VM resources allocated to execute user code.
See Dune.Parser.Opts
for parsing-time restriction options.
The available fields are:
max_heap_size
: Limits the memory usage of the evaluation process using themax_heap_size
flag. Should be an integer> 0
. Defaults to30_000
.max_reductions
: Limits the number of CPU cycles of the evaluation process. The erlang pre-emptive scheduler is using reductions to measure work being done by processes, which is useful to prevent users to run CPU intensive code such as infinite loops. Should be an integer> 0
. Defaults to30_000
.timeout
: Limits the time the evaluation process is authorized to run (in milliseconds). Should be an integer> 0
. Defaults to50
.
The evaluation process will still need to parse and execute the sanitized AST, so using too low limits here would leave only a small margin to actually run user code.
Link to this section Summary
Functions
Validates untrusted options from a keyword or a map and returns a Dune.Eval.Opts
struct.
Link to this section Types
Specs
t() :: %Dune.Eval.Opts{ max_heap_size: pos_integer(), max_reductions: pos_integer(), timeout: pos_integer() }
Link to this section Functions
Specs
Validates untrusted options from a keyword or a map and returns a Dune.Eval.Opts
struct.
Examples
iex> Dune.Eval.Opts.validate!([])
%Dune.Eval.Opts{max_heap_size: 30_000, max_reductions: 30_000, timeout: 50}
iex> Dune.Eval.Opts.validate!(max_reductions: 10_000, max_heap_size: 10_000, timeout: 20)
%Dune.Eval.Opts{max_heap_size: 10_000, max_reductions: 10_000, timeout: 20}
iex> Dune.Eval.Opts.validate!(max_heap_size: 0)
** (ArgumentError) max_heap_size should be an integer > 0
iex> Dune.Eval.Opts.validate!(max_reductions: 0)
** (ArgumentError) max_reductions should be an integer > 0
iex> Dune.Eval.Opts.validate!(timeout: "55")
** (ArgumentError) timeout should be an integer > 0