Ejemplo n.º 1
0
    def summary(self):
        available_resources = reduce(add_resources,
                                     self.dynamic_resources_by_ip.values()
                                     ) if self.dynamic_resources_by_ip else {}
        total_resources = reduce(add_resources,
                                 self.static_resources_by_ip.values()
                                 ) if self.static_resources_by_ip else {}
        usage_dict = {}
        for key in total_resources:
            if key in ["memory", "object_store_memory"]:
                total = total_resources[key] * \
                    ray.ray_constants.MEMORY_RESOURCE_UNIT_BYTES
                available = available_resources[key] * \
                    ray.ray_constants.MEMORY_RESOURCE_UNIT_BYTES
                usage_dict[key] = (total - available, total)
            else:
                total = total_resources[key]
                usage_dict[key] = (total - available_resources[key], total)

        summarized_demand_vector = freq_of_dicts(
            self.get_resource_demand_vector(clip=False))
        summarized_resource_requests = freq_of_dicts(
            self.get_resource_requests())

        def placement_group_serializer(pg):
            bundles = tuple(
                frozenset(bundle.unit_resources.items())
                for bundle in pg.bundles)
            return (bundles, pg.strategy)

        def placement_group_deserializer(pg_tuple):
            # We marshal this as a dictionary so that we can easily json.dumps
            # it later.
            # TODO (Alex): Would there be a benefit to properly
            # marshalling this (into a protobuf)?
            bundles = list(map(dict, pg_tuple[0]))
            return {
                "bundles": freq_of_dicts(bundles),
                "strategy": PlacementStrategy.Name(pg_tuple[1])
            }

        summarized_placement_groups = freq_of_dicts(
            self.get_pending_placement_groups(),
            serializer=placement_group_serializer,
            deserializer=placement_group_deserializer)
        nodes_summary = freq_of_dicts(self.static_resources_by_ip.values())

        return LoadMetricsSummary(
            head_ip=self.local_ip,
            usage=usage_dict,
            resource_demand=summarized_demand_vector,
            pg_demand=summarized_placement_groups,
            request_demand=summarized_resource_requests,
            node_types=nodes_summary)
Ejemplo n.º 2
0
 def placement_group_deserializer(pg_tuple):
     # We marshal this as a dictionary so that we can easily json.dumps
     # it later.
     # TODO (Alex): Would there be a benefit to properly
     # marshalling this (into a protobuf)?
     bundles = list(map(dict, pg_tuple[0]))
     return {
         "bundles": freq_of_dicts(bundles),
         "strategy": PlacementStrategy.Name(pg_tuple[1])
     }