danielhanrahan | 5543875 | 2023-11-29 18:51:16 +0000 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # Copyright 2024 Nordix Foundation. |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | # |
| 17 | |
| 18 | # This script measures the performance of NCMP data passthrough operations: |
| 19 | # NCMP endpoint tested: /ncmp/v1/ch/{cmHandleId}/data/ds/{datastoreName} |
| 20 | |
| 21 | set -o errexit # Exit on most errors |
| 22 | set -o nounset # Disallow expansion of unset variables |
| 23 | set -o pipefail # Use last non-zero exit code in a pipeline |
| 24 | #set -o xtrace # Uncomment for debugging |
| 25 | |
| 26 | ############################ |
| 27 | # Configuration parameters # |
| 28 | ############################ |
| 29 | CPS_HOST=localhost |
| 30 | CPS_PORT=8883 |
| 31 | CPS_USERNAME=cpsuser |
| 32 | CPS_PASSWORD=cpsr0cks! |
| 33 | PARALLEL_REQUESTS=12 |
| 34 | WARMUP_REQUESTS=600 |
| 35 | MEASUREMENT_REQUESTS=240 |
| 36 | |
| 37 | SCRIPT_DIR=$(dirname -- "${BASH_SOURCE[0]}") |
| 38 | # Read DMI delay from docker-compose.yml |
| 39 | DMI_DATA_DELAY=$(grep 'DATA_FOR_CM_HANDLE_DELAY_MS:' "$SCRIPT_DIR"/../docker-compose/docker-compose.yml | grep -oE '[0-9]+') |
| 40 | |
| 41 | function cmHandleExists() { |
| 42 | local cmHandleId=$1 |
| 43 | curl --silent --fail --output /dev/null --user "$CPS_USERNAME:$CPS_PASSWORD" --basic "http://$CPS_HOST:$CPS_PORT/ncmp/v1/ch/$cmHandleId" |
| 44 | } |
| 45 | |
| 46 | function failIfCmHandlesNotFound() { |
| 47 | # Just check to see if last needed CM-handle exists |
| 48 | local MAX_NEEDED_CM_HANDLES=$((WARMUP_REQUESTS > MEASUREMENT_REQUESTS ? WARMUP_REQUESTS : MEASUREMENT_REQUESTS)) |
| 49 | local cmHandleId="ch-$MAX_NEEDED_CM_HANDLES" |
| 50 | if ! cmHandleExists "$cmHandleId"; then |
| 51 | echo "ERROR: CM-handles not registered ($cmHandleId not found)" >&2 |
| 52 | echo "Note: this test assumes CM-handles have IDs ch-1, ch-2... ch-$MAX_NEEDED_CM_HANDLES" >&2 |
| 53 | exit 1 |
| 54 | fi |
| 55 | } |
| 56 | |
| 57 | function warnIfLessThan20kCmHandlesFound() { |
| 58 | local cmHandleId='ch-20000' |
| 59 | if ! cmHandleExists "$cmHandleId"; then |
| 60 | echo "WARNING: testing with less than 20,000 CM-handles is not recommended ($cmHandleId not found)" >&2 |
| 61 | fi |
| 62 | } |
| 63 | |
| 64 | function measureAverageResponseTimeInMillis() { |
| 65 | local totalRequests=$1 |
| 66 | curl --show-error --fail --fail-early \ |
| 67 | --output /dev/null --write-out '%{time_total}\n' \ |
| 68 | --parallel --parallel-max $PARALLEL_REQUESTS --parallel-immediate \ |
| 69 | --user "$CPS_USERNAME:$CPS_PASSWORD" --basic \ |
| 70 | --request POST "http://$CPS_HOST:$CPS_PORT/ncmp/v1/ch/ch-[1-$totalRequests]/data/ds/ncmp-datastore%3Apassthrough-operational?resourceIdentifier=x&include-descendants=true" | |
| 71 | awk '{ sum += $1; n++ } END { if (n > 0) print (sum / n) * 1000; }' |
| 72 | } |
| 73 | |
| 74 | # Sanity checks |
| 75 | failIfCmHandlesNotFound |
| 76 | warnIfLessThan20kCmHandlesFound |
| 77 | |
| 78 | # Do JVM warmup |
| 79 | echo "Warming up ($WARMUP_REQUESTS requests, ignoring results)" |
| 80 | measureAverageResponseTimeInMillis "$WARMUP_REQUESTS" > /dev/null |
| 81 | |
| 82 | # Measure performance |
| 83 | echo "Measuring average time of $MEASUREMENT_REQUESTS total requests, sending $PARALLEL_REQUESTS requests in parallel" |
| 84 | ncmpResponseTime=$(measureAverageResponseTimeInMillis "$MEASUREMENT_REQUESTS") |
| 85 | ncmpOverhead=$(echo "$ncmpResponseTime - $DMI_DATA_DELAY" | bc) |
| 86 | |
| 87 | # Report performance |
| 88 | echo "Average response time from NCMP: $ncmpResponseTime ms" |
| 89 | echo "Average response time from DMI: $DMI_DATA_DELAY ms" |
| 90 | echo "NCMP overhead: $ncmpOverhead ms" |