Example #1
0
 def push(self, data):
     if not self.receiver_list:
         log.info('got data, size={}'.format(len(data)))
         return 'receive data'
     else:
         result = self._compute(data, self.extra_param_list)
         for next_ip, next_port in self.receiver_list:
             log.info('push data to {}:{}'.format(next_ip, next_port))
             ClientGen.call(next_ip, next_port, 'push', result)
         # logging
         log.info('got data: {}'.format(data))
         log.info('compute result: {}'.format(result))
         return 'recieve and forward data: {} bytes'.format(len(data))
Example #2
0
    def _compute(self, data, extra_param_list):
        t1 = time.time()
        log.info('(TIME) start computation: {}'.format(t1))
        log.info('finding object')
        mode = extra_param_list[0]
        if mode == 'offload':
            next_ip, next_port = extra_param_list[1].split(':')
            next_port = int(next_port)
            log.info('push data to {}:{}'.format(next_ip, next_port))
            result = ClientGen.call(next_ip, next_port, 'push', data)
        else:
            yolo_folder = '/opt/github/darknet'
            image_data = base64.b64decode(data)
            image = Image.open(io.BytesIO(image_data))
            img_name = 'img_{}.png'.format(self._imgid)
            self._imgid += 1
            image.save('{}/{}'.format(yolo_folder, img_name), 'PNG')
            cmd = (
                './darknet detect cfg/yolov3-tiny.cfg '
                'yolov3-tiny.weights {}').format(img_name),
            proc = subprocess.Popen(
                cmd, stdout=subprocess.PIPE, shell=True, cwd=yolo_folder,)
            result = proc.communicate()[0]
            if self.exec_delay_time_sec > 0:
                time.sleep(self.exec_delay_time_sec)
            t2 = time.time()
        if self.exec_delay_time_sec > 0:
            time.sleep(self.exec_delay_time_sec)
        t2 = time.time()
        # logging
        log.info('compute result: {}'.format(result))

        log.info('(TIME) stop computation: {}'.format(t2))
        log.info('computation result:\n{}'.format(result))
        return 'exec_time: {}, result:\n{}'.format(t2-t1, result)
Example #3
0
 def run_client(cls, args):
     name = args.name
     ip, port = cls._split_addr(args.address)
     method = args.method
     args_list = args.args_list
     update_rootlogger(name, is_log_to_file=True)
     result = ClientGen.call(ip, port, method, *args_list)
     log.info('result: {}'.format(result))
Example #4
0
 def init_deploy(self, mapping, device_addr):
     log.info('deploy {} ===='.format(self.cur_deploy_cnt))
     for task, device in iteritems(mapping):
         ip, port = device_addr[device]
         result = ClientGen.call(ip, port, 'fetch_from', task,
                                 self.fileserver_ip, self.fileserver_port)
         log.info('depoly {} to {}: {}'.format(task, device, result))
     self.cur_map = mapping
     self.cur_deploy_cnt += 1
Example #5
0
 def client_send_file(cls, args):
     name = args.name
     ip, port = cls._split_addr(args.address)
     method = args.method
     args_list = args.args_list
     update_rootlogger(name, is_log_to_file=True)
     assert len(args_list) == 1
     filepath = args_list[0]
     with open(filepath, 'rb') as binary_file:
         # Read the whole file at once
         data = binary_file.read()
     new_args_list = [base64.b64encode(data)]
     result = ClientGen.call(ip, port, method, *new_args_list)
     log.info('file sent: size={}'.format(len(result)))
Example #6
0
 def re_deploy(self, mapping, device_addr):
     log.info('deploy {} ===='.format(self.cur_deploy_cnt))
     for task, device in iteritems(mapping):
         device_has_task = self.cur_map[task]
         if device_has_task == device:
             continue
         ip, port = device_addr[device]
         server_ip, server_port = device_addr[device_has_task]
         result = ClientGen.call(ip, port, 'fetch_from', task, server_ip,
                                 server_port)
         log.info('move {} from {} to {}: {}'.format(
             task, device_has_task, device, result))
     self.cur_map = mapping
     self.cur_deploy_cnt += 1
Example #7
0
 def _send_data(self, *args):
     data = self.datagen_func(*args)
     for ip, port in self.receiver_list:
         ClientGen.call(ip, port, 'push', data)
Example #8
0
 def trigger_start_prog(agent, ip, port, command):
     log.info('ask agent {} to run command: {}'.format(agent, command))
     result = ClientGen.call(ip, port, 'start_prog', command)
     log.info('result: {}'.format(result))
Example #9
0
 def clean_up(self, servermap):
     for ip, port in iteritems(servermap):
         result = ClientGen.call(ip, port, 'STOP')
         log.info('stop server @{}:{}, {}'.format(ip, port, result))
Example #10
0
 def fetch_from(self, filename, from_ip, from_port):
     result = ClientGen.call(from_ip, from_port, 'fetch', filename)
     return 'fetch {} from {}:{}, got: {}'.format(filename, from_ip,
                                                  from_port, result)