Module hb_persistent.erl¶
Creates and manages long-lived AO-Core resolution processes.
Description¶
These can be useful for situations where a message is large and expensive
to serialize and deserialize, or when executions should be deliberately
serialized to avoid parallel executions of the same computation. This
module is called during the core hb_ao
execution process, so care
must be taken to avoid recursive spawns/loops.
Built using the pg
module, which is a distributed Erlang process group
manager.
Function Index¶
await/4 | If there was already an Erlang process handling this execution, we should register with them and wait for them to notify us of completion. |
deduplicated_execution_test/0* | Test merging and returning a value with a persistent worker. |
default_await/5 | Default await function that waits for a resolution from a worker. |
default_grouper/3 | Create a group name from a Msg1 and Msg2 pair as a tuple. |
default_worker/3 | A server function for handling persistent executions. |
do_monitor/3* | |
find_execution/2* | Find a group with the given name. |
find_or_register/3 | Register the process to lead an execution if none is found, otherwise signal that we should await resolution. |
find_or_register/4* | |
forward_work/2 | Forward requests to a newly delegated execution process. |
group/3 | Calculate the group name for a Msg1 and Msg2 pair. |
notify/4 | Check our inbox for processes that are waiting for the resolution of this execution. |
persistent_worker_test/0* | Test spawning a default persistent worker. |
register_groupname/2* | Register for performing an AO-Core resolution. |
send_response/4* | Helper function that wraps responding with a new Msg3. |
spawn_after_execution_test/0* | |
spawn_test_client/2* | |
spawn_test_client/3* | |
start/0* | Ensure that the pg module is started. |
start_monitor/0 | Start a monitor that prints the current members of the group every n seconds. |
start_monitor/1 | |
start_monitor/2* | |
start_worker/2 | Start a worker process that will hold a message in memory for future executions. |
start_worker/3 | |
stop_monitor/1 | |
test_device/0* | |
test_device/1* | |
unregister/3* | Unregister for being the leader on an AO-Core resolution. |
unregister_groupname/2* | |
unregister_notify/4 | Unregister as the leader for an execution and notify waiting processes. |
wait_for_test_result/1* | |
worker_event/5* | Log an event with the worker process. |
Function Details¶
await/4¶
await(Worker, Msg1, Msg2, Opts) -> any()
If there was already an Erlang process handling this execution, we should register with them and wait for them to notify us of completion.
deduplicated_execution_test/0 *¶
deduplicated_execution_test() -> any()
Test merging and returning a value with a persistent worker.
default_await/5¶
default_await(Worker, GroupName, Msg1, Msg2, Opts) -> any()
Default await function that waits for a resolution from a worker.
default_grouper/3¶
default_grouper(Msg1, Msg2, Opts) -> any()
Create a group name from a Msg1 and Msg2 pair as a tuple.
default_worker/3¶
default_worker(GroupName, Msg1, Opts) -> any()
A server function for handling persistent executions.
do_monitor/3 *¶
do_monitor(Group, Last, Opts) -> any()
find_execution/2 *¶
find_execution(Groupname, Opts) -> any()
Find a group with the given name.
find_or_register/3¶
find_or_register(Msg1, Msg2, Opts) -> any()
Register the process to lead an execution if none is found, otherwise signal that we should await resolution.
find_or_register/4 *¶
find_or_register(GroupName, Msg1, Msg2, Opts) -> any()
forward_work/2¶
forward_work(NewPID, Opts) -> any()
Forward requests to a newly delegated execution process.
group/3¶
group(Msg1, Msg2, Opts) -> any()
Calculate the group name for a Msg1 and Msg2 pair. Uses the Msg1's
group
function if it is found in the info
, otherwise uses the default.
notify/4¶
notify(GroupName, Msg2, Msg3, Opts) -> any()
Check our inbox for processes that are waiting for the resolution of this execution. Comes in two forms: 1. Notify on group name alone. 2. Notify on group name and Msg2.
persistent_worker_test/0 *¶
persistent_worker_test() -> any()
Test spawning a default persistent worker.
register_groupname/2 *¶
register_groupname(Groupname, Opts) -> any()
Register for performing an AO-Core resolution.
send_response/4 *¶
send_response(Listener, GroupName, Msg2, Msg3) -> any()
Helper function that wraps responding with a new Msg3.
spawn_after_execution_test/0 *¶
spawn_after_execution_test() -> any()
spawn_test_client/2 *¶
spawn_test_client(Msg1, Msg2) -> any()
spawn_test_client/3 *¶
spawn_test_client(Msg1, Msg2, Opts) -> any()
start/0 *¶
start() -> any()
Ensure that the pg
module is started.
start_monitor/0¶
start_monitor() -> any()
Start a monitor that prints the current members of the group every n seconds.
start_monitor/1¶
start_monitor(Group) -> any()
start_monitor/2 *¶
start_monitor(Group, Opts) -> any()
start_worker/2¶
start_worker(Msg, Opts) -> any()
Start a worker process that will hold a message in memory for future executions.
start_worker/3¶
start_worker(GroupName, NotMsg, Opts) -> any()
stop_monitor/1¶
stop_monitor(PID) -> any()
test_device/0 *¶
test_device() -> any()
test_device/1 *¶
test_device(Base) -> any()
unregister/3 *¶
unregister(Msg1, Msg2, Opts) -> any()
Unregister for being the leader on an AO-Core resolution.
unregister_groupname/2 *¶
unregister_groupname(Groupname, Opts) -> any()
unregister_notify/4¶
unregister_notify(GroupName, Msg2, Msg3, Opts) -> any()
Unregister as the leader for an execution and notify waiting processes.
wait_for_test_result/1 *¶
wait_for_test_result(Ref) -> any()
worker_event/5 *¶
worker_event(Group, Data, Msg1, Msg2, Opts) -> any()
Log an event with the worker process. If we used the default grouper function, we should also include the Msg1 and Msg2 in the event. If we did not, we assume that the group name expresses enough information to identify the request.