예제 #1
0
def display_leader_imbalance(cluster_topologies):
    """Display leader count and weight imbalance statistics.

    :param cluster_topologies: A dictionary mapping a string name to a
        ClusterTopology object.
    """
    broker_ids = list(next(six.itervalues(cluster_topologies)).brokers.keys())
    assert all(
        set(broker_ids) == set(cluster_topology.brokers.keys())
        for cluster_topology in six.itervalues(cluster_topologies))

    broker_leader_counts = [
        stats.get_broker_leader_counts(cluster_topology.brokers[broker_id]
                                       for broker_id in broker_ids)
        for cluster_topology in six.itervalues(cluster_topologies)
    ]
    broker_leader_weights = [
        stats.get_broker_leader_weights(cluster_topology.brokers[broker_id]
                                        for broker_id in broker_ids)
        for cluster_topology in six.itervalues(cluster_topologies)
    ]

    _display_table_title_multicolumn(
        'Leader Count',
        'Brokers',
        broker_ids,
        list(cluster_topologies.keys()),
        broker_leader_counts,
    )

    print('')

    _display_table_title_multicolumn(
        'Leader weight',
        'Brokers',
        broker_ids,
        list(cluster_topologies.keys()),
        broker_leader_weights,
    )

    for name, blc, blw in zip(list(cluster_topologies.keys()),
                              broker_leader_counts, broker_leader_weights):
        print('\n'
              '{name}'
              'Leader count imbalance: {net_imbalance}\n'
              'Broker leader weight mean: {weight_mean}\n'
              'Broker leader weight stdev: {weight_stdev}\n'
              'Broker leader weight cv: {weight_cv}'.format(
                  name='' if len(cluster_topologies) == 1 else name + '\n',
                  net_imbalance=stats.get_net_imbalance(blc),
                  weight_mean=stats.mean(blw),
                  weight_stdev=stats.standard_deviation(blw),
                  weight_cv=stats.coefficient_of_variation(blw),
              ))
 def broker_leader_weight_cv(self):
     return coefficient_of_variation(self.broker_leader_weights)
 def broker_partition_count_cv(self):
     return coefficient_of_variation(self.broker_partition_counts)
 def broker_weight_cv(self):
     """Return the coefficient of variation of the weight of the brokers."""
     return coefficient_of_variation(self.broker_weights)
예제 #5
0
def test_coefficient_of_variation():
    assert stats.coefficient_of_variation([1, 2, 3, 4, 5]) == sqrt(2) / 3
예제 #6
0
def test_coefficient_of_variation():
    assert stats.coefficient_of_variation([1, 2, 3, 4, 5]) == sqrt(2) / 3
예제 #7
0
파일: display.py 프로젝트: Yelp/kafka-utils
def display_leader_imbalance(cluster_topologies):
    """Display leader count and weight imbalance statistics.

    :param cluster_topologies: A dictionary mapping a string name to a
        ClusterTopology object.
    """
    broker_ids = list(next(six.itervalues(cluster_topologies)).brokers.keys())
    assert all(
        set(broker_ids) == set(cluster_topology.brokers.keys())
        for cluster_topology in six.itervalues(cluster_topologies)
    )

    broker_leader_counts = [
        stats.get_broker_leader_counts(
            cluster_topology.brokers[broker_id]
            for broker_id in broker_ids
        )
        for cluster_topology in six.itervalues(cluster_topologies)
    ]
    broker_leader_weights = [
        stats.get_broker_leader_weights(
            cluster_topology.brokers[broker_id]
            for broker_id in broker_ids
        )
        for cluster_topology in six.itervalues(cluster_topologies)
    ]

    _display_table_title_multicolumn(
        'Leader Count',
        'Brokers',
        broker_ids,
        list(cluster_topologies.keys()),
        broker_leader_counts,
    )

    print('')

    _display_table_title_multicolumn(
        'Leader weight',
        'Brokers',
        broker_ids,
        list(cluster_topologies.keys()),
        broker_leader_weights,
    )

    for name, blc, blw in zip(
            list(cluster_topologies.keys()),
            broker_leader_counts,
            broker_leader_weights
    ):
        print(
            '\n'
            '{name}'
            'Leader count imbalance: {net_imbalance}\n'
            'Broker leader weight mean: {weight_mean}\n'
            'Broker leader weight stdev: {weight_stdev}\n'
            'Broker leader weight cv: {weight_cv}'
            .format(
                name='' if len(cluster_topologies) == 1 else name + '\n',
                net_imbalance=stats.get_net_imbalance(blc),
                weight_mean=stats.mean(blw),
                weight_stdev=stats.stdevp(blw),
                weight_cv=stats.coefficient_of_variation(blw),
            )
        )