Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / qa / workunits / erasure-code / bench.sh
1 #!/bin/bash 
2 #
3 # Copyright (C) 2015 Red Hat <contact@redhat.com>
4 # Copyright (C) 2013,2014 Cloudwatt <libre.licensing@cloudwatt.com>
5 #
6 # Author: Loic Dachary <loic@dachary.org>
7 #
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU Library Public License as published by
10 # the Free Software Foundation; either version 2, or (at your option)
11 # any later version.
12 #
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU Library Public License for more details.
17 #
18 # Test that it works from sources with:
19 #
20 #  CEPH_ERASURE_CODE_BENCHMARK=src/ceph_erasure_code_benchmark  \
21 #  PLUGIN_DIRECTORY=src/.libs \
22 #      qa/workunits/erasure-code/bench.sh fplot jerasure |
23 #      tee qa/workunits/erasure-code/bench.js
24 #
25 # This should start immediately and display:
26 #
27 # ...
28 # [ '2/1',  .48035538612887358583  ],
29 # [ '3/2',  .21648470405675016626  ],
30 # etc.
31 #
32 # and complete within a few seconds. The result can then be displayed with:
33 #
34 #  firefox qa/workunits/erasure-code/bench.html
35 #
36 # Once it is confirmed to work, it can be run with a more significant
37 # volume of data so that the measures are more reliable:
38 #
39 #  TOTAL_SIZE=$((4 * 1024 * 1024 * 1024)) \
40 #  CEPH_ERASURE_CODE_BENCHMARK=src/ceph_erasure_code_benchmark  \
41 #  PLUGIN_DIRECTORY=src/.libs \
42 #      qa/workunits/erasure-code/bench.sh fplot jerasure |
43 #      tee qa/workunits/erasure-code/bench.js
44 #
45 set -e
46
47 export PATH=/sbin:$PATH
48
49 : ${VERBOSE:=false}
50 : ${CEPH_ERASURE_CODE_BENCHMARK:=ceph_erasure_code_benchmark}
51 : ${PLUGIN_DIRECTORY:=/usr/lib/ceph/erasure-code}
52 : ${PLUGINS:=isa jerasure}
53 : ${TECHNIQUES:=vandermonde cauchy}
54 : ${TOTAL_SIZE:=$((1024 * 1024))}
55 : ${SIZE:=4096}
56 : ${PARAMETERS:=--parameter jerasure-per-chunk-alignment=true}
57
58 function bench_header() {
59     echo -e "seconds\tKB\tplugin\tk\tm\twork.\titer.\tsize\teras.\tcommand."
60 }
61
62 function bench() {
63     local plugin=$1
64     shift
65     local k=$1
66     shift
67     local m=$1
68     shift
69     local workload=$1
70     shift
71     local iterations=$1
72     shift
73     local size=$1
74     shift
75     local erasures=$1
76     shift
77     command=$(echo $CEPH_ERASURE_CODE_BENCHMARK \
78         --plugin $plugin \
79         --workload $workload \
80         --iterations $iterations \
81         --size $size \
82         --erasures $erasures \
83         --parameter k=$k \
84         --parameter m=$m \
85         --erasure-code-dir $PLUGIN_DIRECTORY)
86     result=$($command "$@")
87     echo -e "$result\t$plugin\t$k\t$m\t$workload\t$iterations\t$size\t$erasures\t$command ""$@"
88 }
89
90 function packetsize() {
91     local k=$1
92     local w=$2
93     local vector_wordsize=$3
94     local size=$4
95
96     local p=$(( ($size / $k / $w / $vector_wordsize ) * $vector_wordsize))
97     if [ $p -gt 3100 ] ; then
98         p=3100
99     fi
100     echo $p
101 }
102
103 function bench_run() {
104     local plugin=jerasure
105     local w=8
106     local VECTOR_WORDSIZE=16
107     local ks="2 3 4 6 10"
108     declare -A k2ms
109     k2ms[2]="1"
110     k2ms[3]="2"
111     k2ms[4]="2 3"
112     k2ms[6]="2 3 4"
113     k2ms[10]="3 4"
114     for technique in ${TECHNIQUES} ; do
115         for plugin in ${PLUGINS} ; do
116             eval technique_parameter=\$${plugin}2technique_${technique}
117             echo "serie encode_${technique}_${plugin}"
118             for k in $ks ; do
119                 for m in ${k2ms[$k]} ; do
120                     bench $plugin $k $m encode $(($TOTAL_SIZE / $SIZE)) $SIZE 0 \
121                         --parameter packetsize=$(packetsize $k $w $VECTOR_WORDSIZE $SIZE) \
122                         ${PARAMETERS} \
123                         --parameter technique=$technique_parameter
124
125                 done
126             done
127         done
128     done
129     for technique in ${TECHNIQUES} ; do
130         for plugin in ${PLUGINS} ; do
131             eval technique_parameter=\$${plugin}2technique_${technique}
132             echo "serie decode_${technique}_${plugin}"
133             for k in $ks ; do
134                 for m in ${k2ms[$k]} ; do
135                     echo
136                     for erasures in $(seq 1 $m) ; do
137                         bench $plugin $k $m decode $(($TOTAL_SIZE / $SIZE)) $SIZE $erasures \
138                             --parameter packetsize=$(packetsize $k $w $VECTOR_WORDSIZE  $SIZE) \
139                             ${PARAMETERS} \
140                             --parameter technique=$technique_parameter
141                     done
142                 done
143             done
144         done
145     done
146 }
147
148 function fplot() {
149     local serie
150     bench_run | while read seconds total plugin k m workload iteration size erasures rest ; do 
151         if [ -z $seconds ] ; then
152             echo null,
153         elif [ $seconds = serie ] ; then
154             if [ "$serie" ] ; then
155                 echo '];'
156             fi
157             local serie=`echo $total | sed 's/cauchy_\([0-9]\)/cauchy_good_\1/g'`
158             echo "var $serie = ["
159         else
160             local x
161             if [ $workload = encode ] ; then
162                 x=$k/$m
163             else
164                 x=$k/$m/$erasures
165             fi
166             echo "[ '$x', " $(echo "( $total / 1024 / 1024 ) / $seconds" | bc -ql) " ], "
167         fi
168     done
169     echo '];'
170 }
171
172 function main() {
173     bench_header
174     bench_run
175 }
176
177 if [ "$1" = fplot ] ; then
178     "$@"
179 else
180     main
181 fi
182 # Local Variables:
183 # compile-command: "\
184 #   CEPH_ERASURE_CODE_BENCHMARK=../../../src/ceph_erasure_code_benchmark \
185 #   PLUGIN_DIRECTORY=../../../src/.libs \
186 #   ./bench.sh
187 # "
188 # End: