Beispiel #1
0
def makeDepth(fs, root, n):
    cwd = root
    for _ in range(0, n):
        # Make up a random 5-character name for this directory.
        name = randomDirName()
        fs.mkdir(cwd, name)
        cwd = dynamo_fs.concatPath(cwd, name)
    return cwd
Beispiel #2
0
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()
Beispiel #3
0
def runAllWithFs(fsClass, depth, fileSize, idstring, numTrials=10):
    # Create a random chain of directories to get the proper depth.
    fs = fsClass()
    cwd = benchmark_utils.makeDepth(fs, '/', depth)
    filename = dynamo_fs.concatPath(cwd, 'the_file')
    fs.flush()
    results = list()
    for _ in range(numTrials):
        for bench in runAllWithFile(idstring):
            del fs
            fs = fsClass()
            benchmark_utils.clearFSCache()
            results.append(bench(fs, filename, depth, fileSize))
            fs.flush()
    return results
Beispiel #4
0
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()
Beispiel #5
0
 def mkdir(self, path, newName):
     path = self._fromRoot(path)
     os.mkdir(concatPath(path, newName))
Beispiel #6
0
 def _fromRoot(self, path):
     return concatPath(self.root, path)