Files
fn-serverless/fnlb
Reed Allman e637f9736e back the lb with a db for scale
now we can run multiple lbs in the same 'cluster' and they will all point to
the same nodes. all lb nodes are not guaranteed to have the same set of
functions nodes to route to at any point in time since each lb node will
perform its own health checks independently, but they will all be backed by
the same list from the db to health check at least. in cases where there will
be more than a few lbs we can rethink this strategy, we mostly need to back
the lbs with a db so that they persist nodes and remain fault tolerant in that
sense. the strategy of independent health checks is useful to reduce thrashing
the db during network partitions between lb and fn pairs. it would be nice to
have gossip health checking to reduce network traffic, but this works too, and
we'll need to seed any gossip protocol with a list from a db anyway.

db_url is the same format as what functions takes. i don't have env vars set
up for fnlb right now (low hanging fruit), the flag is `-db`, it defaults to
in memory sqlite3 so nodes will be forgotten between reboots. used the sqlx
stuff, decided not to put the lb stuff in the datastore stuff as this was easy
enough to just add here to get the sugar, and avoid bloating the datastore
interface. the tables won't collide, so can just use same pg/mysql as what the
fn servers are running in prod even, db load is low from lb (1 call every 1s
per lb).

i need to add some tests, touch testing worked as expected.
2017-07-07 07:45:17 -07:00
..
2017-07-07 07:45:17 -07:00
2017-06-28 20:41:16 -07:00
2017-07-07 07:45:17 -07:00

Oracle Functions LoadBalancer

Loadbalancing several Oracle Functions

You can run multiple Oracle Functions instances and balance the load amongst them using fnlb as follows:

fnlb --listen <address-for-incoming> --nodes <node1>,<node2>,<node3>

And redirect all traffic to the load balancer.

NOTE: For the load balancer to be of use, all function nodes need to be sharing the same DB.

Running with docker

To build a docker image for fnlb just run (in fnlb/):

make docker-build

To start the fnlb proxy with the addresses of functions nodes in a docker container:

docker run -d --name fnlb -p 8081:8081 funcy/fnlb:latest --nodes <node1>,<node2>

If running locally with functions servers in docker, running with docker links can make things easier (can use local addresses). for example:

docker run -d --name fn-8080 --privileged -p 8080:8080 funcy/functions:latest
docker run -d --name fnlb --link fn-8080 -p 8081:8081 funcy/fnlb:latest --nodes 127.0.0.1:8080

Operating / usage

To make functions requests against the lb with the cli:

API_URL=http://<fnlb_address> fn call my/function

To add a functions node later:

curl -sSL -X PUT -d '{"node":"<node>"}' <fnlb_address>/1/lb/nodes

<node> should be the address of a functions server. The lb will health check this and log if it cannot reach that node as well as stop sending requests to that node until it begins passing health checks again. Any number of functions servers may be added to the load balancer.

To permanently remove a functions node:

curl -sSL -X DELETE -d '{"node":"<node>"}' <fnlb_address>/1/lb/nodes

To list functions nodes and their state:

curl -sSL -X GET <fnlb_address>/1/lb/nodes