Runtime
- class mosaic.runtime.runtime.Runtime(**kwargs)[source]
Bases:
BaseRPC
Class representing a local runtime of any possible type.
The runtime handles the mosaic life cycle:
it handles the comms manager, the event loop, the logger and keeps proxies to existing remote runtimes;
it keeps track of resident mosaic objects (tessera, task) and proxies to those;
it routes remote commands to these resident mosaic objects.
For referece on accepted parameters, check mosaic.init.
- property address
IP address of the runtime.
- async barrier(timeout=None)[source]
Wait until all pending tasks are done. If no timeout is provided, the barrier will wait indefinitely.
- Parameters:
timeout (float, optional) –
- cmd(sender_id, cmd)[source]
Process incoming command address to one of the resident objects.
- Parameters:
sender_id (str) –
cmd (CMD) –
- connect(sender_id, uid, address, port)[source]
Connect to a specific remote runtime.
- Parameters:
sender_id (str) –
uid (str) –
address (str) –
port (int) –
- dec_ref(sender_id, uid, type)[source]
Decrease reference count for a resident object.
If reference count decreases below 1, deregister the object.
- Parameters:
sender_id (str) – Caller UID.
uid (str) – UID of the object being referenced.
type (str) – Type of the object being referenced.
- dec_refs(sender_id, msgs)[source]
Decrease reference count for multiple resident objects.
If reference count decreases below 1, deregister the object.
- Parameters:
sender_id (str) – Caller UID.
msgs (list) – UIDs of the object being referenced.
- disconnect(sender_id, uid)[source]
Disconnect specific remote runtime.
- Parameters:
sender_id (str) –
uid (str) –
- get_event_loop(asyncio_loop=None)[source]
Access event loop.
- Parameters:
asyncio_loop (object, optional) – Async loop to use in our mosaic event loop, defaults to new loop.
- hand(sender_id, address, port)[source]
Handle incoming handshake petition.
- Parameters:
sender_id (str) –
address (str) –
port (int) –
- inc_ref(sender_id, uid, type)[source]
Increase reference count for a resident object.
- Parameters:
sender_id (str) – Caller UID.
uid (str) – UID of the object being referenced.
type (str) – Type of the object being referenced.
- async init_task(sender_id, task, uid)[source]
Create new task for a tessera in this worker.
- Parameters:
sender_id (str) – Caller UID.
task (dict) – Task configuration.
uid (str) – UID of the new task.
- async init_tessera(sender_id, cls, uid, args, **kwargs)[source]
Create tessera in this worker.
- Parameters:
sender_id (str) – Caller UID.
cls (type) – Class of the tessera.
uid (str) – UID of the new tessera.
args (tuple, optional) – Arguments for the initialisation of the tessera.
kwargs (optional) – Keyword arguments for the initialisation of the tessera.
- is_head = False
- is_monitor = False
- is_node = False
- is_warehouse = False
- is_worker = False
- log_debug(sender_id, buf)[source]
Log remote message from
sender_id
on debug stream.- Parameters:
sender_id (str) –
buf (str) –
- log_error(sender_id, buf)[source]
Log remote message from
sender_id
on error stream.- Parameters:
sender_id (str) –
buf (str) –
- log_info(sender_id, buf)[source]
Log remote message from
sender_id
on info stream.- Parameters:
sender_id (str) –
buf (str) –
- log_perf(sender_id, buf)[source]
Log remote message from
sender_id
on perf stream.- Parameters:
sender_id (str) –
buf (str) –
- log_warning(sender_id, buf)[source]
Log remote message from
sender_id
on warning stream.- Parameters:
sender_id (str) –
buf (str) –
- maintenance_msg(method, msg)[source]
Add message to maintenance queue
- Parameters:
method (callable) –
msg (dict) –
- memory_limit()[source]
Amount of RSS memory available to the runtime.
- Returns:
RSS memory.
- Return type:
float
- property nodes
Nodes on the network.
- property num_nodes
Number of nodes on the network.
- property num_workers
Number of workers on the network.
- property port
Port of the runtime.
- static proxy(name=None, indices=(), uid=None)[source]
Generate proxy from name, indices or UID.
- Parameters:
name (str, optional) –
indices (tuple, optional) –
uid (str, optional) –
- proxy_from_uid(uid, proxy=None)[source]
Generate a proxy from a UID.
- Parameters:
uid (str) –
proxy (BaseProxy) –
- Return type:
BaseProxy
- ps_process
- property pubsub_port
Pub-sub port of the runtime.
- async put(obj, publish=False, reply=False)[source]
Put an object into the warehouse.
- Parameters:
obj –
publish –
reply –
- raise_exception(sender_id, exc)[source]
Raise remote exception that ocurred on
sender_id
.- Parameters:
sender_id (str) –
exc (Exception description) –
- recv_profile(sender_id, profiler_update)[source]
Process a profiler update.
- Parameters:
sender_id (str) –
profiler_update (dict) –
- remove_proxy_from_uid(uid, proxy=None)[source]
Remove a proxy from a UID.
- Parameters:
uid (str) –
proxy (BaseProxy) –
- set_comms(address=None, port=None)[source]
Set up comms manager.
- Parameters:
address (str, optional) – Address to use, defaults to None. If None, the comms will try to guess the address.
port (int, optional) – Port to use, defaults to None. If None, the comms will test ports until one becomes available.
- shake(sender_id, network)[source]
Handle handshake response.
- Parameters:
sender_id (str) –
network (dict) –
- wait(wait=False)[source]
Wait on the comms loop until done.
- Parameters:
wait (bool) – Whether or not to wait, defaults to False.
- property workers
Workers on the network.
- class mosaic.runtime.runtime.RuntimeProxy(name=None, indices=(), uid=None, comms=None)[source]
Bases:
BaseRPC
This class represents a proxy to a remote running runtime.
This proxy can be used to execute methods and commands on the remote runtime simply by calling methods on it.
The proxy uses the comms to direct messages to the correct endpoint using its UID.
- Parameters:
name (str, optional) – Name of the runtime, defaults to None. If no name is provided, the UID has to be given.
indices (tuple or int, optional) – Indices associated with the runtime, defaults to none.
uid (str) – UID from which to find the name and indices, defaults to None.
comms (CommsManager) – Comms instance to use, defaults to global comms.
- property address
Remote runtime IP address.
- property comms
- property port
Remote runtime port.
- property pubsub_port
Remote pub-sub port.
- property subprocess
Subprocess on which remote runtime lives, if any.