Skip to content

Latest commit

 

History

History
204 lines (172 loc) · 7.96 KB

File metadata and controls

204 lines (172 loc) · 7.96 KB

Scripting hyperfoil with quarkus getting started

The curl command from Scripting Quarkus getting started was a substitute for the load generator. We are going to use Hyperfoil to drive the load to our quarkus application and use qDup phases to coordinate the test.

Introduction

This tutorial will introduce:

Prerequisites

qDup connects to computers through ssh. You need to have a computer that will accept ssh connections. You can setup ssh on your own computer by following the steps in the prerequisites

Running the experiment

The script will clone the quarkus-quickstarts repository, install quarkus-cli if needed, and, start the application. In parallel, it will download and install Hyperfoil. Once the application is ready, it will start a simple benchmark. In the end, it will download the result and stop the quarkus-quickstarts application.

#> cat > hyperfoil.yaml << 'EOF'
scripts:
  setup-hyperfoil:
  - sh: cd /tmp
  - sh: mkdir hyperfoil-data
  - sh: >
      wget https://github.com/Hyperfoil/Hyperfoil/releases/download/hyperfoil-all-0.27.1/hyperfoil-0.27.1.zip
      && unzip hyperfoil-0.27.1.zip
      && cd hyperfoil-0.27.1
  - sh: "sed -i 's|http://hyperfoil.io|http://localhost:8080|g' examples/single-request.hf.yaml"
  - sh: export HYPERFOIL_HOME=$(pwd)

  test-endpoint:
  - wait-for: ready
    then:
      - sh: cd $HYPERFOIL_HOME
      - add-prompt: "[hyperfoil]$ "
      - sh: ./bin/cli.sh
      - add-prompt: "[hyperfoil@in-vm]$ " #do not forget the space
      - sh: start-local
      - sh: upload examples/single-request.hf.yaml
      - sh: run single-request
      - sh: export 0000 --destination=/tmp/hyperfoil-data/report.json
      - sh: report 0000 --destination=/tmp/hyperfoil-data/report.html
      - queue-download: /tmp/hyperfoil-data/report.json
      - queue-download: /tmp/hyperfoil-data/report.html
      - signal: done

  remove-hyperfoil:
  - sh: cd /tmp && rm -fR hyperfoil*

  setup-getting-started:
  - sh: cd /tmp/
  - sh: "[[ ! -d quarkus-quickstarts ]] && git clone https://github.com/quarkusio/quarkus-quickstarts.git"
  - sh: cd quarkus-quickstarts
  - sh: cd getting-started
  - script: ensure-quarkus-cli
  - sh: export GETTING_STARTED_DIR="$(pwd)" #set an environment variable

  ensure-quarkus-cli:
  - sh: quarkus version
    then:
    - regex: "command not found"
      then:
      - sh: "curl -Ls https://sh.jbang.dev | bash -s - trust add https://repo1.maven.org/maven2/io/quarkus/quarkus-cli/"
      - sh: "curl -Ls https://sh.jbang.dev | bash -s - app install --fresh --force quarkus@quarkusio"
      - sh: "source ~/.bashrc"

  run-getting-started:
  - sh: cd $GETTING_STARTED_DIR #ensure we are in the correct directory
  - sh:
      command: quarkus dev
      prompt:
        "Press [e] to edit command line args (currently ''), [r] to resume testing, [o] Toggle test output, [:] for the terminal, [h] for more options>": "r"
    watch:
    - regex: "Tests completed"
      then:
      - signal: ready
    on-signal:
      done:
      - ctrlC
hosts:
  test: ${{target-host}}
roles:
  setup:
    hosts:
    - test
    setup-scripts:
    - setup-getting-started
    run-scripts:
    - run-getting-started
  hyperfoil:
    hosts:
    - test
    setup-scripts:
    - setup-hyperfoil
    run-scripts:
    - test-endpoint
    cleanup-scripts:
    - remove-hyperfoil
EOF

Run with java -jar qDup-0.8.5-uber.jar -i ~/.ssh/qdup hyperfoil.yaml -ix -S target-host=$USER@localhost.

Splitting the roles

The previous tutorial created a role to run all of ours scripts. This works but a proper performance test will normally isolate the load generator from the process we are testing. qDup isolates scripts by assigning them to roles that are running on different hosts. To isolate test-endpoint from run-getting-started we need to introduce a second role. Let us call it hyperfoil. The roles section will now look like the following:

roles:
  setup:
    hosts:
    - test
    setup-scripts:
    - setup-getting-started
    run-scripts:
    - run-getting-started
  hyperfoil:
    hosts:
    - test
    setup-scripts:
    - setup-hyperfoil
    run-scripts:
    - test-endpoint
    cleanup-scripts:
    - remove-hyperfoil
Note
We are only running an ssh server on one computer so we still use the test host for both roles but now we could split them if needed.

Hyperfoil role

We named the new role hyperfoil.

setup-hyperfoil

The qDup script will download and install Hyperfoil locally. The single-request.hf.yaml has http://hyperfoil.io as a target and the script will replace to http://localhost:8080 (the endpoint that our application is running) using sed

- sh: "sed -i 's|http://hyperfoil.io|http://localhost:8080|g' examples/single-request.hf.yaml"

test-endpoint

The next command is to run > bin/cli.sh. Notice how it starts an interactive shell and changes the prompt.

qDup uses a custom prompt to detect when commands finish running. We are going to use the qDup add-prompt command to tell qDup that there is another prompt that indicates the command is finished.

  - add-prompt: "[hyperfoil]$ "
  - sh: ./bin/cli.sh

The next command in the guide is start-local. This is a command inside the hyperfoil cli but because we used add-prompt we can include it as though it is a normal shell command.

[hyperfoil]$ start-local
Starting controller in default directory (/tmp/hyperfoil)
Controller started, listening on 127.0.0.1:40041
Connecting to the controller...
Connected to 127.0.0.1:40041!
[hyperfoil@in-vm]$

It changes the prompt again. We are going to add another add-prompt

  - add-prompt: "[hyperfoil@in-vm]$ " #do not forget the space
  - sh: start-local
Note
qDup looks for the prompt at then of the ssh connection. We could combine the two prompts to `]$ ` but a short pattern could incorrectly match part of a command’s output and break the script.

The next step in the hyperfoil guide is to upload the test definition and start the performance test

  - sh: upload examples/single-request.hf.yaml
  - sh: run single-request

The hyperfoil guide tells us about the stats command to see a run summary. We want to save the results with the qDup output files. Hyperfoil can export the run data and generate a report so we will add them both to our script and queue-download both files.

  - sh: export 0000 --destination=/tmp/report.json
  - sh: report 0000 --destination=/tmp/report.html
  - queue-download: /tmp/report.json
  - queue-download: /tmp/report.html

Setup, Run, and Cleanup

Notice how we added an sh: export …​ at the end of setup-getting-started and an sh: cd …​ at the beginning of run-getting-started. qDup tracks changes to environment variables during setup-scripts and will apply those same environment variable changes to all scripts in the same role. Our updated role now has 2 scripts:

roles:
  setup:
    hosts:
    - test
    setup-scripts:
    - setup-getting-started
    run-scripts:
    - run-getting-started

Our test-endpoint script assumes that the hyperfoil run ID is always 0000 but that will only be true if it is the first time we ran a test using that hyperfoil setup. We could introduce regex to identify the run ID from run single-request but instead we will remove the Hyperfoil setup in a cleanup-script. We are removing all the artifacts stored by this setup in order to allow you to rerun the script multiple times.

  remove-hyperfoil:
  - sh: cd /tmp && rm -fR hyperfoil*

Next steps

The next tutorial demonstrates how to troubleshoot scripts. There is an integrated debug server in the qDup process which helps with both inspecting the running qDup commands and interacting with them to troubleshoot problems.