3 # Copyright 2024 Nordix Foundation.
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
9 # http://www.apache.org/licenses/LICENSE-2.0
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.
18 # This script measures the performance of NCMP data passthrough operations:
19 # NCMP endpoint tested: /ncmp/v1/ch/{cmHandleId}/data/ds/{datastoreName}
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
26 ############################
27 # Configuration parameters #
28 ############################
32 CPS_PASSWORD=cpsr0cks!
35 MEASUREMENT_REQUESTS=240
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]+')
41 function cmHandleExists() {
43 curl --silent --fail --output /dev/null --user "$CPS_USERNAME:$CPS_PASSWORD" --basic "http://$CPS_HOST:$CPS_PORT/ncmp/v1/ch/$cmHandleId"
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
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
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; }'
75 failIfCmHandlesNotFound
76 warnIfLessThan20kCmHandlesFound
79 echo "Warming up ($WARMUP_REQUESTS requests, ignoring results)"
80 measureAverageResponseTimeInMillis "$WARMUP_REQUESTS" > /dev/null
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)
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"