예제 #1
0
파일: balancer.py 프로젝트: vkap/mastermind
def get_group_weights(n):
    try:
        size_to_sgs = {}
        (good, bad) = bla.filter_symm_groups()
        all_symm_groups = list(good) + list(bad)
        all_symm_group_objects = []
        for tuple_symm_group in all_symm_groups:
            symm_group = bla.SymmGroup(tuple_symm_group)
            sized_symm_groups = size_to_sgs.setdefault(len(tuple_symm_group), [])
            sized_symm_groups.append(symm_group)
            all_symm_group_objects.append(symm_group)
            logging.info(str(symm_group))

        result = {}

        for size in size_to_sgs:
            (group_weights, info) = balancelogic.rawBalance(all_symm_group_objects, bla.getConfig(), bla.GroupSizeEquals(size))
            result[size] = [item for item in group_weights.items()]
            logging.info("Cluster info: " + str(info))

        logging.info(str(result))
        return result
    except Exception as e:
        logging.error("Balancelogic error: " + str(e) + "\n" + traceback.format_exc())
        return {'Balancelogic error': str(e)}
예제 #2
0
    def get_group_weights(self, request):
        namespaces = {}
        all_symm_group_objects = []
        for couple in storage.couples:
            if couple.status not in storage.GOOD_STATUSES:
                continue

            symm_group = bla.SymmGroup(couple)
            namespaces.setdefault(couple.namespace, set())
            namespaces[couple.namespace].add(len(couple))
            all_symm_group_objects.append(symm_group)
            # logger.debug(str(symm_group))

        result = {}

        for namespace, sizes in namespaces.iteritems():
            for size in sizes:
                (group_weights, info) = balancelogic.rawBalance(
                    all_symm_group_objects,
                    bla.getConfig(),
                    bla._and(bla.GroupSizeEquals(size), bla.GroupNamespaceEquals(namespace)),
                )
                result.setdefault(namespace, {})[size] = [
                    ([g.group_id for g in item[0].groups],) + item[1:] + (int(item[0].get_stat().free_space),)
                    for item in group_weights.items()
                ]
                logger.info("Cluster info: " + str(info))

        logger.info(str(result))
        return result
예제 #3
0
    def get_group_weights(self, request):
        namespaces = {}
        all_symm_group_objects = []
        for couple in storage.couples:
            if couple.status not in storage.GOOD_STATUSES:
                continue

            symm_group = bla.SymmGroup(couple)
            namespaces.setdefault(couple.namespace, set())
            namespaces[couple.namespace].add(len(couple))
            all_symm_group_objects.append(symm_group)
            # logger.debug(str(symm_group))

        result = {}

        for namespace, sizes in namespaces.iteritems():
            for size in sizes:
                (group_weights, info) = balancelogic.rawBalance(
                    all_symm_group_objects, bla.getConfig(),
                    bla._and(bla.GroupSizeEquals(size),
                             bla.GroupNamespaceEquals(namespace)))
                result.setdefault(namespace, {})[size] = \
                    [([g.group_id for g in item[0].groups],) +
                         item[1:] +
                         (int(item[0].get_stat().free_space),)
                     for item in group_weights.items()]
                logger.info('Cluster info: ' + str(info))

        logger.info(str(result))
        return result
예제 #4
0
    def test_NormalSet(self):
        import math
        units_set = []

        normal_units_count = 200
        archive_units_count = 100

        for n in range(normal_units_count):
            units_set.append(generators.normal_unit())
        for n in range(archive_units_count):
            units_set.append(generators.archive_unit())

        # reference object
        normal_unit = generators.normal_unit()

        putPerSecond = normal_unit.realPutPerPeriod() * normal_units_count
        putPerSecond = max(
            putPerSecond + self.__balance_directives["AdditionalMessagePerSecondNumber"],
            putPerSecond * (1 + self.__balance_directives["AdditionalMessagePerSecondPercentage"]))

        # the next line sometimes yealds a wrong value because of roundup problems
        position = math.ceil(putPerSecond / normal_unit.maxPutPerPeriod()) - 1
        position = max(
            position + self.__balance_directives["AdditionalUnitsNumber"],
            int(position * (1 + self.__balance_directives["AdditionalUnitsPercentage"])),
            self.__balance_directives["MinimumUnitsWithPositiveWeight"])
        # soft and hard positions are equal because of no step in space

        reference_cluster_statistics = {
            'PutMaxTotal': normal_unit.maxPutPerPeriod() * (normal_units_count + archive_units_count),
            'GetMaxTotal': normal_unit.maxGetPerPeriod() * (normal_units_count + archive_units_count),
            'GetRealTotal': normal_unit.realGetPerPeriod() * (normal_units_count + archive_units_count),
            'PutRealTotal': normal_unit.realPutPerPeriod() * normal_units_count,
            'UnitUsedNumber': normal_units_count + archive_units_count,
            'UnitUnusedNumber': 0,
            'HardPosition': position,
            'SoftPosition': position}

        reference_balance_result = {}
        for (current_position, unit) in enumerate(units_set):
            if current_position < position:
                reference_balance_result[unit.unitId()] = normal_unit.maxGetPerPeriod() *\
                        self.__balance_directives["WeightMultiplierHead"]
            else:
                reference_balance_result[unit.unitId()] = 0

        (balance_result, cluster_statistics) = balancelogic.rawBalance(units_set, self.__balance_directives)
        self.assertEqual(reference_cluster_statistics, cluster_statistics)
        self.assertEqual(reference_balance_result, balance_result)
예제 #5
0
    def test_NormalSet(self):
        import math
        units_set = []

        normal_units_count = 200
        archive_units_count = 100

        for n in range(normal_units_count):
            units_set.append(generators.normal_unit())
        for n in range(archive_units_count):
            units_set.append(generators.archive_unit())

        # reference object
        normal_unit = generators.normal_unit()

        putPerSecond = normal_unit.realPutPerPeriod() * normal_units_count
        putPerSecond = max(
            putPerSecond +
            self.__balance_directives["AdditionalMessagePerSecondNumber"],
            putPerSecond *
            (1 +
             self.__balance_directives["AdditionalMessagePerSecondPercentage"])
        )

        # the next line sometimes yealds a wrong value because of roundup problems
        position = math.ceil(putPerSecond / normal_unit.maxPutPerPeriod()) - 1
        position = max(
            position + self.__balance_directives["AdditionalUnitsNumber"],
            int(position *
                (1 + self.__balance_directives["AdditionalUnitsPercentage"])),
            self.__balance_directives["MinimumUnitsWithPositiveWeight"])
        # soft and hard positions are equal because of no step in space

        reference_cluster_statistics = {
            'PutMaxTotal':
            normal_unit.maxPutPerPeriod() *
            (normal_units_count + archive_units_count),
            'GetMaxTotal':
            normal_unit.maxGetPerPeriod() *
            (normal_units_count + archive_units_count),
            'GetRealTotal':
            normal_unit.realGetPerPeriod() *
            (normal_units_count + archive_units_count),
            'PutRealTotal':
            normal_unit.realPutPerPeriod() * normal_units_count,
            'UnitUsedNumber':
            normal_units_count + archive_units_count,
            'UnitUnusedNumber':
            0,
            'HardPosition':
            position,
            'SoftPosition':
            position
        }

        reference_balance_result = {}
        for (current_position, unit) in enumerate(units_set):
            if current_position < position:
                reference_balance_result[unit.unitId()] = normal_unit.maxGetPerPeriod() *\
                        self.__balance_directives["WeightMultiplierHead"]
            else:
                reference_balance_result[unit.unitId()] = 0

        (balance_result, cluster_statistics) = balancelogic.rawBalance(
            units_set, self.__balance_directives)
        self.assertEqual(reference_cluster_statistics, cluster_statistics)
        self.assertEqual(reference_balance_result, balance_result)