File: create_derived_load.sh

package info (click to toggle)
blkreplay 1.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 25,672 kB
  • sloc: sh: 3,175; ansic: 2,057; makefile: 23
file content (134 lines) | stat: -rwxr-xr-x 4,099 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/env bash
# Copyright 2010-2012 Thomas Schoebel-Theuer /  1&1 Internet AG
#
# Email: tst@1und1.de
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

#####################################################################

# Create derived loads from original loads.
#
# The original loads "$@" are split into snippets having length $window each.
# The snippets are sorted according to IOPS and distributed to
# 0..($max-1) output files in a round-robin fashion, where
# max is iterating through the list $split_list.
#
# The rationale is explained at
# http://www.blkreplay.org/loads/natural/1and1/natural-derived/00README
#
# TST 2012-06-03

# check some preconditions
noecho=1
script_dir="$(cd "$(dirname "$(which "$0")")"; pwd)"
source "$script_dir/modules/lib.sh" || exit $?

check_list="gzip gunzip grep sed gawk cut"
check_installed "$check_list"

window=${window:-300}
split_list=${split_list:-001 002 004 008 016 032 064 128}


function paste_together
{
    gawk -F";" 'BEGIN{ old = 0.0; offset = 0.0; } { if ($1 < old) { offset += old; } printf("%17.9f ;%s;%s;%s;%s;%s\n", $1 + offset, $2, $3, $4, $5, $6); old = $1; }'
}

function from_start
{
    gawk -F";" 'BEGIN{ offset = -1; } { if (offset < 0) { offset = $1; } printf("%17.9f ;%s;%s;%s;%s;%s\n", $1 - offset, $2, $3, $4, $5, $6); }'
}

tmp="${TMPDIR:-/tmp}/snippets.$$"
mkdir -p $tmp/s || exit $?

echo "Creating snippets. This may take a long time...." 1>&2
limit=$window
snippet=0
total=0
cat "$@" |\
    gunzip -f |\
    grep ";" |\
    grep -v "[a-z]" |\
    paste_together |\
{
    count=0
    while true; do
        while IFS="." read time rest; do
	    if (( time >= limit )); then
		break;
	    fi
	    echo "$time.$rest"
	    (( count++ ))
	done >> $tmp/xxx
	if [ -z "$time" ]; then
	    break
	fi
	(( iops = count / window ))
	echo "  snippet $snippet at $limit has $count requests ($iops IOPS)" 1>&2
	(( total += count ))
	from_start < $tmp/xxx > $tmp/s/$count.$snippet
	rm -f $tmp/xxx
	(( snippet++ ))
	(( limit += window ))
	echo "$time.$rest" > $tmp/xxx
	count=1
    done
    echo "------------------------------------------------" 1>&2
    echo "snippets      : $snippet" 1>&2
    echo "reworked lines: $total" 1>&2
    echo "rest     lines: $count" 1>&2
    echo "sum      lines: $(( total + count ))" 1>&2
    echo "average  IOPS : $(( total / snippet / window ))" 1>&2
    echo "------------------------------------------------" 1>&2
}

base="$(basename "$1" | sed 's/\.\(load\|gz\|[0-9]\+\)//g')"

for max in $split_list; do
    max_num=$(echo $max | sed 's/^0*//')
    dir="${base}.derived.split.$max"
    mkdir -p "$dir" || exit $?
    echo "------------------------------------------------" 1>&2
    echo "Splitting into $max:" 1>&2
    for i in $(eval "echo {0..$(($max_num - 1))}"); do
	out[i]="$(printf "$base.derived.%03d.of.$max_num.load.gz" $i)"
	list[i]=""
    done

    j=0
    for i in $( (cd $tmp/s && ls) | sort -n -r ); do
	#echo "$i => $j" 1>&2
	list[j]="${list[j]} $i"
	(( j = (j + 1) % max_num ))
    done

    for i in $(eval "echo {0..$(($max_num - 1))}"); do
	[ -z "${list[i]}" ] && continue
	echo "${out[i]} ${list[i]}" 1>&2
	(
	    echo_copyright "$(basename "$1")..."
	    echo "start ; sector; length ; op ;  replay_delay ; replay_duration"
	    cd $tmp/s
	    cat ${list[i]} | paste_together
	) | gzip -8 > "$dir/${out[i]}" &
    done
    echo "Waiting for termination of subprocesses...." 1>&2
    wait
done

rm -rf $tmp