3 # A workload generator for the cleaner benchmarks. This will randomly write to
4 # a collection of files at a fixed rate, to dirty data in the file system.
6 # DO NOT RUN FROM A DIRECTORY WITH FILES YOU CARE ABOUT--it will overwrite
7 # files in and under the current directory.
9 import os, random, sys, time
11 def write_file(path, size=1024**2):
17 def modify_files(files, rate=1.0, fraction=0.25):
18 files = random.sample(files, int(round(len(files) * fraction)))
19 print "Modifying", len(files), "files"
21 last_time = time.time()
25 next_time = last_time + (1.0/rate)
26 time.sleep(max(0.0, next_time - now))
32 if __name__ == '__main__':
33 print "Modifying files in", os.getcwd()
36 for (path, dirs, files) in iter(os.walk(".")):
38 all_files.append(os.path.join(path, f))
39 print len(all_files), "files total"
40 modify_files(all_files, rate=1e6)