github.com/iron-io/functions@v0.0.0-20180820112432-d59d7d1c40b2/test/fnlb-test-harness/README.md (about)

     1  # fnlb-test-harness
     2  Test harness that exercises the fnlb load balancer in order to verify that it works properly.
     3  ## How it works
     4  This is a test harness that makes calls to an IronFunctions route through the fnlb load balancer, which routes traffic to multiple IronFunctions nodes.
     5  The test harness keeps track of which node each request was routed to so we can assess how the requests are being distributed across the nodes.  The functionality
     6  of fnlb is to normally route traffic to the same small number of nodes so that efficiences can be achieved and to support reuse of hot functions.
     7  ### Primes function
     8  The test harness utilizes the "primes" function, which calculates prime numbers as an excuse for consuming CPU resources.  The function is invoked as follows:
     9  ```
    10  curl http://host:8080/r/primesapp/primes?max=1000000&loops=1
    11  ```
    12  where:
    13  - *max*: calculate all primes <= max (increasing max will increase memory usage, due to the Sieve of Eratosthenes algorithm)
    14  - *loops*: number of times to calculate the primes (repeating the count consumes additional CPU without consuming additional memory)
    15  
    16  ## How to use it
    17  The test harness requires running one or more IronFunctions nodes and one instance of fnlb.  The list of nodes must be provided both to fnlb and to the test harness
    18  because the test harness must call each node directly one time in order to discover the node's container id.
    19  
    20  After it has run, examine the results to see how the requests were distributed across the nodes.
    21  ### How to run it locally
    22  Each of the IronFunctions nodes needs to connect to the same database.
    23  
    24  STEP 1: Create a route for the primes function.  Example:
    25  ```
    26  fn apps create primesapp
    27  fn routes create primesapp /primes jconning/primes:0.0.1
    28  ```
    29  STEP 2: Run five IronFunctions nodes locally.  Example (runs five nodes in the background using Docker):
    30  ```
    31  sudo docker run -d -it --name functions-8082 --privileged -v ${HOME}/data-8082:/app/data -p 8082:8080 -e "DB_URL=postgres://dbUser:dbPassword@dbHost:5432/dbName" iron/functions
    32  sudo docker run -d -it --name functions-8083 --privileged -v ${HOME}/data-8083:/app/data -p 8083:8080 -e "DB_URL=postgres://dbUser:dbPassword@dbHost:5432/dbName" iron/functions
    33  sudo docker run -d -it --name functions-8084 --privileged -v ${HOME}/data-8084:/app/data -p 8084:8080 -e "DB_URL=postgres://dbUser:dbPassword@dbHost:5432/dbName" iron/functions
    34  sudo docker run -d -it --name functions-8085 --privileged -v ${HOME}/data-8085:/app/data -p 8085:8080 -e "DB_URL=postgres://dbUser:dbPassword@dbHost:5432/dbName" iron/functions
    35  sudo docker run -d -it --name functions-8086 --privileged -v ${HOME}/data-8086:/app/data -p 8086:8080 -e "DB_URL=postgres://dbUser:dbPassword@dbHost:5432/dbName" iron/functions
    36  ```
    37  STEP 3: Run fnlb locally.  Example (runs fnlb on the default port 8081):
    38  ```
    39  fnlb -nodes localhost:8082,localhost:8083,localhost:8084,localhost:8085,localhost:8086
    40  ```
    41  STEP 4: Run the test harness.  Note that the 'nodes' parameter should be the same that was used with fnlb.  Example:
    42  ```
    43  cd functions/test/fnlb-test-harness
    44  go run main.go -nodes localhost:8082,localhost:8083,localhost:8084,localhost:8085,localhost:8086 -calls 10 -v
    45  ```
    46  STEP 5: Examine the output to determine how many times fnlb called each node.  Assess whether it is working properly.
    47  
    48  ### Usage
    49  go run main.go -help
    50  
    51  <i>Command line parameters:</i>
    52  - *-calls*: number of times to call the route (default 100)
    53  - *-lb*: host and port of load balancer (default "localhost:8081")
    54  - *-loops*: number of times to execute the primes calculation (ex: '-loops 2' means run the primes calculation twice) (default 1)
    55  - *-max*: maximum number to search for primes (higher number consumes more memory) (default 1000000)
    56  - *-nodes*: comma-delimited list of nodes (host:port) balanced by the load balancer (needed to discover container id of each) (default "localhost:8080")
    57  - *-route*: path representing the route to the primes function (default "/r/primesapp/primes")
    58  - *-v*: flag indicating verbose output
    59  
    60  ### Examples: quick vs long running
    61  
    62  **Quick function:**: calculate primes up to 1000
    63  ```
    64  go run main.go -nodes localhost:8082,localhost:8083,localhost:8084,localhost:8085,localhost:8086 -max 1000 -v
    65  ```
    66  where *-max* is default of 1M, *-calls* is default of 100, *-route* is default of "/r/primesapp/primes", *-lb* is default localhost:8081
    67  
    68  **Normal function**: calculate primes up to 1M
    69  ```
    70  go run main.go -nodes localhost:8082,localhost:8083,localhost:8084,localhost:8085,localhost:8086 -v
    71  ```
    72  where *-max* is default of 1M, *-calls* is default of 100, *-route* is default of "/r/primesapp/primes", *-lb* is default localhost:8081
    73  
    74  **Longer running function**: calculate primes up to 1M and perform the calculation ten times
    75  ```
    76  go run main.go -nodes localhost:8082,localhost:8083,localhost:8084,localhost:8085,localhost:8086 -loops 10 -v
    77  ```
    78  where *-max* is default of 1M, *-calls* is default of 100, *-route* is default of "/r/primesapp/primes", *-lb* is default localhost:8081
    79  
    80  **1000 calls to the route**: send 1000 requests through the load balancer
    81  ```
    82  go run main.go -nodes localhost:8082,localhost:8083,localhost:8084,localhost:8085,localhost:8086 -calls 1000 -v
    83  ```
    84  where *-max* is default of 1M, *-calls* is default of 100, *-route* is default of "/r/primesapp/primes", *-lb* is default localhost:8081
    85  
    86  ## Planned Enhancements
    87  - Create 1000 routes and distribute calls amongst them.
    88  - Use concurrent programming to enable the test harness to call multiple routes at the same time.