def __send_rdy(self, connection, command):
        if self.__consumer.original_rdy is None:
            node_count = self.__consumer.get_node_count_for_topic(
                            connection.context.topic)
            self.__logger_rdy.debug("Calculating RDY: max_in_flight=(%d) "
                                    "node_count=(%d)", 
                                    self.__consumer.max_in_flight, node_count)
            if self.__consumer.max_in_flight >= node_count:
                rdy_this = int(math.ceil(
                                        float(self.__consumer.max_in_flight) /
                                        float(node_count)))
                self.__logger_rdy.debug("Assigning RDY based on max_in_flight "
                                        "(%d) and node count (%d) (optimal): "
                                        "(%d)", 
                                        self.__consumer.max_in_flight, 
                                        node_count, rdy_this)
            else:
                self.__logger_rdy.debug("(max_in_flight > nodes). Doing RDY "
                                        "election.")
                sleeping_connections = [
                    c \
                    for (c, info) \
                    in self.__consumer.connection_context.items() \
                    if info['rdy_count'] == 0]
                self.__logger_rdy.debug("Current sleeping_connections: %s", 
                                        sleeping_connections)
                if sleeping_connections:
                    elected_connection = random.choice(sleeping_connections)
                    self.__logger_rdy.debug("Sending RDY of (1) on: [%s]", 
                                            elected_connection)
                    command_elected = nsq.command.Command(elected_connection)
                    command_elected.rdy(1)
                else:
                    self.__logger.debug("No sleeping connections. We got the "
                                        "short stick: [%s]", connection)
                rdy_this = 0
        else:
            try:
                rdy_this = self.__consumer.original_rdy(
                            connection.node, 
                            self.__consumer.connection_count, 
                            self.__consumer)
                self.__logger_rdy.debug("Using RDY from callback: (%d)", 
                                        rdy_this)
            except TypeError:
                rdy_this = self.__consumer.original_rdy
                self.__logger_rdy.debug("Using static RDY: (%d)", rdy_this)
        rdy_this = min(rdy_this + \
                        self.__get_total_rdy_count(), 
                       self.__consumer.max_in_flight)
        server_features = self.__consumer.identify.server_features
        max_rdy_count = server_features['max_rdy_count']
        rdy_this = min(max_rdy_count, rdy_this)
        self.__logger_rdy.debug("Final RDY (max_in_flight=(%d) "
                                "max_rdy_count=(%d)): (%d)", 
                                self.__consumer.max_in_flight, max_rdy_count, 
                                rdy_this)
        if rdy_this > 0:
            command.rdy(rdy_this)
        else:
            self.__logger_rdy.info("This connection will go to sleep (not "
                                   "enough RDY to go around).")
        return rdy_this