Beispiel #1
0
  def __init__(self, pplan_helper, in_stream, out_stream, looper):
    self.pplan_helper = pplan_helper
    self.in_stream = in_stream
    self.output_helper = OutgoingTupleHelper(self.pplan_helper, out_stream)
    self.looper = looper
    self.sys_config = system_config.get_sys_config()

    # will set a root logger here
    self.logger = logging.getLogger()
  def register_metrics(self, context):
    """Registers metrics to context

    :param context: Topology Context
    """
    sys_config = system_config.get_sys_config()
    interval = float(sys_config[constants.HERON_METRICS_EXPORT_INTERVAL_SEC])
    collector = context.get_metrics_collector()
    super(ComponentMetrics, self).register_metrics(collector, interval)
Beispiel #3
0
    def __init__(self, pplan_helper, in_stream, out_stream, looper):
        self.pplan_helper = pplan_helper
        self.in_stream = in_stream
        self.output_helper = OutgoingTupleHelper(self.pplan_helper, out_stream)
        self.looper = looper
        self.sys_config = system_config.get_sys_config()

        # will set a root logger here
        self.logger = logging.getLogger()
Beispiel #4
0
 def __init__(self, metrics_collector):
     self.process = psutil.Process()
     # total sys cpu time
     self.sys_cpu_time = AssignableMetrics(0)
     # total user cpu time
     self.user_cpu_time = AssignableMetrics(0)
     # threads cpu usage
     self.threads = AssignableMetrics(0)
     # number of open file descriptors
     self.fd_nums = AssignableMetrics(0)
     # number of threads
     self.num_threads = AssignableMetrics([])
     # rss: aka "Resident Set Size"
     # this is the non-swapped physical memory a process has used.
     self.physical_memory = AssignableMetrics(0)
     # vms: "Virtual Memory Size", this is the total
     # amount of virtual memory used by the process.
     self.virtual_memory = AssignableMetrics(0)
     # stats about three generations of GC
     # count is the number of objects in one generation
     # threshold is the collect frequency of one generation
     self.g1_count, self.g1_threshold = AssignableMetrics(
         0), AssignableMetrics(0)
     self.g2_count, self.g2_threshold = AssignableMetrics(
         0), AssignableMetrics(0)
     self.g3_count, self.g3_threshold = AssignableMetrics(
         0), AssignableMetrics(0)
     PY_SYS_CPU_TIME = '__py-sys-cpu-time-secs'
     PY_USER_CPU_TIME = '__py-user-cpu-time-secs'
     PY_FD_NUMS = '__py-file-descriptors-number'
     PY_PHYSICAL_MEMORY = '__py-physical-memory-byte'
     PY_VIRTUAL_MEMORY = '__py-virtual-memory-byte'
     PY_GC_GENERATION_1_COUNT = '__py-generation-1-count'
     PY_GC_GENERATION_2_COUNT = '__py-generation-2-count'
     PY_GC_GENERATION_3_COUNT = '__py-generation-3-count'
     PY_GC_GENERATION_1_THRESHOLD = '__py-generation-1-collection-threshold'
     PY_GC_GENERATION_2_THRESHOLD = '__py-generation-2-collection-threshold'
     PY_GC_GENERATION_3_THRESHOLD = '__py-generation-3-collection-threshold'
     self.metrics = {
         PY_SYS_CPU_TIME: self.sys_cpu_time,
         PY_USER_CPU_TIME: self.user_cpu_time,
         PY_FD_NUMS: self.fd_nums,
         PY_PHYSICAL_MEMORY: self.physical_memory,
         PY_VIRTUAL_MEMORY: self.virtual_memory,
         PY_GC_GENERATION_1_COUNT: self.g1_count,
         PY_GC_GENERATION_2_COUNT: self.g2_count,
         PY_GC_GENERATION_3_COUNT: self.g3_count,
         PY_GC_GENERATION_1_THRESHOLD: self.g1_threshold,
         PY_GC_GENERATION_2_THRESHOLD: self.g2_threshold,
         PY_GC_GENERATION_3_THRESHOLD: self.g3_threshold
     }
     super(PyMetrics, self).__init__(self.metrics)
     sys_config = system_config.get_sys_config()
     interval = float(
         sys_config[constants.HERON_METRICS_EXPORT_INTERVAL_SEC])
     self.register_metrics(metrics_collector, interval)
Beispiel #5
0
    def register_metrics(self, context):
        """Registers metrics to context

    :param context: Topology Context
    """
        sys_config = system_config.get_sys_config()
        interval = float(
            sys_config[constants.HERON_METRICS_EXPORT_INTERVAL_SEC])
        collector = context.get_metrics_collector()
        super(ComponentMetrics, self).register_metrics(collector, interval)
Beispiel #6
0
 def __init__(self, looper, heron_instance_cls, strmgr_host, port, topology_name, topology_id,
              instance, sock_map, gateway_metrics, socket_options):
   HeronClient.__init__(self, looper, strmgr_host, port, sock_map, socket_options)
   self.heron_instance_cls = heron_instance_cls
   self.topology_name = topology_name
   self.topology_id = topology_id
   # physical_plan_pb2.Instance message
   self.instance = instance
   self.gateway_metrics = gateway_metrics
   self._pplan_helper = None
   self.sys_config = system_config.get_sys_config()
Beispiel #7
0
    def __init__(self, topology_name, topology_id, instance, stream_port,
                 metrics_port, topo_pex_file_path):
        # Basic information about this heron instance
        self.topology_name = topology_name
        self.topology_id = topology_id
        self.instance = instance
        self.stream_port = stream_port
        self.metrics_port = metrics_port
        self.topo_pex_file_abs_path = os.path.abspath(topo_pex_file_path)
        self.sys_config = system_config.get_sys_config()

        self.in_stream = HeronCommunicator(producer_cb=None, consumer_cb=None)
        self.out_stream = HeronCommunicator(producer_cb=None, consumer_cb=None)

        self.socket_map = dict()
        self.looper = GatewayLooper(self.socket_map)

        # Initialize metrics related
        self.out_metrics = HeronCommunicator()
        self.out_metrics.\
          register_capacity(self.sys_config[constants.INSTANCE_INTERNAL_METRICS_WRITE_QUEUE_CAPACITY])
        self.metrics_collector = MetricsCollector(self.looper,
                                                  self.out_metrics)
        self.gateway_metrics = GatewayMetrics(self.metrics_collector)
        self.py_metrics = PyMetrics(self.metrics_collector)

        # Create socket options and socket clients
        socket_options = create_socket_options()
        self._stmgr_client = \
          SingleThreadStmgrClient(self.looper, self, self.STREAM_MGR_HOST, stream_port,
                                  topology_name, topology_id, instance, self.socket_map,
                                  self.gateway_metrics, socket_options)
        self._metrics_client = \
          MetricsManagerClient(self.looper, self.METRICS_MGR_HOST, metrics_port, instance,
                               self.out_metrics, self.in_stream, self.out_stream,
                               self.socket_map, socket_options, self.gateway_metrics, self.py_metrics)
        self.my_pplan_helper = None
        self.serializer = None

        # my_instance is a AssignedInstance tuple
        self.my_instance = None
        self.is_instance_started = False
        self.is_stateful_started = False
        self.stateful_state = None

        # Debugging purposes
        def go_trace(_, stack):
            with open("/tmp/trace.log", "w") as f:
                traceback.print_stack(stack, file=f)
            self.looper.register_timer_task_in_sec(self.looper.exit_loop, 0.0)

        signal.signal(signal.SIGUSR1, go_trace)
Beispiel #8
0
 def __init__(self, metrics_collector):
   self.process = psutil.Process()
   # total sys cpu time
   self.sys_cpu_time = AssignableMetrics(0)
   # total user cpu time
   self.user_cpu_time = AssignableMetrics(0)
   # threads cpu usage
   self.threads = MultiAssignableMetrics()
   # number of open file descriptors
   self.fd_nums = AssignableMetrics(0)
   # number of threads
   self.num_threads = AssignableMetrics([])
   # rss: aka "Resident Set Size"
   # this is the non-swapped physical memory a process has used.
   self.physical_memory = AssignableMetrics(0)
   # vms: "Virtual Memory Size", this is the total
   # amount of virtual memory used by the process.
   self.virtual_memory = AssignableMetrics(0)
   # stats about three generations of GC
   # count is the number of objects in one generation
   # threshold is the collect frequency of one generation
   self.g1_count, self.g1_threshold = AssignableMetrics(0), AssignableMetrics(0)
   self.g2_count, self.g2_threshold = AssignableMetrics(0), AssignableMetrics(0)
   self.g3_count, self.g3_threshold = AssignableMetrics(0), AssignableMetrics(0)
   PY_SYS_CPU_TIME = '__py-sys-cpu-time-secs'
   PY_USER_CPU_TIME = '__py-user-cpu-time-secs'
   PY_FD_NUMS = '__py-file-descriptors-number'
   PY_PHYSICAL_MEMORY = '__py-physical-memory-byte'
   PY_VIRTUAL_MEMORY = '__py-virtual-memory-byte'
   PY_GC_GENERATION_1_COUNT = '__py-generation-1-count'
   PY_GC_GENERATION_2_COUNT = '__py-generation-2-count'
   PY_GC_GENERATION_3_COUNT = '__py-generation-3-count'
   PY_GC_GENERATION_1_THRESHOLD = '__py-generation-1-collection-threshold'
   PY_GC_GENERATION_2_THRESHOLD = '__py-generation-2-collection-threshold'
   PY_GC_GENERATION_3_THRESHOLD = '__py-generation-3-collection-threshold'
   self.metrics = {PY_SYS_CPU_TIME: self.sys_cpu_time,
                   PY_USER_CPU_TIME: self.user_cpu_time,
                   PY_FD_NUMS: self.fd_nums,
                   PY_PHYSICAL_MEMORY: self.physical_memory,
                   PY_VIRTUAL_MEMORY: self.virtual_memory,
                   PY_GC_GENERATION_1_COUNT: self.g1_count,
                   PY_GC_GENERATION_2_COUNT: self.g2_count,
                   PY_GC_GENERATION_3_COUNT: self.g3_count,
                   PY_GC_GENERATION_1_THRESHOLD: self.g1_threshold,
                   PY_GC_GENERATION_2_THRESHOLD: self.g2_threshold,
                   PY_GC_GENERATION_3_THRESHOLD: self.g3_threshold}
   super(PyMetrics, self).__init__(self.metrics)
   sys_config = system_config.get_sys_config()
   interval = float(sys_config[constants.HERON_METRICS_EXPORT_INTERVAL_SEC])
   self.register_metrics(metrics_collector, interval)
Beispiel #9
0
    def __init__(self, looper, metrics_host, port, instance, out_metrics,
                 in_stream, out_stream, sock_map, socket_options,
                 gateway_metrics):
        HeronClient.__init__(self, looper, metrics_host, port, sock_map,
                             socket_options)
        self.instance = instance
        self.out_queue = out_metrics
        self.in_stream = in_stream
        self.out_stream = out_stream
        self.gateway_metrics = gateway_metrics
        self.sys_config = system_config.get_sys_config()

        self._add_metrics_client_tasks()
        Log.debug('start updating in and out stream metrics')
        self._update_in_out_stream_metrics_tasks()
Beispiel #10
0
  def __init__(self, looper, metrics_host, port, instance,
               out_metrics, in_stream, out_stream, sock_map, socket_options,
               gateway_metrics, py_metrics):
    HeronClient.__init__(self, looper, metrics_host, port, sock_map, socket_options)
    self.instance = instance
    self.out_queue = out_metrics
    self.in_stream = in_stream
    self.out_stream = out_stream
    self.gateway_metrics = gateway_metrics
    self.py_metrics = py_metrics
    self.sys_config = system_config.get_sys_config()

    self._add_metrics_client_tasks()
    Log.debug('start updating in and out stream metrics')
    self._update_in_out_stream_metrics_tasks()
    self._update_py_metrics()
Beispiel #11
0
  def __init__(self, pplan_helper, in_stream, out_stream, looper):
    self.pplan_helper = pplan_helper
    self.in_stream = in_stream
    self.output_helper = OutgoingTupleHelper(self.pplan_helper, out_stream)
    self.looper = looper
    self.sys_config = system_config.get_sys_config()

    # will set a root logger here
    self.logger = logging.getLogger()
    context = pplan_helper.context
    mode = context.get_cluster_config().get(api_constants.TOPOLOGY_RELIABILITY_MODE,
                                            api_constants.TopologyReliabilityMode.ATMOST_ONCE)
    self.is_stateful = bool(mode == api_constants.TopologyReliabilityMode.EXACTLY_ONCE)
    self._stateful_state = None
    self.serializer = SerializerHelper.get_serializer(pplan_helper.context)
    self._initialized_global_metrics = False
Beispiel #12
0
  def __init__(self, topology_name, topology_id, instance,
               stream_port, metrics_port, topo_pex_file_path):
    # Basic information about this heron instance
    self.topology_name = topology_name
    self.topology_id = topology_id
    self.instance = instance
    self.stream_port = stream_port
    self.metrics_port = metrics_port
    self.topo_pex_file_abs_path = os.path.abspath(topo_pex_file_path)
    self.sys_config = system_config.get_sys_config()

    self.in_stream = HeronCommunicator(producer_cb=None, consumer_cb=None)
    self.out_stream = HeronCommunicator(producer_cb=None, consumer_cb=None)

    self.socket_map = dict()
    self.looper = GatewayLooper(self.socket_map)

    # Initialize metrics related
    self.out_metrics = HeronCommunicator()
    self.out_metrics.\
      register_capacity(self.sys_config[constants.INSTANCE_INTERNAL_METRICS_WRITE_QUEUE_CAPACITY])
    self.metrics_collector = MetricsCollector(self.looper, self.out_metrics)
    self.gateway_metrics = GatewayMetrics(self.metrics_collector)
    self.py_metrics = PyMetrics(self.metrics_collector)

    # Create socket options and socket clients
    socket_options = create_socket_options()
    self._stmgr_client = \
      SingleThreadStmgrClient(self.looper, self, self.STREAM_MGR_HOST, stream_port,
                              topology_name, topology_id, instance, self.socket_map,
                              self.gateway_metrics, socket_options)
    self._metrics_client = \
      MetricsManagerClient(self.looper, self.METRICS_MGR_HOST, metrics_port, instance,
                           self.out_metrics, self.in_stream, self.out_stream,
                           self.socket_map, socket_options, self.gateway_metrics, self.py_metrics)
    self.my_pplan_helper = None

    # my_instance is a AssignedInstance tuple
    self.my_instance = None
    self.is_instance_started = False

    # Debugging purposes
    def go_trace(_, stack):
      with open("/tmp/trace.log", "w") as f:
        traceback.print_stack(stack, file=f)
      self.looper.register_timer_task_in_sec(self.looper.exit_loop, 0.0)
    signal.signal(signal.SIGUSR1, go_trace)
  def __init__(self, pplan_helper, out_stream):
    self.out_stream = out_stream
    self.pplan_helper = pplan_helper

    self.current_data_tuple_set = None
    self.current_control_tuple_set = None

    self.current_data_tuple_size_in_bytes = 0
    self.total_data_emitted_in_bytes = 0

    self.sys_config = system_config.get_sys_config()

    # read the config values
    self.data_tuple_set_capacity = self.sys_config[constants.INSTANCE_SET_DATA_TUPLE_CAPACITY]
    self.max_data_tuple_size_in_bytes =\
      self.sys_config.get(constants.INSTANCE_SET_DATA_TUPLE_SIZE_BYTES, sys.maxint)
    self.control_tuple_set_capacity = self.sys_config[constants.INSTANCE_SET_CONTROL_TUPLE_CAPACITY]
Beispiel #14
0
  def __init__(self, pplan_helper, out_stream):
    self.out_stream = out_stream
    self.pplan_helper = pplan_helper

    self.current_data_tuple_set = None
    self.current_control_tuple_set = None

    self.current_data_tuple_size_in_bytes = 0
    self.total_data_emitted_in_bytes = 0

    self.sys_config = system_config.get_sys_config()

    # read the config values
    self.data_tuple_set_capacity = self.sys_config[constants.INSTANCE_SET_DATA_TUPLE_CAPACITY]
    self.max_data_tuple_size_in_bytes =\
      self.sys_config.get(constants.INSTANCE_SET_DATA_TUPLE_SIZE_BYTES, sys.maxint)
    self.control_tuple_set_capacity = self.sys_config[constants.INSTANCE_SET_CONTROL_TUPLE_CAPACITY]
Beispiel #15
0
def create_socket_options():
  """Creates SocketOptions object from a given sys_config dict"""
  sys_config = system_config.get_sys_config()
  opt_list = [const.INSTANCE_NETWORK_WRITE_BATCH_SIZE_BYTES,
              const.INSTANCE_NETWORK_WRITE_BATCH_TIME_MS,
              const.INSTANCE_NETWORK_READ_BATCH_SIZE_BYTES,
              const.INSTANCE_NETWORK_READ_BATCH_TIME_MS,
              const.INSTANCE_NETWORK_OPTIONS_SOCKET_RECEIVED_BUFFER_SIZE_BYTES,
              const.INSTANCE_NETWORK_OPTIONS_SOCKET_SEND_BUFFER_SIZE_BYTES]

  Log.debug("In create_socket_options()")
  try:
    value_lst = [int(sys_config[opt]) for opt in opt_list]
    sock_opt = SocketOptions(*value_lst)
    return sock_opt
  except ValueError as e:
    # couldn't convert to int
    raise ValueError("Invalid value in sys_config: %s" % e.message)
  except KeyError as e:
    # option key was not found
    raise KeyError("Incomplete sys_config: %s" % e.message)
Beispiel #16
0
def create_socket_options():
  """Creates SocketOptions object from a given sys_config dict"""
  sys_config = system_config.get_sys_config()
  opt_list = [const.INSTANCE_NETWORK_WRITE_BATCH_SIZE_BYTES,
              const.INSTANCE_NETWORK_WRITE_BATCH_TIME_MS,
              const.INSTANCE_NETWORK_READ_BATCH_SIZE_BYTES,
              const.INSTANCE_NETWORK_READ_BATCH_TIME_MS,
              const.INSTANCE_NETWORK_OPTIONS_SOCKET_RECEIVED_BUFFER_SIZE_BYTES,
              const.INSTANCE_NETWORK_OPTIONS_SOCKET_SEND_BUFFER_SIZE_BYTES]

  Log.debug("In create_socket_options()")
  try:
    value_lst = [int(sys_config[opt]) for opt in opt_list]
    sock_opt = SocketOptions(*value_lst)
    return sock_opt
  except ValueError as e:
    # couldn't convert to int
    raise ValueError("Invalid value in sys_config: %s" % e.message)
  except KeyError as e:
    # option key was not found
    raise KeyError("Incomplete sys_config: %s" % e.message)
 def __init__(self, metrics_collector):
   sys_config = system_config.get_sys_config()
   super(GatewayMetrics, self).__init__(self.metrics)
   interval = float(sys_config[constants.HERON_METRICS_EXPORT_INTERVAL_SEC])
   self.register_metrics(metrics_collector, interval)
Beispiel #18
0
 def __init__(self, metrics_collector):
     sys_config = system_config.get_sys_config()
     super(GatewayMetrics, self).__init__(self.metrics)
     interval = float(
         sys_config[constants.HERON_METRICS_EXPORT_INTERVAL_SEC])
     self.register_metrics(metrics_collector, interval)