async def __init__( self, controller_name: str, http_config: HTTPOptions, checkpoint_path: str, detached: bool = False, _override_controller_namespace: Optional[str] = None, ): # Used to read/write checkpoints. self.controller_namespace = ray.get_runtime_context().namespace self.controller_name = controller_name self.checkpoint_path = checkpoint_path kv_store_namespace = f"{self.controller_name}-{self.controller_namespace}" self.kv_store = make_kv_store(checkpoint_path, namespace=kv_store_namespace) self.snapshot_store = RayInternalKVStore(namespace=kv_store_namespace) # Dictionary of deployment_name -> proxy_name -> queue length. self.deployment_stats = defaultdict(lambda: defaultdict(dict)) # Used to ensure that only a single state-changing operation happens # at any given time. self.write_lock = asyncio.Lock() self.long_poll_host = LongPollHost() self.http_state = HTTPState( controller_name, detached, http_config, _override_controller_namespace=_override_controller_namespace, ) self.endpoint_state = EndpointState(self.kv_store, self.long_poll_host) # Fetch all running actors in current cluster as source of current # replica state for controller failure recovery all_current_actor_names = ray.util.list_named_actors() self.deployment_state_manager = DeploymentStateManager( controller_name, detached, self.kv_store, self.long_poll_host, all_current_actor_names, _override_controller_namespace=_override_controller_namespace, ) # TODO(simon): move autoscaling related stuff into a manager. self.autoscaling_metrics_store = InMemoryMetricsStore() asyncio.get_event_loop().create_task(self.run_control_loop())
def test_basics(self): s = InMemoryMetricsStore() s.add_metrics_point({"m1": 1}, timestamp=1) s.add_metrics_point({"m1": 2}, timestamp=2) assert s.window_average("m1", window_start_timestamp_s=0) == 1.5
def test_multiple_metrics(self): s = InMemoryMetricsStore() s.add_metrics_point({"m1": 1, "m2": -1}, timestamp=1) s.add_metrics_point({"m1": 2, "m2": -2}, timestamp=2) assert s.window_average("m1", window_start_timestamp_s=0) == 1.5 assert s.window_average("m2", window_start_timestamp_s=0) == -1.5