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++:

    1. from pyfaasm.code import faasm_main
    2. from pyfaasm.state import get_state, set_state
    3.  
    4. def my_func():
    5. # Read the state
    6. key = "myKey"
    7. state_val = get_state(key)
    8. # Do something useful
    9.  
    10. # Set an updated value
    11. 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.