一天搞定两大技术点,成就满满。

一,dockerfile

FROM harbor.xxx.com.cn/3rd_part/tensorflow:1.14.0-gpu-py3-jupyter

LABEL "maintainer"="xxx4k"
LABEL "version"="1.0"

#COPY numpy-1.17.4-cp36-none-linux_x86_64.whl /tmp/
#COPY pyzmq-18.1.0-cp36-none-linux_x86_64.whl /tmp/

#RUN pip install /tmp/numpy-1.17.4-cp36-none-linux_x86_64.whl \
#    && pip install /tmp/pyzmq-18.1.0-cp36-none-linux_x86_64.whl \
RUN     pip install --no-cache-dir \
      -i http://xxx.com.cn/root/pypi/+simple/  \
      --trusted-host xxx.com.cn \
      tensorflow==1.14.0 bert-base==0.0.9 flask flask_compress flask_cors  flask_json \
    && rm -rf /tmp/* \
    && rm -rf ~/.cache/pip \
    && echo "finished"

二,修改Http.py

参考URL:
https://www.jianshu.com/p/beab4df088df
https://blog.csdn.net/jusang486/article/details/82382358
https://blog.csdn.net/AbeBetter/article/details/77652457
https://blog.csdn.net/anh3000/article/details/83047027

如果在flask里,使用app.run()的模式,输出总会提示:

* Serving Flask app "bert_base.server.http" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
I1113 :: _internal.py:] * Running on http://0.0.0.0:8091/ (Press CTRL+C to quit)

那如何改进呢?
可以选用nginx或是tornado。
如果是代码模式下,tornador是首选。

from multiprocessing import Process
from tornado.wsgi import WSGIContainer
from tornado.httpserver import HTTPServer
from tornado.ioloop import IOLoop
import asyncio
from termcolor import colored

from .helper import set_logger

class BertHTTPProxy(Process):
    def __init__(self, args):
        super().__init__()
        self.args = args

    def create_flask_app(self):
        try:
            from flask import Flask, request
            from flask_compress import Compress
            from flask_cors import CORS
            from flask_json import FlaskJSON, as_json, JsonError
            from bert_base.client import ConcurrentBertClient
        except ImportError:
            raise ImportError('BertClient or Flask or its dependencies are not fully installed, '
                              'they are required for serving HTTP requests.'
                              'Please use "pip install -U bert-serving-server[http]" to install it.')

        # support up to 10 concurrent HTTP requests
        bc = ConcurrentBertClient(max_concurrency=self.args.http_max_connect,
                                  port=self.args.port, port_out=self.args.port_out,
                                  output_fmt='list', mode=self.args.mode)
        app = Flask(__name__)
        logger = set_logger(colored('PROXY', 'red'))

        @app.route('/status/server', methods=['GET'])
        @as_json
        def get_server_status():
            return bc.server_status

        @app.route('/status/client', methods=['GET'])
        @as_json
        def get_client_status():
            return bc.status

        @app.route('/encode', methods=['POST'])
        @as_json
        def encode_query():
            data = request.form if request.form else request.json
            try:
                logger.info('new request from %s' % request.remote_addr)
                print(data)
                return {'id': data['id'],
                        'result': bc.encode(data['texts'], is_tokenized=bool(
                            data['is_tokenized']) if 'is_tokenized' in data else False)}

            except Exception as e:
                logger.error('error when handling HTTP request', exc_info=True)
                raise JsonError(description=str(e), type=str(type(e).__name__))

        CORS(app, origins=self.args.cors)
        FlaskJSON(app)
        Compress().init_app(app)
        return app

    def run(self):
        app = self.create_flask_app()
        # app.run(port=self.args.http_port, threaded=True, host='0.0.0.0')
        # tornado 5 中引入asyncio.set_event_loop即可
        asyncio.set_event_loop(asyncio.new_event_loop())
        http_server = HTTPServer(WSGIContainer(app))
        http_server.listen(self.args.http_port)
        IOLoop.instance().start()

三,启动命令

bert-base-serving-start -bert_model_dir  -http_port  -port  -port_out  

Bert镜像制作及flask生产环境模式启动的更多相关文章

  1. flask生产环境部署

    1.安装uwsgipip install uwsgi 2.创建ini配置文件vim uwsgi.ini内容如下:[uwsgi]# 配置启动的服务地址和iphttp=0.0.0.0:5001# 项目目录 ...

  2. Vue生产环境部署

    前面的话 开发时,Vue 会提供很多警告来帮助解决常见的错误与陷阱.生产时,这些警告语句却没有用,反而会增加载荷量.再次,有些警告检查有小的运行时开销,生产环境模式下是可以避免的.本文将详细介绍Vue ...

  3. 测试环境docker化(一)—基于ndp部署模式的docker基础镜像制作

    本文来自网易云社区 作者:孙婷婷 背景 我所在测试项目组目前的测试环境只有一套,在项目版本迭代过程中,开发或产品偶尔会在测试环境进行数据校验,QA人数在不断增加,各个人员在负责不同模块工作时也会产生脏 ...

  4. 【openstack N版】——手把手教你制作生产环境镜像

    一.CentOS7镜像制作 1.1创建CentOS7虚拟机 1.1.1创建虚拟磁盘 #注:尽量将虚拟机创建在控制节点,以便于将镜像上传至glance [root@linux-node1 ~]# qem ...

  5. 2020最新nginx+gunicorn+supervisor部署基于flask开发的项目的生产环境的详细攻略

    本攻略基于ubuntu1804的版本,服务器用的华为云的服务器,python3(python2已经在2020彻底停止维护了,所以转到python3是必须的)欢迎加我的QQ6398903,或QQ群讨论相 ...

  6. 【原】Storm Local模式和生产环境中Topology运行配置

    Storm入门教程 1. Storm基础 Storm Storm主要特点 Storm基本概念 Storm调度器 Storm配置 Guaranteeing Message Processing(消息处理 ...

  7. Centos6.3 下使用 Tomcat-6.0.43 非root用户 jsvc模式部署 生产环境 端口80 vsftp

    一.安装JDK环境 方法一. 官方下载链接 http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260 ...

  8. 生产环境该如何选择lvs的工作模式,和哪一种算法

    lvs的工作模式有这几种: 1.RR : 轮叫算法,平均分配,你一个,我一个: 2.WRR :加权轮叫算法,谁的处理能力强,谁的权重就高: 3.LC :最少链接算法,谁的连接数最少,谁就处理更多的链接 ...

  9. 生产环境下Flask项目目录构建

    接触Flask已经有大半年了,本篇博客主要来探讨如何规范化生产环境下Flask的项目目录结构.虽然目录结构见仁见智,个人有个人的看法和习惯,但总的来说,经过很多人的实践和总结,还是有很多共同的意见和想 ...

随机推荐

  1. Flutter - flutter desktop embedding / flutter 桌面支持

    2019年5月9日,随着谷歌在IO19宣布Flutter支持Web平台,就标志着Flutter已经全面支持所有平台(移动.网页.桌面.嵌入式). 现编一个跨平台小段子: 微软Xarmarin:喵喵喵? ...

  2. MySql数据库之数据库基础命令

    继续上篇博客所说到的,使用命令玩转MySql数据库. 在连接数据库时,我们需要确定数据库所在的服务器IP,用户名以及密码.当然,我们一般练习都会使用本地数据库,那么本地数据库的连接命令如下: mysq ...

  3. SpringAOP基础

    例1.已知有这么一段代码,会打印出Hello public static void main(String[] args) { sayHello(); } public static void say ...

  4. PlayJava Day026

    1.泛型:指代任意对象类型 public class CC<T> {} C<Integer> c = new C<Integer>(1) ; 2.限制泛型:用于继承 ...

  5. 下拉框移动 jquery

    <%@ page contentType="text/html;charset=UTF-8" language="java" %><html& ...

  6. Spring Boot Mybatis 最基本使用mysql存储过程

    首先声明:只是用最简单的方法大致了解如何用存储过程开发,如果需要查看存储过程创建语法的自行百度搜索 一.首先创建最基本的数据库 CREATE TABLE `t_user` ( `id` varchar ...

  7. mysql DDL 锁表

    mysql DDL 锁表 select trx_state, trx_started, trx_mysql_thread_id, trx_query from information_schema.i ...

  8. python怎么连接MySQL(附源码)

    一.源码如下: import pymysql from pymysql.cursors import DictCursor # 创建数据库连接 localhost等效于127.0.0.1 conn = ...

  9. [专题总结]初探插头dp

    彻彻底底写到自闭的一个专题. 就是大型分类讨论,压行+宏定义很有优势. 常用滚动数组+哈希表+位运算.当然还有轮廓线. Formula 1: 经过所有格子的哈密顿回路数. 每个非障碍点必须有且仅有2个 ...

  10. java之方法的重载(overload)

    什么是重载? 在任何一个类中,允许存在一个以上的同名的方法,只要它们的参数个数或者参数类型不同即可: 重载的特点? 与返回值无关,只看参数列表.且参数列表必须不同(参数个数或参数类型).调用时,根据方 ...