Пример #1
0
    def _write(self,
               iteration_cnt,
               block_size,
               mount_point,
               filename,
               with_fsync=False):
        """
        Perform iteration_cnt number of block_size write on mount_point and return avg latencies
        """
        filepath = '{}/{}'.format(mount_point, filename)
        self.file_path_created.append(filepath)
        fd = None
        latencies = 0
        self._creat(filepath)

        try:
            fd = os.open(filepath, os.O_TRUNC | os.O_RDWR)
            for _ in range(iteration_cnt):
                str_to_write = str.encode('a' * block_size)
                latencies += measure_latency(os.write, fd, str_to_write)
                if with_fsync:
                    os.fsync(fd)

        except Exception as e:
            print('problem has occured while write benchmarking')
            print(e.__traceback__)
            print(e)
        finally:
            if fd is None:
                raise Exception(
                    'benchmarking failed during some I/O operations')
            else:
                os.close(fd)

        return latencies / iteration_cnt
Пример #2
0
    def _read(self, iteration_cnt, block_size, mount_point, filename):
        """
        Perform iteration_cnt number of block_size read on mount_point and return avg latencies
        """
        filepath = '{}/{}'.format(mount_point, filename)
        self.file_path_created.append(filepath)
        file_size = iteration_cnt * block_size
        fd = None
        latencies = 0
        self._creat(filepath)

        try:
            # write bytes before reading
            fd = os.open(filepath, os.O_TRUNC | os.O_RDWR)
            bytes_written = os.write(fd, str.encode('a' * file_size))
            # print('bytes written: {}'.format(bytes_written))
            os.fsync(fd)
            os.lseek(fd, 0, 0)

            for _ in range(iteration_cnt):
                os.read(fd, block_size)
                latencies += measure_latency(os.read, fd, block_size)

        except Exception as e:
            print('problem has occured while read benchmarking')
            print(e.__traceback__)
            print(e)
        finally:
            if fd is None:
                raise Exception(
                    'benchmarking failed during some I/O operations')
            else:
                os.close(fd)

        return latencies / iteration_cnt
Пример #3
0
    def _run_cp(self, iteration_cnt, block_size, mount_point, filename):
        src_filepath = '{}/{}'.format(mount_point, filename)
        self.file_path_created.append(src_filepath)
        #create a new dir for /temp and append filepath+name
        dsn_file_dir = '{}/{}'.format(mount_point, "tmp")
        dsn_filepath = '{}/{}'.format(dsn_file_dir, filename)

        try:
            if not os.path.exists(dsn_file_dir):
                os.mkdir(dsn_file_dir)
        except OSError:
            print("Creation of the directory %s failed" % dsn_filepath)

        latencies = 0
        self._creat(src_filepath)

        try:
            for _ in range(iteration_cnt):
                latencies += measure_latency(
                    subprocess.call, ['cp', '-r', src_filepath, dsn_filepath])

            self.file_path_created.append(dsn_filepath)
            self.file_path_created.append(dsn_file_dir)
        except Exception as e:
            print('problem has occured while write benchmarking')
            print(e.__traceback__)
            print(e)

        return latencies / iteration_cnt
Пример #4
0
async def ping(ctx: Context):
    """
    display bot latency
    """

    latency: Optional[float] = measure_latency()
    if latency is not None:
        await ctx.send(translations.f_pong_latency(latency * 1000))
    else:
        await ctx.send(translations.pong)
Пример #5
0
    def _create(self, frequency, mount_point, filename):
        """
        Create frequency number of files on mount_point and return avg latencies
        """
        if not mount_point:
            raise Exception('Provide mount point')

        latencies = 0

        for i in range(frequency):
            file_path = '{mount_point}/{filename}_{number}.txt'\
                .format(mount_point=mount_point, filename=filename, number=i)
            self.file_path_created.append(file_path)
            latencies += measure_latency(self._creat, file_path)
        return latencies / frequency
Пример #6
0
    def _run_untar(self, iteration_cnt, block_size, mount_point, filename):
        filepath = '{}/{}'.format(mount_point, filename)
        latencies = 0
        dsn_file_dir = '{}/{}'.format(mount_point, "untarred")

        try:
            if not os.path.exists(dsn_file_dir):
                os.mkdir(dsn_file_dir)
        except OSError:
            print("Creation of the directory %s failed" % dsn_file_dir)
        # dsn_file_dir = '{}/{}'.format(mount_point, dsn_file_dir)

        try:
            for _ in range(iteration_cnt):
                latencies += measure_latency(
                    subprocess.call,
                    ['tar', 'xf', filepath, '-C', dsn_file_dir])
            self.file_path_created.append(dsn_file_dir)
        except Exception as e:
            print('problem has occured while write benchmarking')
            print(e.__traceback__)
            print(e)
        return latencies / iteration_cnt