Пример #1
0
    def testSpeedControl(self):
        settings = Settings()
        counter_server = CounterServer(self.dir_, settings)
        self.serv = SpeedControlServer(self.dir_, settings, rpc_server=self.rpc_server,
                                       counter_server=counter_server)
        self.cli = SpeedControlClient(self.serv, 'localhost', 0)
        
        self.assertEqual(self.cli.require(10), (10, 0))
        
        self.serv.set_speed(100)

        almost = lambda left, right: left[0] == right[0] \
                                     and abs(left[1] - right[1]) < 0.1

        self.assertTrue(almost(self.cli.require(100), (100, 0.5)))
        self.assertTrue(almost(self.cli.require(1), (0, 0.5)))
        
        self.serv.set_instance_speed(50)
        self.serv.calc_spans()
        self.serv.reset()
        self.assertTrue(almost(self.cli.require(50), (50, 1.1)))
        self.assertTrue(almost(self.cli.require(1), (0, 1.1)))
        
        self.serv.set_adaptive(True)
        addr = 'localhost#0'
        self.serv.counter_server.acc(addr, 'banned_start', 1100)
        self.serv.counter_server.acc(addr, 'banned_end', 1500)
        self.serv.counter_server.acc(addr, 'normal_start', 1000)
        self.serv.counter_server.acc(addr, 'normal_end', 1100)
        self.serv.counter_server.acc(addr, 'normal_pages', 200)
        self.serv.counter_server.inc(addr, 'pages', 500)
        self.serv.counter_server.inc(addr, 'secs', 1000)
        self.serv.calc_spans()
        self.serv.reset()
        self.assertTrue(almost(self.cli.require(24), (24, 0.5)))
        self.assertTrue(almost(self.cli.require(1), (0, 0.5)))
Пример #2
0
 def _init_speed_server(self):
     speed_dir = os.path.join(self.working_dir, 'speed')
     self.speed_server = SpeedControlServer(speed_dir,
                                            self.settings,
                                            rpc_server=self.rpc_server,
                                            app_name=self.job_name)