Skip to content

Latest commit

 

History

History
55 lines (40 loc) · 2.46 KB

File metadata and controls

55 lines (40 loc) · 2.46 KB

Threading

Serverless applications benefit most from the parallelism of many small functions distributed across hosts. Spawning one or two threads to do background work still makes sense, but using threading and shared memory to parallelise a larger application is not necessarily effective in a serverless context.

To support larger multi-threaded applications, Faasm can transparently distribute threads across multiple serverless functions, thus allowing them to take advantage of serverless parallelism.

This functionality is accessed in C/C++ through pthreads and OpenMP. Faasm intercepts normal threading calls and chains a new serverless function to execute the thread, potentially on another host. Shared data is managed with shared state and the process memory is migrated across hosts with Proto-Faaslets.

pthreads

Faasm supports the following pthread functions. Although all pthread_attr_XXX calls are supported, the attributes themselves may be ignored in a Faasm context.

Function Description
int pthread_create(...) Spawn a new thread
int pthread_join(...) Await thread completion
void pthread_exit(...) Exit the current thread
void pthread_attr_XXX All attr-related calls

OpenMP

Faasm OpenMP support has separate docs.

Threading modes

Faasm has two threading modes, local and chain, which are configured with the THREAD_MODE environment variable. In local mode, threads are spawned locally,
operating on the same Wasm module memory as per the Wasm threading proposal and using WAVM's underlying implementation.

In chain mode, Faasm spawns all new threads as chained function calls, which may or may not execute on the same host.

Migrating threads across hosts

Threads are migrated across hosts using a version of Proto-Faaslets, which duplicate a function's memory and execution state on another host. This provides the function on the other host with a copy of the heap, stack and data from its parent function, thus letting it continue thread-like execution and read any shared data.

Writes to global variables and shared memory are not propagated across distributed threads automatically, and must be handled explicitly with Faasm's shared state.

An example of a distributed threaded application can be found in the examples.