summaryrefslogtreecommitdiffstats
path: root/qa/workunits/erasure-code/bench.sh
blob: 87e997c3500f91d85c1ef6f796827abf56f276c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
#!/usr/bin/env bash
#
# Copyright (C) 2015 Red Hat <contact@redhat.com>
# Copyright (C) 2013,2014 Cloudwatt <libre.licensing@cloudwatt.com>
#
# Author: Loic Dachary <loic@dachary.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU Library Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Library Public License for more details.
#
# Test that it works from sources with:
#
#  TOTAL_SIZE=$((4 * 1024 * 1024)) SIZE=4096 \
#  CEPH_ERASURE_CODE_BENCHMARK=build/bin/ceph_erasure_code_benchmark  \
#  PLUGIN_DIRECTORY=build/lib \
#      qa/workunits/erasure-code/bench.sh fplot jerasure |
#      tee qa/workunits/erasure-code/bench.js
#
# This should start immediately and display:
#
# ...
# [ '2/1',  .48035538612887358583  ],
# [ '3/2',  .21648470405675016626  ],
# etc.
#
# and complete within a few seconds. The result can then be displayed with:
#
#  firefox qa/workunits/erasure-code/bench.html
#
# Once it is confirmed to work, it can be run with a more significant
# volume of data so that the measures are more reliable. Ideally the size
# of the buffers (SIZE) should be larger than the L3 cache to avoid cache hits.
# The following example uses an 80MB (80 * 1024 * 1024) buffer.
# A larger buffer with fewer iterations (iterations = TOTAL SIZE / SIZE) should result in
# more time spent encoding/decoding and less time allocating/aligning buffers:
#
#  TOTAL_SIZE=$((100 * 80 * 1024 * 1024)) SIZE=$((80 * 1024 * 1024)) \
#  CEPH_ERASURE_CODE_BENCHMARK=build/bin/ceph_erasure_code_benchmark  \
#  PLUGIN_DIRECTORY=build/lib \
#      qa/workunits/erasure-code/bench.sh fplot jerasure |
#      tee qa/workunits/erasure-code/bench.js
#
set -e

export PATH=/sbin:$PATH

: ${VERBOSE:=false}
: ${CEPH_ERASURE_CODE_BENCHMARK:=ceph_erasure_code_benchmark}
: ${PLUGIN_DIRECTORY:=/usr/lib/ceph/erasure-code}
: ${PLUGINS:=isa jerasure}
: ${TECHNIQUES:=vandermonde cauchy liberation reed_sol_r6_op blaum_roth liber8tion}
: ${TOTAL_SIZE:=$((100 * 80 * 1024 * 1024))} #TOTAL_SIZE / SIZE = number of encode or decode iterations to run
: ${SIZE:=$((80 * 1024 * 1024))} #size of buffer to encode/decode
: ${PARAMETERS:=--parameter jerasure-per-chunk-alignment=true}

declare -rA isa_techniques=(
    [vandermonde]="reed_sol_van"
    [cauchy]="cauchy"
)

declare -rA jerasure_techniques=(
    [vandermonde]="reed_sol_van"
    [cauchy]="cauchy_good"
    [reed_sol_r6_op]="reed_sol_r6_op"
    [blaum_roth]="blaum_roth"
    [liberation]="liberation"
    [liber8tion]="liber8tion"
)

function bench_header() {
    echo -e "seconds\tKB\tplugin\tk\tm\twork.\titer.\tsize\teras.\tcommand."
}

function bench() {
    local plugin=$1
    shift
    local k=$1
    shift
    local m=$1
    shift
    local workload=$1
    shift
    local iterations=$1
    shift
    local size=$1
    shift
    local erasures=$1
    shift
    command=$(echo $CEPH_ERASURE_CODE_BENCHMARK \
        --plugin $plugin \
        --workload $workload \
        --iterations $iterations \
        --size $size \
        --erasures $erasures \
        --parameter k=$k \
        --parameter m=$m \
        --erasure-code-dir $PLUGIN_DIRECTORY)
    result=$($command "$@")
    echo -e "$result\t$plugin\t$k\t$m\t$workload\t$iterations\t$size\t$erasures\t$command ""$@"
}

function packetsize() {
    local k=$1
    local w=$2
    local vector_wordsize=$3
    local size=$4

    local p=$(( ($size / $k / $w / $vector_wordsize ) * $vector_wordsize))
    if [ $p -gt 3100 ] ; then
        p=3100
    fi
    echo $p
}

function get_technique_name()
{
    local plugin=$1
    local technique=$2

    declare -n techniques="${plugin}_techniques"
    echo ${techniques["$technique"]}
}

function technique_is_raid6() {
    local technique=$1
    local r6_techniques="liberation reed_sol_r6_op blaum_roth liber8tion"

    if [[ $r6_techniques =~ $technique ]]; then
        return 0
    fi
    return 1
}

function bench_run() {
    local plugin=jerasure
    local w=8
    local VECTOR_WORDSIZE=16
    local ks="2 3 4 6 10"
    declare -A k2ms
    k2ms[2]="1"
    k2ms[3]="2"
    k2ms[4]="2 3"
    k2ms[6]="2 3 4"
    k2ms[10]="3 4"

    for technique in ${TECHNIQUES} ; do
        for plugin in ${PLUGINS} ; do
            technique_parameter=$(get_technique_name $plugin $technique)
            if [[ -z $technique_parameter ]]; then continue; fi
            echo "serie encode_${technique}_${plugin}"
            for k in $ks ; do
                for m in ${k2ms[$k]} ; do
                    if [ $m -ne 2 ] && technique_is_raid6 $technique; then continue; fi
                    bench $plugin $k $m encode $(($TOTAL_SIZE / $SIZE)) $SIZE 0 \
                        --parameter packetsize=$(packetsize $k $w $VECTOR_WORDSIZE $SIZE) \
                        ${PARAMETERS} \
                        --parameter technique=$technique_parameter
                done
            done
        done
    done
    for technique in ${TECHNIQUES} ; do
        for plugin in ${PLUGINS} ; do
            technique_parameter=$(get_technique_name $plugin $technique)
            if [[ -z $technique_parameter ]]; then continue; fi
            echo "serie decode_${technique}_${plugin}"
            for k in $ks ; do
                for m in ${k2ms[$k]} ; do
                    if [ $m -ne 2 ] && technique_is_raid6 $technique; then continue; fi
                    echo
                    for erasures in $(seq 1 $m) ; do
                        bench $plugin $k $m decode $(($TOTAL_SIZE / $SIZE)) $SIZE $erasures \
                            --parameter packetsize=$(packetsize $k $w $VECTOR_WORDSIZE  $SIZE) \
                            ${PARAMETERS} \
                            --parameter technique=$technique_parameter
                    done
                done
            done
        done
    done
}

function fplot() {
    local serie=""
    local plot=""
    local encode_table="var encode_table = [\n"
    local decode_table="var decode_table = [\n"
    while read seconds total plugin k m workload iteration size erasures rest ; do
        if [ -z $seconds ] ; then
            plot="$plot  null,\n"
        elif [ $seconds = serie ] ; then
            if [ "$serie" ] ; then
                echo -e "$plot];\n"
            fi
            local serie=`echo $total | sed 's/cauchy_\([0-9]\)/cauchy_good_\1/g'`
            plot="var $serie = [\n"
        else
            local x
            local row
            local technique=`echo $rest | grep -Po "(?<=technique=)\w*"`
            local packetsize=`echo $rest | grep -Po "(?<=packetsize=)\w*"`
            if [ $workload = encode ] ; then
                x=$k/$m
                row="[ '$plugin', '$technique', $seconds, $total, $k, $m, $iteration, $packetsize ],"
                encode_table="$encode_table  $row\n"

            else
                x=$k/$m/$erasures
                row="[ '$plugin', '$technique', $seconds, $total, $k, $m, $iteration, $packetsize, $erasures ],"
                decode_table="$decode_table  $row\n"
            fi
            local out_time="$(echo "( $total / 1024 / 1024 ) / $seconds" | bc -ql)"
            plot="$plot  [ '$x', $out_time ],\n"
        fi
    done < <(bench_run)

    echo -e "$plot];\n"
    echo -e "$encode_table];\n"
    echo -e "$decode_table];\n"
}

function main() {
    bench_header
    bench_run
}

if [ "$1" = fplot ] ; then
    "$@"
else
    main
fi
# Local Variables:
# compile-command: "\
#   CEPH_ERASURE_CODE_BENCHMARK=../../../src/ceph_erasure_code_benchmark \
#   PLUGIN_DIRECTORY=../../../build/lib \
#   ./bench.sh
# "
# End: