Fn's architecture

The easiest setup of an Fn Server is just bringing up a standalone Fn container; however, the more complete architecture will be as shown here. A cluster implementation will be demonstrated at the end of this chapter. The following diagram shows the overview of the Fn architecture:

Figure 5.1: The architecture of the Fn FaaS cluster

As is the case with the common FaaS architecture, Fn also has the API gateway, which is Fn LB in the previous diagram. Fn LB is basically a load balancer. It passes through requests from the client to each Fn Server. In the Fn Server implementation, there is no separation concept of initiator and executor as there is no event bus at the core of the Fn's architecture. So, an Fn Server also acts as an executor to execute functions on its associate Docker engine.

Fn Servers connect to a Log Store, which could be a standalone or a cluster of DBMS. All data sent from an Fn function to the standard error is logged to the Log Store.

Fn UI and Fn LB are extra components to help make the Fn Project better in terms of production. The Fn UI is the user interface server, such as dashboard, for Fn, while Fn LB is the load balancer to round robin among Fn nodes in the cluster.

There is a concept of an Executor Agent inside the Fn Server. The agent is responsible for controlling the runtime. In the case of Fn, the runtime is Docker. So, the executor agent is also referred as a Docker agent in this chapter. With the default configuration, the Docker agent inside an Fn Server connects to the local Docker engine and starts Fn functions via a local Unix socket:

Figure 5.2: A diagram showing an Fn cluster over a Swarm-scoped network

The previous diagram shows a running Fn cluster over a Swarm-scoped overlay network. To form a cluster, we will use an attachable Swarm-scoped network. Each Fn Server instance has to attach to the network. When a request is made to the gateway or directly to the server, it will be passed through to the EntryPoint. The EntryPoint is a language-specific program that wraps around the real function program. For example, in the case of an Fn function built with Java, the EntryPoint is the class com.fnproject.fn.runtime.EntryPoint. There is a code inside this Java class to invoke the real function via Java's reflection technique:

Figure 5.3: An Fn function interacting with STDIN, STDOUT, and writing logs to STDERR, where it delegates logs to the store

The Fn Server sends the request body in the form of STDIN to the Function container. After the EntryPoint receives the STDIN stream, it converts the data content to match the type of function signature. In the previous diagram, the signature is String. So the function body is converted to a string. Output sent to STDOUT will be forwarded to the Fn Server and sent out as the result, while output sent to STDERR will be captured and stored in the Log Store.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset