1、windows下安装docker 去这里下载并安装:https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi 可能存在问题:wsl2 installation is incomplete 下载:https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi 进行安装即可 完成后打开命令行,输入:docker --version 然后执行第一个hello world程序:docker run hello-world 2、试用wrk
代码语言:javascript复制import json
from transformers import pipeline, AutoModelForTokenClassification, AutoTokenizer
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
import uvicorn
from asgiref.sync import sync_to_async
model = AutoModelForTokenClassification.from_pretrained('model_hub/ner')
tokenizer = AutoTokenizer.from_pretrained('model_hub/ner')
class NerPipeline:
def __init__(self):
self.ner = pipeline("ner", grouped_entities=True, model=model, tokenizer=tokenizer)
def predict(self, text):
return self.ner(text)
nerPipeline = NerPipeline()
# text = "江苏警方通报特斯拉冲进店铺"
# text = "本院定于2022年6月1日 上午09时00分在普洱市中级人民法院第三法庭公开开庭审理原告中国音像著作权集体管理协会与被告普洱帝都娱乐有限公司著作权权属、侵权纠纷一案。"
# 启动app
app = FastAPI()
# 让app可以跨域
origins = ["*"]
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
@app.get("/")
async def main():
return {"message": "Hello World"}
# 实现功能
@app.get('/get_ner_simple')
def ner_simple(sentence: str):
result = str(nerPipeline.predict(sentence))
return {"result": result}
@app.get('/get_ner_simple_aysnc')
async def ner_async_simple(sentence: str):
result = await sync_to_async(nerPipeline.predict)(sentence)
result = str(result)
return {"result": result}
if __name__ == '__main__':
uvicorn.run(app='main:app', host="0.0.0.0",
port=8000, reload=True, debug=True)
docker pull williamyeh/wrk 该镜像为一次性镜像,无法挂起,容器运行即停。 docker run -it --rm williamyeh/wrk -t100 -c1000 -d100s "http://192.168.188.1:8000/get_ner_simple?sentence=本院定于2022年6月1日 上午09时00分在普洱市中级人民法院第三法庭公开开庭审理原告中国音像著作权集体管理协会与被告普洱帝都娱乐有限公司著作权权属、侵权纠纷一案。"
100 threads and 1000 connections Thread Stats Avg Stdev Max /- Stdev Latency 729.41ms 583.61ms 2.00s 54.55% Req/Sec 1.84 4.18 50.00 89.53% 1807 requests in 1.67m, 719.02KB read Socket errors: connect 0, read 739, write 539, timeout 1708 Non-2xx or 3xx responses: 739 Requests/sec: 18.05 Transfer/sec: 7.18KB
docker run -it --rm williamyeh/wrk -t100 -c1000 -d100s "http://192.168.188.1:8000/get_ner_simple_async?sentence=本院定于2022年6月1日 上午09时00分在普洱市中级人民法院第三法庭公开开庭审理原告中国音像著作权集体管理协会与被告普洱帝都娱乐有限公司著作权权属、侵权纠纷一案。"
100 threads and 1000 connections Thread Stats Avg Stdev Max /- Stdev Latency 986.64ms 544.48ms 2.00s 62.69% Req/Sec 14.64 17.82 130.00 88.63% 36269 requests in 1.67m, 5.33MB read Socket errors: connect 0, read 0, write 0, timeout 35205 Non-2xx or 3xx responses: 36269 Requests/sec: 362.34 Transfer/sec: 54.49KB