summaryrefslogtreecommitdiffstats
path: root/perf-framework/nfs_delete.sh
blob: a6cb5bcbe21c3778f508d02b263c69e5cce2382f (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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
#!/bin/bash


function emptyfiles_create()
{
   mkdir -p $PG/emptyfiles;
   for i in $(seq 1 $smallfilecount); do
       : > $PG/emptyfiles/file.$i;
   done
}


function emptyfiles_delete()
{
    rm -rf $PG/emptyfiles;
}


function emptydirs_create()
{
    mkdir -p $PG/emptydirs;

    eval "echo $PG/emptydirs/top.{1..$emptytops}" | xargs mkdir -p;
    for top in $(seq 1 $emptytops); do
        eval "echo $PG/emptydirs/top.$top/dir.{1..$emptydirs}" | xargs mkdir -p;
    done
}


function emptydirs_delete()
{
    rm -rf $PG/emptydirs;
}


function smallfiles_create()
{
    mkdir -p $PG/smallfiles;
    for i in $(seq 1 $smallfilecount); do
	echo -n $smallblob >$PG/smallfiles/file.$i
    done
}


function smallfiles_rewrite()
{
    smallfiles_create "$@";
}


function smallfiles_read()
{
    for i in $(seq 1 $smallfilecount); do
	cat $PG/smallfiles/file.$i > /dev/null
    done
}


function smallfiles_reread()
{
    smallfiles_read "$@";
}


function smallfiles_delete()
{
    rm -rf $PG/smallfiles;
}


function largefile_create()
{
    mkdir -p $PG/largefile;
    dd if=/dev/zero of=$PG/largefile/large_file bs=$largeblock count=$largecount 2>/dev/null;
}


function largefile_rewrite()
{
    largefile_create "$@";
}


function largefile_read()
{
    dd if=$PG/largefile/large_file of=/dev/null bs=$largeblock count=$largecount 2>/dev/null;
}


function largefile_reread()
{
     largefile_read "$@";
}


function largefile_delete()
{
    rm -rf $PG/largefile
}


function crawl_create_recurse()
{
    local subpath;
    local depth;

    subpath="$1";
    depth="$2";

    if [ $depth -eq 0 ]; then
	for i in $(seq 1 $leafcount); do
	    : > $subpath/file.$i;
	done
	return
    fi

    depth=$(($depth - 1));

    eval "echo  $subpath/dir.{1..$crawlwidth}" | xargs mkdir -p;

    for i in $(seq 1 $crawlwidth); do
	crawl_create_recurse "$subpath/dir.$i" $depth;
    done
}


function directory_crawl_create ()
{
    crawl_create_recurse "$PG/crawl" $crawldepth;
}


function directory_crawl()
{
    ls -lR "$PG/crawl" >/dev/null
}


function directory_recrawl()
{
    directory_crawl "$@";
}


function directory_crawl_delete()
{
    rm -rf "$PG/crawl";
}


function metadata_modify ()
{
    chmod -R 777 "$PG/crawl";
    chown -R 1234 "$PG/crawl";
}


function run_tests()
{
    run emptyfiles_create;
    #run emptyfiles_delete;


    # run emptydirs_create;
    # run emptydirs_delete;


    #run smallfiles_create;
    #run smallfiles_rewrite;
    #echo 3 > /proc/sys/vm/drop_caches;
    #sleep 10;
    #run smallfiles_read;
    #run smallfiles_reread;
    #run smallfiles_delete;


    #run largefile_create;
    #run largefile_rewrite;
    #echo 3 > /proc/sys/vm/drop_caches;
    #sleep 10;
    #run largefile_read;
    #run largefile_reread;
    #run largefile_delete;


    #run directory_crawl_create;
    #echo 3 > /proc/sys/vm/drop_caches;
    #sleep 10;
    #run directory_crawl;
    #run directory_recrawl;
    #run metadata_modify;
    #run directory_crawl_delete;
}


#####################################################
############ Framework code #########################
#####################################################


function cleanup_playground()
{
    rm -rvf $PG;
    mkdir -p $PG;
}


function params_init()
{
    emptytops=10;
    emptydirs=10000;

    smallfilecount=80000;
    smallblock=4096;

    largeblock=64K;
    largecount=16K;

    crawlwidth=10;
    crawldepth=3;
    leafcount=100;

    smallblob=;
    for i in $(seq 1 $smallblock); do
	smallblob=a$smallblob
    done
}


function _init()
{
    params_init;

    TSTDOUT=251
    TSTDERR=252
    LOGFD=253
    LOGFILE=/tmp/perf$$

    eval "exec $TSTDOUT>&1"
    eval "exec $TSTDERR>&2"
    eval "exec $LOGFD<>$LOGFILE";
}


function parse_cmdline()
{
    MOUNT=;

    if [ "x$1" == "x" ] ; then
        echo "Usage: $0 /gluster/mount"
        exit 1
    fi

    MOUNT="$1";
    PG=$MOUNT/playground;
}


function wrap()
{
    "$@" 1>&$TSTDOUT 2>&$TSTDERR;
}


function measure()
{
    set -o pipefail;
    (time -p wrap "$@") 2>&1 >/dev/null | tail -n 3 | head -n 1 | cut -f2 -d' '
}


function log()
{
    local t;
    local rest;

    t=$1;
    shift;
    rest="$@";

    echo "$rest $t" >&$LOGFD;
}


function run()
{
    local t;

    echo -n "running $@ ... "
    t=$(measure "$@");

    if [ $? -eq 0 ]; then
        echo "done ($t secs)";
        log "$t" "$@";
    else
        echo "FAILED!!!"
    fi
}


function verify_mount()
{
    if [ ! -d "$MOUNT" ] ; then
        echo "Can't access '$MOUNT'"
        exit 1
    fi
}


function show_report()
{
    (echo "Testname Time"; cat $LOGFILE) | column -t;
    rm -f $LOGFILE;
}


function main()
{
    parse_cmdline "$@";

    verify_mount;

    cleanup_playground;

    run_tests;

    show_report;
}


_init && main "$@"