livebook/lib/live_book/runtime.ex
Jonatan Kłosko 79e5c432b3
Move evaluation to a separate Elixir runtime (#20)
* Isolate evaluation in separate node for each session

* Start new remote upon first evaluation and handle nodedown

* Add UI for managing evaluation node, improve naming and structure

* Show runtime initialization errors and some fixes

* Improve standalone node initialization

* Correctly handle multiple sessions connecting to the same node

* Fix session tests concerning evaluation

* Documentation and some refactoring

* Various improvements

* Configure schedulers to get to sleep immediately after evaluation

* Move EvaluatorSpervisor into the Remote namespace

* Fix evaluators cleanup

* Add tests

* Improve flash messages

* Introduce remote genserver taking care of cleanup

* Redefine the Runtime protocol to serve as an interface for evaluation

* Cleanup operations

* Use reference for communication with a standalone node

* Use shortnames for distribution by default

* Update node configuration and make sure epmd is running

* Rename Remote to ErlDist
2021-02-11 12:42:17 +01:00

64 lines
2.1 KiB
Elixir

defprotocol LiveBook.Runtime do
@moduledoc false
# This protocol defines an interface for evaluation backends.
#
# Usually a runtime involves a set of processes responsible
# for evaluation, which could be running on a different node,
# however the protocol does not require that.
@typedoc """
A term used to identify evaluation or container.
"""
@type ref :: term()
@doc """
Sets the caller as runtime owner.
The runtime most likely has some kind of leading process,
this method starts monitoring it and returns the monitor reference,
so the caller knows if the runtime is down by listening to a :DOWN message.
"""
@spec connect(t()) :: reference()
def connect(runtime)
@doc """
Disconnects the current owner from runtime.
This should cleanup the underlying node/processes.
"""
@spec disconnect(t()) :: :ok
def disconnect(runtime)
@doc """
Asynchronously parses and evaluates the given code.
Container isolates a group of evaluations. Every evaluation can use previous
evaluation's environment and bindings, as long as they belong to the same container.
Evaluation outputs are send to the connected runtime owner.
The messages should be of the form:
* `{:evaluation_stdout, ref, string}` - output captured during evaluation
* `{:evaluation_response, ref, response}` - final result of the evaluation
"""
@spec evaluate_code(t(), String.t(), ref(), ref(), ref()) :: :ok
def evaluate_code(runtime, code, container_ref, evaluation_ref, prev_evaluation_ref \\ :initial)
@doc """
Disposes of evaluation identified by the given ref.
This should be used to cleanup resources related to old evaluation if no longer needed.
"""
@spec forget_evaluation(t(), ref(), ref()) :: :ok
def forget_evaluation(runtime, container_ref, evaluation_ref)
@doc """
Disposes of evaluation container identified by the given ref.
This should be used to cleanup resources keeping track
of the container and contained evaluations.
"""
@spec drop_container(t(), ref()) :: :ok
def drop_container(runtime, container_ref)
end