def mutateRandomTree(fs, root, depth, fanout, numMutations): for _ in range(0, numMutations): # Create a random path. path = root for _ in range(0, depth + 1): # Add 1 to create the filename at the end of the directory string. path = concatPath(path, str(randint(0, fanout - 1))) # Write a chunk to the file. f = fs.open(path, 'w') if f.stringOptimized: f.write(benchmark_utils.randomString(CHUNK_SIZE)) else: f.write_array(benchmark_utils.randomArray(CHUNK_SIZE)) f.close()
def makeRandomTree(fs, root, depth, fanout, fileSize): if depth > 0: for i in range(0, fanout): iStr = str(i) fs.mkdir(root, iStr) makeRandomTree(fs, concatPath(root, iStr), depth - 1, fanout, fileSize) else: # depth is zero; now we make files. for i in range(0, fanout): f = fs.open(concatPath(root, str(i)), 'w') bytesLeft = fileSize while bytesLeft > 0: if f.stringOptimized: f.write(benchmark_utils.randomString(CHUNK_SIZE)) else: f.write_array(benchmark_utils.randomArray(CHUNK_SIZE)) bytesLeft -= CHUNK_SIZE f.close()
from random import randint import sys import benchmark_utils import dynamo_fs import os from dynamo_fs import concatPath import file import shutil # General Note: fileSizes will be rounded up to the nearest multiple of # chunk size, for all benchmarks. CHUNK_SIZE = 4096 # Generate some random data to read and write. STRING = benchmark_utils.randomString(CHUNK_SIZE) ARRAY = benchmark_utils.randomArray(CHUNK_SIZE) # Generates a random position to seek to in a file. def randPos(fileSize): if fileSize <= CHUNK_SIZE: return 0 else: return randint(0, fileSize - 1 - CHUNK_SIZE) # rand - True for random writes, false for sequential writes. def write(fs, filename, fileSize, sampler, rand): sampler.begin() f = fs.open(filename, 'w') if f.stringOptimized: print 'WARNING: Data not being twiddled between blocks'