def stop_all_p(): processor_manager = app.config['PROCESSOR_MANAGER'] processors = Processor.from_json_request(request.json, many=True) names = list(map(lambda psor: psor.name, processors)) results = [] for name in names: processor = _stop_p(name, processor_manager) results.append(processor) response = Processor.to_json_responses(*results, time.time()) return jsonify(response)
def run_all_p(): process_manager = app.config['PROCESS_MANAGER'] processor_manager = app.config['PROCESSOR_MANAGER'] body = request.json processors = Processor.from_json_request(body, many=True) results = [] for processor in processors: name = processor.name processor = _run_p(name, processor, processor_manager, process_manager) results.append(processor) response = Processor.to_json_responses(*results, time.time()) return jsonify(response)
def get_all_p(): processor_manager = app.config['PROCESSOR_MANAGER'] processors = list( map(lambda processor_state: processor_state['processor'], processor_manager)) response = Processor.to_json_responses(*processors, timestamp=time.time()) return jsonify(response)
def run_p(name): process_manager = app.config['PROCESS_MANAGER'] processor_manager = app.config['PROCESSOR_MANAGER'] body = request.json processor = Processor.from_json_request(body) processor = _run_p(name, processor, processor_manager, process_manager) response = processor.to_json_response(time.time()) return jsonify(response)
def get_p(name): processor_manager = app.config['PROCESSOR_MANAGER'] processor_state = find_processor_state_by_name(name, processor_manager) if processor_state is not None: response = processor_state['processor'].to_json_response(time.time()) else: response = Processor( name=name, error_code='Processor is not found').to_json_response(time.time()) return jsonify(response)
def _stop_p(name, processor_manager): processor_state = find_processor_state_by_name(name, processor_manager) if processor_state is not None and processor_state[ 'processor'].status == 'running': stop_signal = processor_state['stop_signal'] state = processor_state['state'] p = processor_state['process'] processor = processor_state['processor'] stop_signal.set() while state.value != 'stopped': pass processor.status = state.value logging.info('Stop a processor: ' + name) elif processor_state is not None and processor_state[ 'processor'].status == 'stopped': processor = Processor(name=name, error_code='Processor was already stopped') logging.info('Processor was already stopped') else: processor = Processor(name=name, error_code='Processor not found') logging.info('Processor is not found') return processor
def initialize_processors(): candidates = os.listdir(os.path.join('processors', 'pretrained_models')) processor_names = list(map(lambda c: c.replace('.pkl', ''), candidates)) logging.info('Found processors: ' + ','.join(processor_names)) for name in processor_names: app.config['PROCESSOR_MANAGER'].append({ 'processor': Processor(name=name, status='stopped'), 'stop_signal': None, 'state': None, 'process': None })
def simulation(self, exp_lambda: float = None, b: float = None, a: float = None, count_request: int = 100): if exp_lambda is None: exp_lambda = self.exp_lambda if a is None: a = self.a if b is None: b = self.b if count_request is None: count_request = self.count_request # print('norm SIGMA', a) #v8 # self._generator = RequestGenerator(NormalGenerator(a, b)) # self._processor = Processor(ExponentialGenerator(exp_lambda)) ################################## # print(a,b, exp_lambda) self._generator = RequestGenerator(ExponentialGenerator(exp_lambda)) self._processor = Processor(UniformGenerator(a, b)) self._generator.add_receiver(self._processor) times = [self._generator, self._processor] current_time = 0 while self._processor.requests_processed < count_request: current_time += times[0].next_eval_time for i in range(len(times) - 1, -1, -1): times[i].time_pass(times[0].next_eval_time) times[0].process() times.sort(key=lambda x: x.next_eval_time) gen_int = self._generator.intensity pro_int = self._processor.intensity if pro_int != 0: load = gen_int / pro_int else: load = 0 yield (gen_int, pro_int, load, self._processor.requests_processed, current_time)