-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate-data.sh
executable file
·191 lines (185 loc) · 3.71 KB
/
generate-data.sh
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
#!/bin/bash
BUCKET_BASE=BUCKET%
BUCKET_COUNT=$(($RANDOM % 128))
KEY_BASE=KEY%
KEY_COUNT=$(($RANDOM % 65536))
HOST_LIST=(127.0.0.1:8098)
DATA_SIZE=128
DATA_SOURCE=/dev/random
VERBOSE=0
MAXPROC=$((`ulimit -u` / 2))
while [ "${1:0:1}" = "-" -a "${#1}" -gt 1 ]; do
case ${1:1} in
k=* | keys=*)
arry=(${1/=/ })
KEY_COUNT=${arry[1]}
unset arry
shift
;;
k | keys)
shift
KEY_COUNT=$1
shift
;;
K=* | KEY=*)
arry=(${1/=/ })
KEY_BASE=${arry[1]}
[ "${KEY_BASE//%/}" = "$KEY_BASE" ] && KEY_BASE="${KEY_BASE}%"
unset arry
shift
;;
K | KEY)
shift
KEY_BASE=$1
shift
[ "${KEY_BASE//%/}" = "$KEY_BASE" ] && KEY_BASE="${KEY_BASE}%"
;;
b=* | buckets=*)
arry=(${1/=/ })
BUCKET_COUNT=${arry[1]}
unset arry
shift
;;
b | buckets)
shift
BUCKET_COUNT=$1
shift
;;
B=* | BUCKET=*)
arry=(${1/=/ })
BUCKET_BASE=${arry[1]}
[ "${BUCKET_BASE//%/}" = "$BUCKET_BASE" ] && BUCKET_BASE="${BUCKET_BASE}%"
unset arry
shift
;;
B | BUCKET)
shift
BUCKET_BASE=$1
shift
[ "${BUCKET_BASE//%/}" = "$BUCKET_BASE" ] && BUCKET_BASE="${BUCKET_BASE}%"
;;
d=* | size=*)
arry=(${1/=/ })
DATA_SIZE=${arry[1]}
unset arry
shift
;;
d | size)
shift
DATA_SIZE=$1
shift
;;
m | maxproc)
shift
MAXPROC=$1
shift
;;
m=* | maxproc=*)
arry=(${1/=/ })
MAXPROC=${arry[1]}
unset arry
shift
;;
data=*)
arry=(${1/=/ })
DATA_SOURCE=${arry[1]}
unset arry
shift
;;
data)
shift
DATA_SOURCE=$1
shift
;;
v)
shift
VERBOSE=1
if [ -n "$1" -a "${1//[^0-9]/}" = "$1" ]; then
VERBOSE=$1
shift
fi
;;
v=*)
arry=(${1/=/ })
VERBOSE=${arry[1]}
unset arry
shift
;;
pw)
shift
PW=$1
shift
;;
pw=*)
arry=(${1/=/ })
PW=${arry[1]}
unset arry
shift
;;
dw)
shift
DW=$1
shift
;;
dw=*)
arry=(${1/=/ })
DW=${arry[1]}
unset arry
shift
;;
*)
echo "Unknown flag $1"
exit
;;
esac
done
[ $# -gt 0 ] && HOST_LIST=($*)
if [ $VERBOSE -gt 0 ]; then
echo "BUCKET_BASE: $BUCKET_BASE"
echo "BUCKET_COUNT: $BUCKET_COUNT"
echo "KEY_BASE: $KEY_BASE"
echo "KEY_COUNT: $KEY_COUNT"
echo "HOST: ${HOST_LIST[*]}"
echo "DATA_SIZE: $DATA_SIZE"
echo "VERBOSE LEVEL: $VERBOSE"
echo "..."
fi
opts=""
gets=""
if [ -n "$PW" ]; then
[ -z "$gets" ] && gets="?" || gets="${gets}&"
opts="$opts with pw=$PW"
gets="${gets}pw=$PW"
fi
if [ -n "$DW" ]; then
[ -z "$gets" ] && gets="?" || gets="${gets}&"
opts="$opts with dw=$DW"
gets="${gets}dw=$DW"
fi
echo "Writing $DATA_SIZE bytes data in $KEY_COUNT keys to $BUCKET_COUNT buckets using ${#HOST_LIST[*]} nodes$opts."
bucket_sub=""
key_sub=""
hostidx=0;
proccnt=0;
for i in `seq 1 $BUCKET_COUNT`; do
[ $BUCKET_COUNT -gt 1 ] && bucket_sub=`printf "%03X" $i`
bucket=${BUCKET_BASE//%/$bucket_sub}
[ $VERBOSE = 1 ] && echo "Putting $KEY_COUNT keys in bucket '$bucket'"
for j in `seq 1 $KEY_COUNT`; do
[ $KEY_COUNT -gt 1 ] && key_sub=`printf "%03X" $j`
host=${HOST_LIST[$hostidx]}
key=${KEY_BASE//%/$key_sub}
[ $VERBOSE = 2 ] && echo -e -n "\rPutting $DATA_SIZE bytes in key '$key' in bucket '$bucket' using node '$host'$opts"
[ $VERBOSE -gt 2 ] && echo dd if=$DATA_SOURCE bs=1 count=$DATA_SIZE 2\>/dev/null \| curl -s $host/BUCKETS/$bucket/KEYS/$key$gets -X PUT -H "content-type: application/octet-stream" --data-binary @-
dd if=$DATA_SOURCE bs=1 count=$DATA_SIZE </dev/null 2>/dev/null | curl -s $host/buckets/$bucket/keys/$key$gets -X PUT -H "content-type: application/octet-stream" --data-binary @- 2>&1 >/dev/null &
proccnt=$(($proccnt + 1))
hostidx=$((hostidx + 1))
if [ $hostidx -ge ${#HOST_LIST[*]} ]; then
hostidx=0
fi
while [ $proccnt -gt $MAXPROC ]; do
sleep 0.1
proccnt=`ps | grep 'curl -s' | wc -l`
done
done
done