blob: 21b031ce95035e787322381455473b81b281c291 [file] [log] [blame]
danielhanrahan55438752023-11-29 18:51:16 +00001#!/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
21set -o errexit # Exit on most errors
22set -o nounset # Disallow expansion of unset variables
23set -o pipefail # Use last non-zero exit code in a pipeline
24#set -o xtrace # Uncomment for debugging
25
26############################
27# Configuration parameters #
28############################
29CPS_HOST=localhost
30CPS_PORT=8883
31CPS_USERNAME=cpsuser
32CPS_PASSWORD=cpsr0cks!
33PARALLEL_REQUESTS=12
34WARMUP_REQUESTS=600
35MEASUREMENT_REQUESTS=240
36
37SCRIPT_DIR=$(dirname -- "${BASH_SOURCE[0]}")
38# Read DMI delay from docker-compose.yml
39DMI_DATA_DELAY=$(grep 'DATA_FOR_CM_HANDLE_DELAY_MS:' "$SCRIPT_DIR"/../docker-compose/docker-compose.yml | grep -oE '[0-9]+')
40
41function 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
46function 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
57function 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
64function 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
75failIfCmHandlesNotFound
76warnIfLessThan20kCmHandlesFound
77
78# Do JVM warmup
79echo "Warming up ($WARMUP_REQUESTS requests, ignoring results)"
80measureAverageResponseTimeInMillis "$WARMUP_REQUESTS" > /dev/null
81
82# Measure performance
83echo "Measuring average time of $MEASUREMENT_REQUESTS total requests, sending $PARALLEL_REQUESTS requests in parallel"
84ncmpResponseTime=$(measureAverageResponseTimeInMillis "$MEASUREMENT_REQUESTS")
85ncmpOverhead=$(echo "$ncmpResponseTime - $DMI_DATA_DELAY" | bc)
86
87# Report performance
88echo "Average response time from NCMP: $ncmpResponseTime ms"
89echo "Average response time from DMI: $DMI_DATA_DELAY ms"
90echo "NCMP overhead: $ncmpOverhead ms"