Files
fn-serverless/docs/operating/routes.md
James Jeffrey c7f3066c75 Update references remove refs to treeder oracle funcy (#376)
* Remove lots of refs to iron and funcy oracle etc..

* more ref replacements

* Replacing more refs. Treeder

* Use Fn not FN
2017-09-29 16:22:15 -07:00

2.7 KiB

Fn Routes

Routes have a many-to-one mapping to an app.

A good practice to get the best performance on your Fn API is define the required memory for each function.

Route level configuration

When creating a route, you can configure it to tweak its behavior, the possible choices are: memory, type and config.

memory is number of usable MiB for this function. If during the execution it exceeds this maximum threshold, it will halt and return an error in the logs. It expects to be an integer. Default: 128.

type is the type of the function. Either sync, in which the client waits until the request is successfully completed, or async, in which the clients dispatches a new request, gets a call ID back and closes the HTTP connection. Default: sync.

config is a map of values passed to the route runtime in the form of environment variables.

Note: Route level configuration overrides app level configuration.

TODO: link to swagger doc on swaggerhub after it's updated.

Understanding Fn memory management

When Fn starts it registers the total available memory in your system in order to know during its runtime if the system has the required amount of free memory to run each function. Every function starts the runner reduces the amount of memory used by that function from the available memory register. When the function finishes the runner returns the used memory to the available memory register.

Creating function

curl -H "Content-Type: application/json" -X POST -d '{
    "route": {
        "path":"<route name>",
        "image":"<route image>",
        "memory": <memory mb number>,
        "type": "<route type>",
        "config": {"<unique key>": <value>}
    }
}' http://localhost:8080/v1/apps/<app name>/routes

Eg. Creating /myapp/hello with required memory as 100mb, type sync and some container configuration values.

curl -H "Content-Type: application/json" -X POST -d '{
    "route": {
        "path":"/hello",
        "image":"fnproject/hello",
        "memory": 100,
        "type": "sync",
        "config": {"APPLOG": "stderr"}
    }
}' http://localhost:8080/v1/apps/myapp/routes

Updating function

curl -H "Content-Type: application/json" -X POST -d '{
    "route": {
        "memory": <memory mb number>,
        "type": "<route type>",
        "config": {"<unique key>": <value>}
    }
}' http://localhost:8080/v1/apps/<app name>/routes/<route name>

Eg. Updating /myapp/hello required memory as 100mb, type async and changed container configuration values.

curl -H "Content-Type: application/json" -X POST -d '{
    "route": {
        "memory": 100,
        "type": "async",
        "config": {"APPLOG": "stdout"}
    }
}' http://localhost:8080/v1/apps/myapp/routes/hello