Load Balancing


Load Balancing is the act of choosing which system in a cluster to execute the start or schedule data on.  The final result of load balancing is the selection of the server.  The Webserver server then sends the object to the Launcher server to start the session.

Built In Load Balancers

FastX ships with several built in load balancers to simplify standard load balancing algorithms

Admin > Sessions > Launcher > Load Balancing

  • Fewest Sessions — return node with lowest number of sessions
  • Most Available Memory — return node with the most free RAM
  • Round Robin — evenly distribute the launcher sessions
  • Custom — Use a custom load balancer

Custom Load Balancers

Admins can create custom load balancing scripts. In FastX 4, the load balancer script is a custom executable script that the admin writes. Set the following environment variables in $FX_CONFIG_DIR/fastx.env

  • LOAD_BALANCER=custom — set the load balancer to custom
  • LOAD_BALANCER_SCRIPT=/path/to/your/script — custom script to use for load balancing

Output

The goal is to return a nodeID on stdout.

Script Input

The load balancer script will send the following input to stdin as a JSON string.

{
   "nodes": [<node1>, <node2>, ... <nodeN>],
   "params": <input object>
}

Node Object

The node object is a JSON object with data of a system that has a launcher service running on it. There are many parameters in each node, but the ones that matter are listed below

{
  "id": "node_id",
  "nodeData": {
    "health": <health>,
    "services": [<service1>,<service2>, ... <serviceN> ]
    "sessions": [ <session1>, <session2>, ... <sessionN> ]
  },
  metadata: {}
}
  • health — node health data
  • services — list of services on the node
  • sessions — array of session data objects
  • metadata — metadata object. Object parameters are set by setting the METADATA_<NAME> environment variable in the environment and then restarting the service

Params Object

{
  "me": <user-object>,
  "start": <start-object>,
  "jwt": <json-web-token>
}