Exemplo n.º 1
0
    def start_zmq_serving_with_args(self):
        '''
        Start one PaddleHub-Serving instance by arguments with zmq.
        '''
        if self.modules_info is not None:
            for module, info in self.modules_info.items():
                CacheUpdater("hub_serving_start", module=module, version=info['init_args']['version']).start()
            front_port = self.args.port
            if is_port_occupied("127.0.0.1", front_port) is True:
                log.logger.error("Port %s is occupied, please change it." % front_port)
                return False
            back_port = int(front_port) + 1
            for index in range(100):
                if not is_port_occupied("127.0.0.1", back_port):
                    break
                else:
                    back_port = int(back_port) + 1
            else:
                raise RuntimeError(
                    "Port from %s to %s is occupied, please use another port" % (int(front_port) + 1, back_port))
            self.dump_pid_file()
            run_all(self.modules_info, self.args.gpu, front_port, back_port)

        else:
            log.logger.error("Lack of necessary parameters!")
Exemplo n.º 2
0
 def start_single_app_with_args(self):
     '''
     Start one PaddleHub-Serving instance by arguments with flask.
     '''
     module = self.args.modules
     if module is not None:
         port = self.args.port
         if is_port_occupied("127.0.0.1", port) is True:
             log.logger.error("Port %s is occupied, please change it." % port)
             return False
         self.preinstall_modules()
         self.dump_pid_file()
         app.run(configs=self.modules_info, port=port)
     else:
         log.logger.error("Lack of necessary parameters!")
Exemplo n.º 3
0
 def start_app_with_args(self):
     '''
     Start one PaddleHub-Serving instance by arguments with gunicorn.
     '''
     module = self.args.modules
     if module is not None:
         port = self.args.port
         if is_port_occupied("127.0.0.1", port) is True:
             log.logger.error("Port %s is occupied, please change it." % port)
             return False
         self.preinstall_modules()
         options = {"bind": "0.0.0.0:%s" % port, "workers": self.args.workers}
         self.dump_pid_file()
         StandaloneApplication(app.create_app(init_flag=False, configs=self.modules_info), options).run()
     else:
         log.logger.error("Lack of necessary parameters!")
Exemplo n.º 4
0
    def start_bert_serving(args):
        '''
        Start bert serving server.
        '''
        if platform.system() != "Linux":
            log.logger.error("Error. Bert Service only support linux.")
            return False

        if is_port_occupied("127.0.0.1", args.port) is True:
            log.logger.error("Port %s is occupied, please change it." % args.port)
            return False

        from paddle_gpu_serving.run import BertServer
        bs = BertServer(with_gpu=args.use_gpu)
        bs.with_model(model_name=args.modules[0])
        CacheUpdater("hub_bert_service", module=args.modules[0], version="0.0.0").start()
        bs.run(gpu_index=args.gpu, port=int(args.port))
Exemplo n.º 5
0
    def listen(self, port: int):
        if platform.system() == "Windows":
            back_port = int(port) + 1
            for index in range(100):
                if not is_port_occupied("127.0.0.1", back_port):
                    break
                else:
                    back_port = int(back_port) + 1
            else:
                raise RuntimeError(
                    "Port from %s to %s is occupied, please use another port" %
                    (int(port) + 1, back_port))
            worker_backend = "tcp://localhost:%s" % back_port
            backend = "tcp://*:%s" % back_port
        else:
            worker_backend = "ipc://backend.ipc"
            backend = "ipc://backend.ipc"

        start_workers(modules_info=self.modules_info,
                      gpus=self.gpus,
                      backend_addr=worker_backend)
        d = InferenceDevice()
        d.listen('tcp://*:%s' % port, backend)