State
The Faasm runtime ensures this state is shared efficiently across the cluster, takingcare of all underlying replication and synchronisation.
Faasm provides some simple wrappers around state operations, e.g. in C++:
- from pyfaasm.code import faasm_main
- from pyfaasm.state import get_state, set_state
- def my_func():
- # Read the state
- key = "myKey"
- state_val = get_state(key)
- # Do something useful
- # Set an updated value
- set_state(key, state_val)
When operating in parallel on larger state values, it may be unnecessary to loadthe full value into memory for every function instance. For example, many functionsoperating in parallel on a large matrix may only access a few rows or columns each.In this scenario it's unnecessarily expensive and slow to load the full matrix intoevery function.
The low-level offset state operations are part of theFaasm host interface, and explained in more detail in.