コード例 #1
0
    def test_load_distribution(self):
        """ All servers must receive almost the same number of requests.
        """
        wrk = self.get_client('wrk')

        self.start_all_servers()
        self.start_tempesta()
        self.start_all_clients()
        self.wait_while_busy(wrk)

        tempesta = self.get_tempesta()
        servers = self.get_servers()
        tempesta.get_stats()
        servers_get_stats(servers)

        cl_reqs = tempesta.stats.cl_msg_forwarded
        s_reqs_expected = cl_reqs / len(servers)
        # On short running tests too small delta leads to false negatives.
        delta = max(self.precision * s_reqs_expected, self.min_delta)

        for srv in servers:
            tf_cfg.dbg(
                3, "Server %s received %d requests, [%d, %d] was expected" %
                (srv.get_name(), srv.requests, s_reqs_expected - delta,
                 s_reqs_expected + delta))
            self.assertAlmostEqual(
                srv.requests,
                s_reqs_expected,
                delta=delta,
                msg=("Server %s received %d requests, but [%d, %d] "
                     "was expected" %
                     (srv.get_name(), srv.requests, s_reqs_expected - delta,
                      s_reqs_expected + delta)))
コード例 #2
0
    def test_load_distribution(self):
        """ Manually calculate resulted weight of every server and compare with
        definded in configuration.
        """
        wrk = self.get_client('wrk')

        self.start_all_servers()
        self.start_tempesta()
        self.start_all_clients()

        self.wait_while_busy(wrk)

        tempesta = self.get_tempesta()
        servers = self.get_servers()

        tempesta.get_stats()
        servers_get_stats(servers)

        cl_reqs = tempesta.stats.cl_msg_forwarded
        tot_weight = 0
        def_weight = sched_ratio_static_def_weight()
        for srv in servers:
            tot_weight += srv.weight if srv.weight else def_weight

        for srv in servers:
            exp_weight = srv.weight if srv.weight else def_weight
            calc_weight = 1.0 * srv.requests / cl_reqs * tot_weight

            prec = self.precision
            if exp_weight <= 30:
                prec *= 2
            if exp_weight <= 10:
                prec *= 2

            s_reqs_expected = cl_reqs * exp_weight / tot_weight
            delta = prec * s_reqs_expected

            tf_cfg.dbg(
                3, "Server %s with weight %d received %d requests; "
                "calculated weight is %f, [%d, %d] requests was expected" %
                (srv.get_name(), exp_weight, srv.requests, calc_weight,
                 s_reqs_expected - delta, s_reqs_expected + delta))
            self.assertAlmostEqual(
                calc_weight,
                exp_weight,
                delta=(exp_weight * prec),
                msg=("Server %s calculated weight is %f, but %d was expected" %
                     (srv.get_name(), calc_weight, exp_weight)))
コード例 #3
0
    def test_inherit(self):
        wrk_h_1 = self.get_client('wrk_vhost_1')
        wrk_h_2 = self.get_client('wrk_vhost_2')
        wrk_h_1.options = ['-H "Host: example.com"']

        self.start_all_servers()
        self.start_tempesta()
        self.start_all_clients()
        self.wait_while_busy(wrk_h_1)
        self.wait_while_busy(wrk_h_2)

        servers = self.get_servers()
        servers_get_stats(servers)

        for group, lb_type in self.group_scheds:
            self.check_lb(group, lb_type)
コード例 #4
0
    def test_load_distribution(self):
        """ Configure slow and fast servers. The faster server, the more
        weight it should get.
        """
        duration = int(tf_cfg.cfg.get('General', 'Duration'))
        if duration < self.min_duration:
            raise unittest.TestCase.skipTest(
                self, "Test is not stable on short periods")
        if (tf_cfg.cfg.get('Tempesta',
                           'hostname') == tf_cfg.cfg.get('Server',
                                                         'hostname')):
            raise unittest.TestCase.skipTest(
                self, "Test is not stable if Tempesta and Servers " \
                "are started on the same node.")

        wrk = self.get_client('wrk')

        self.start_all_servers()
        self.start_tempesta()
        self.start_all_clients()

        self.wait_while_busy(wrk)

        tempesta = self.get_tempesta()
        servers = self.get_servers()
        tempesta.get_stats()
        servers_get_stats(servers)

        cl_reqs = tempesta.stats.cl_msg_forwarded
        tot_weight = len(servers) * 50  # for weight normalisation.
        weights = [(srv.get_name(), 1.0 * srv.requests / cl_reqs * tot_weight)
                   for srv in servers]
        weights.sort()
        tf_cfg.dbg(3, "Calculated server weights: %s" % weights)

        prev_name, prev_weight = weights[0]
        for name, weight in weights:
            self.assertLessEqual(
                weight,
                prev_weight,
                msg=("Faster server %s got less weight than slower %s" %
                     (prev_name, name)))
            if weight <= self.min_server_weight:
                break
            prev_weight = weight
            prev_name = name
コード例 #5
0
ファイル: stress.py プロジェクト: tempesta-tech/tempesta-test
 def servers_get_stats(self):
     control.servers_get_stats(self.servers)