]> git.proxmox.com Git - ceph.git/blame - ceph/src/spdk/test/iscsi_tgt/qos/qos.sh
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / spdk / test / iscsi_tgt / qos / qos.sh
CommitLineData
11fdf7f2
TL
1#!/usr/bin/env bash
2
3testdir=$(readlink -f $(dirname $0))
4rootdir=$(readlink -f $testdir/../../..)
5source $rootdir/test/common/autotest_common.sh
6source $rootdir/test/iscsi_tgt/common.sh
7
9f95a23c
TL
8# $1 = "iso" - triggers isolation mode (setting up required environment).
9# $2 = test type posix or vpp. defaults to posix.
10iscsitestinit $1 $2
11
12function run_fio() {
13 local bdev_name=$1
f67539c2
TL
14 local iostats
15 local start_io_count
16 local start_bytes_read
17 local end_io_count
18 local end_bytes_read
9f95a23c
TL
19 local run_time=5
20
f67539c2
TL
21 iostats=$($rpc_py bdev_get_iostat -b $bdev_name)
22 start_io_count=$(jq -r '.bdevs[0].num_read_ops' <<< "$iostats")
23 start_bytes_read=$(jq -r '.bdevs[0].bytes_read' <<< "$iostats")
9f95a23c
TL
24
25 $fio_py -p iscsi -i 1024 -d 128 -t randread -r $run_time
26
f67539c2
TL
27 iostats=$($rpc_py bdev_get_iostat -b $bdev_name)
28 end_io_count=$(jq -r '.bdevs[0].num_read_ops' <<< "$iostats")
29 end_bytes_read=$(jq -r '.bdevs[0].bytes_read' <<< "$iostats")
9f95a23c 30
f67539c2
TL
31 IOPS_RESULT=$(((end_io_count - start_io_count) / run_time))
32 BANDWIDTH_RESULT=$(((end_bytes_read - start_bytes_read) / run_time))
9f95a23c
TL
33}
34
35function verify_qos_limits() {
36 local result=$1
37 local limit=$2
38
f67539c2
TL
39 [ "$(bc <<< "$result > $limit*0.85")" -eq 1 ] \
40 && [ "$(bc <<< "$result < $limit*1.05")" -eq 1 ]
11fdf7f2
TL
41}
42
43if [ -z "$TARGET_IP" ]; then
44 echo "TARGET_IP not defined in environment"
45 exit 1
46fi
47
48if [ -z "$INITIATOR_IP" ]; then
49 echo "INITIATOR_IP not defined in environment"
50 exit 1
51fi
52
11fdf7f2
TL
53MALLOC_BDEV_SIZE=64
54MALLOC_BLOCK_SIZE=512
9f95a23c
TL
55IOPS_RESULT=
56BANDWIDTH_RESULT=
11fdf7f2
TL
57rpc_py="$rootdir/scripts/rpc.py"
58fio_py="$rootdir/scripts/fio.py"
59
60timing_enter start_iscsi_tgt
61
f67539c2 62"${ISCSI_APP[@]}" &
11fdf7f2
TL
63pid=$!
64echo "Process pid: $pid"
f67539c2 65trap 'killprocess $pid; iscsitestfini $1 $2; exit 1' SIGINT SIGTERM EXIT
11fdf7f2
TL
66waitforlisten $pid
67echo "iscsi_tgt is listening. Running tests..."
68
69timing_exit start_iscsi_tgt
70
f67539c2
TL
71$rpc_py iscsi_create_portal_group $PORTAL_TAG $TARGET_IP:$ISCSI_PORT
72$rpc_py iscsi_create_initiator_group $INITIATOR_TAG $INITIATOR_NAME $NETMASK
73$rpc_py bdev_malloc_create $MALLOC_BDEV_SIZE $MALLOC_BLOCK_SIZE
11fdf7f2
TL
74# "Malloc0:0" ==> use Malloc0 blockdev for LUN0
75# "1:2" ==> map PortalGroup1 to InitiatorGroup2
76# "64" ==> iSCSI queue depth 64
77# "-d" ==> disable CHAP authentication
f67539c2 78$rpc_py iscsi_create_target_node Target1 Target1_alias 'Malloc0:0' $PORTAL_TAG:$INITIATOR_TAG 64 -d
11fdf7f2
TL
79sleep 1
80
81iscsiadm -m discovery -t sendtargets -p $TARGET_IP:$ISCSI_PORT
82iscsiadm -m node --login -p $TARGET_IP:$ISCSI_PORT
83
f67539c2 84trap 'iscsicleanup; killprocess $pid; iscsitestfini $1 $2; exit 1' SIGINT SIGTERM EXIT
9f95a23c
TL
85
86# Run FIO without any QOS limits to determine the raw performance
87run_fio Malloc0
88
89# Set IOPS/bandwidth limit to 50% of the actual unrestrained performance.
f67539c2
TL
90IOPS_LIMIT=$((IOPS_RESULT / 2))
91BANDWIDTH_LIMIT=$((BANDWIDTH_RESULT / 2))
9f95a23c
TL
92# Set READ bandwidth limit to 50% of the RW bandwidth limit to be able
93# to differentiate those two.
f67539c2 94READ_BANDWIDTH_LIMIT=$((BANDWIDTH_LIMIT / 2))
9f95a23c
TL
95
96# Also round them down to nearest multiple of either 1000 IOPS or 1MB BW
97# which are the minimal QoS granularities
f67539c2
TL
98IOPS_LIMIT=$((IOPS_LIMIT / 1000 * 1000))
99BANDWIDTH_LIMIT_MB=$((BANDWIDTH_LIMIT / 1024 / 1024))
100BANDWIDTH_LIMIT=$((BANDWIDTH_LIMIT_MB * 1024 * 1024))
101READ_BANDWIDTH_LIMIT_MB=$((READ_BANDWIDTH_LIMIT / 1024 / 1024))
102READ_BANDWIDTH_LIMIT=$((READ_BANDWIDTH_LIMIT_MB * 1024 * 1024))
11fdf7f2
TL
103
104# Limit the I/O rate by RPC, then confirm the observed rate matches.
f67539c2 105$rpc_py bdev_set_qos_limit Malloc0 --rw_ios_per_sec $IOPS_LIMIT
9f95a23c
TL
106run_fio Malloc0
107verify_qos_limits $IOPS_RESULT $IOPS_LIMIT
11fdf7f2
TL
108
109# Now disable the rate limiting, and confirm the observed rate is not limited anymore.
f67539c2 110$rpc_py bdev_set_qos_limit Malloc0 --rw_ios_per_sec 0
9f95a23c
TL
111run_fio Malloc0
112[ "$IOPS_RESULT" -gt "$IOPS_LIMIT" ]
11fdf7f2
TL
113
114# Limit the I/O rate again.
f67539c2 115$rpc_py bdev_set_qos_limit Malloc0 --rw_ios_per_sec $IOPS_LIMIT
9f95a23c
TL
116run_fio Malloc0
117verify_qos_limits $IOPS_RESULT $IOPS_LIMIT
118
11fdf7f2
TL
119echo "I/O rate limiting tests successful"
120
9f95a23c 121# Limit the I/O bandwidth rate by RPC, then confirm the observed rate matches.
f67539c2 122$rpc_py bdev_set_qos_limit Malloc0 --rw_ios_per_sec 0 --rw_mbytes_per_sec $BANDWIDTH_LIMIT_MB
9f95a23c
TL
123run_fio Malloc0
124verify_qos_limits $BANDWIDTH_RESULT $BANDWIDTH_LIMIT
125
126# Now disable the bandwidth rate limiting, and confirm the observed rate is not limited anymore.
f67539c2 127$rpc_py bdev_set_qos_limit Malloc0 --rw_mbytes_per_sec 0
9f95a23c
TL
128run_fio Malloc0
129[ "$BANDWIDTH_RESULT" -gt "$BANDWIDTH_LIMIT" ]
130
131# Limit the I/O bandwidth rate again with both read/write and read/only.
f67539c2 132$rpc_py bdev_set_qos_limit Malloc0 --rw_mbytes_per_sec $BANDWIDTH_LIMIT_MB --r_mbytes_per_sec $READ_BANDWIDTH_LIMIT_MB
9f95a23c
TL
133run_fio Malloc0
134verify_qos_limits $BANDWIDTH_RESULT $READ_BANDWIDTH_LIMIT
135
136echo "I/O bandwidth limiting tests successful"
137
11fdf7f2 138iscsicleanup
f67539c2 139$rpc_py iscsi_delete_target_node 'iqn.2016-06.io.spdk:Target1'
11fdf7f2
TL
140
141rm -f ./local-job0-0-verify.state
142trap - SIGINT SIGTERM EXIT
143killprocess $pid
144
9f95a23c 145iscsitestfini $1 $2