package rpc_parallel
Module Parallel.MakeSource
module Worker = Make(T)
The Worker module has specialized functions to spawn workers and run functions on workers.
Parameters
module S : Worker_specSignature
A Worker.t type is defined with bin_io so it is possible to create functions that take a worker as an argument.
include Core.Bin_prot.Binable.S with type t := t
include Bin_prot.Binable.S_only_functions with type t := t
This function only needs implementation if t exposed to be a polymorphic variant. Despite what the type reads, this does *not* produce a function after reading; instead it takes the constructor tag (int) before reading and reads the rest of the variant t afterwards.
Accessor for the functions implemented by this worker type
serve arg will start an Rpc server in process implementing all the functions of the given worker.
type 'a with_spawn_args =
?how:How_to_run.t ->
?name:string ->
?env:(string * string) list ->
?connection_timeout:Core.Time_float.Span.t ->
?cd:string ->
on_failure:(Core.Error.t -> unit) ->
'aThe various spawn functions create a new worker process that implements the functions specified in the Worker_spec.
name will be attached to certain error messages and is useful for debugging.
env extends the environment of the spawned worker process.
connection_timeout is used for various internal timeouts. This may need be to increased if the init arg is really large (serialization and deserialization takes more than connection_timeout).
cd changes the current working directory of a spawned worker process.
shutdown_on specifies when a worker should shut itself down.
on_failure exn will be called in the spawning process upon the worker process raising a background exception. All exceptions raised before functions return will be returned to the caller. on_failure will be called in Monitor.current () at the time of this spawn call. The worker initiates shutdown upon sending the exception to the master process.
worker_state_init_arg (below) will be passed to init_worker_state of the given Worker_spec module. This initializes a persistent worker state for all connections to this worker.
val spawn :
(?umask:int ->
shutdown_on:'a Shutdown_on(Core.Or_error).t ->
redirect_stdout:Fd_redirection.t ->
redirect_stderr:Fd_redirection.t ->
S.Worker_state.init_arg ->
'a)
with_spawn_argsThe spawned worker process daemonizes. Any initialization errors that wrote to stderr (Rpc_parallel internal initialization, not user initialization code) will be captured and rewritten to the spawning process's stderr with the prefix "WORKER %NAME% STDERR".
redirect_stdout and redirect_stderr specify stdout and stderr of the worker process.
val spawn_exn :
(?umask:int ->
shutdown_on:'a Shutdown_on(Core.Monad.Ident).t ->
redirect_stdout:Fd_redirection.t ->
redirect_stderr:Fd_redirection.t ->
S.Worker_state.init_arg ->
'a)
with_spawn_argsval spawn_in_foreground :
(shutdown_on:'a Shutdown_on(Spawn_in_foreground_result).t ->
S.Worker_state.init_arg ->
'a)
with_spawn_argsSimilar to spawn but the worker process does not daemonize. If the process was spawned on a remote host, the ssh Process.t is returned.
Remember to call Process.wait on the returned Process.t to avoid a zombie process. Once the process exits, remember to call Writer.close on Process.stdin and Reader.close on Process.stdout and Process.stderr to close the process's stdin/stdout/stderr.
val spawn_in_foreground_exn :
(shutdown_on:'a Shutdown_on(Spawn_in_foreground_exn_result).t ->
S.Worker_state.init_arg ->
'a)
with_spawn_argsshutdown attempts to connect to a worker. Upon success, Shutdown.shutdown 0 is run in the worker. If you want strong guarantees that a worker did shutdown, consider using spawn_in_foreground and inspecting the Process.t.
This module is used for internal testing of the rpc_parallel library.