def __init__(self, config_file: str = None): if sys.version_info.major < 3: python_version = str(sys.version_info.major) + "." + str( sys.version_info.minor) raise RuntimeError("Requires python 3.6 and above. Actual: " + python_version) self.origin = 'py' + (''.join(str(uuid.uuid4()).split('-'))) self.config = ConfigReader(config_file) self.util = Utility() log_dir = self.config.get_property('log.directory') log_file = self.config.get_property('log.filename') log_level = self.config.get_property('log.level') self._max_threads = self.config.get('max.threads') self.work_dir = self.config.get_property('work.directory') self.log = LoggingService(log_dir=log_dir, log_file=log_file, log_level=log_level).get_logger() self._loop = asyncio.new_event_loop() # DO NOT CHANGE 'distributed.trace.processor' which is an optional user defined trace aggregator my_tracer = DistributedTrace(self, 'distributed.trace.processor') my_nc = self.config.get_property('network.connector') self._cloud = NetworkConnector(self, my_tracer, self._loop, my_nc, self.origin) self._function_queues = dict() self._executor = concurrent.futures.ThreadPoolExecutor( max_workers=self._max_threads) self.log.info("Concurrent thread pool = " + str(self._max_threads)) # # Before we figure out how to solve blocking file I/O, we will regulate event output rate. # my_test_dir = self.util.normalize_path(self.work_dir + "/test") if not os.path.exists(my_test_dir): os.makedirs(my_test_dir) self._throttle = Throttle(self.util.normalize_path(my_test_dir + "/to_be_deleted"), log=self.log) self._seq = 0 self.util.cleanup_dir(my_test_dir) self.log.info("Estimated performance is " + format(self._throttle.get_tps(), ',d') + " events per second") self.running = True self.stopped = False # distributed trace sessions self._traces = {} # start event loop in a new thread to avoid blocking the main thread def main_event_loop(): self.log.info("Event system started") self._loop.run_forever() self.log.info("Event system stopped") self._loop.close() threading.Thread(target=main_event_loop).start()
def __init__(self, work_dir: str = None, log_file: str = None, log_level: str = None, max_threads: int = None, network_connector: str = None): if sys.version_info.major < 3: python_version = str(sys.version_info.major) + "." + str( sys.version_info.minor) raise RuntimeError("Requires python 3.6 and above. Actual: " + python_version) self.util = Utility() self.origin = 'py' + (''.join(str(uuid.uuid4()).split('-'))) config = AppConfig() my_log_file = (config.LOG_FILE if hasattr(config, 'LOG_FILE') else None) if log_file is None else log_file my_log_level = config.LOG_LEVEL if log_level is None else log_level self._max_threads = config.MAX_THREADS if max_threads is None else max_threads self.work_dir = config.WORK_DIRECTORY if work_dir is None else work_dir self.log = LoggingService( log_dir=self.util.normalize_path(self.work_dir + "/log"), log_file=my_log_file, log_level=my_log_level).get_logger() self._loop = asyncio.new_event_loop() my_distributed_trace = DistributedTrace( self, config.DISTRIBUTED_TRACE_PROCESSOR) my_connector = config.NETWORK_CONNECTOR if network_connector is None else network_connector self._cloud = NetworkConnector(self, my_distributed_trace, self._loop, my_connector, self.origin) self._function_queues = dict() self._executor = concurrent.futures.ThreadPoolExecutor( max_workers=self._max_threads) self.log.info("Concurrent thread pool = " + str(self._max_threads)) # # Before we figure out how to solve blocking file I/O, we will regulate event output rate. # my_test_dir = self.util.normalize_path(self.work_dir + "/test") if not os.path.exists(my_test_dir): os.makedirs(my_test_dir) self._throttle = Throttle(self.util.normalize_path(my_test_dir + "/to_be_deleted"), log=self.log) self._seq = 0 self.util.cleanup_dir(my_test_dir) self.log.debug("Estimated processing rate is " + format(self._throttle.get_tps(), ',d') + " events per second for this computer") self.running = True self.stopped = False # distributed trace sessions self._traces = {} # start event loop in a new thread to avoid blocking the main thread def main_event_loop(): self.log.info("Event system started") self._loop.run_forever() self.log.info("Event system stopped") self._loop.close() threading.Thread(target=main_event_loop).start()