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 test_mean(): assert stats.mean([1, 2, 3, 4, 5]) == 3
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), ) )