需求:分診算法所使用的模型占用內(nèi)存較多积担,當(dāng)前test服務(wù)器的內(nèi)存不足,需要將服務(wù)遷移到新的learn服務(wù)器们豌,重新創(chuàng)建RPC服務(wù)接口交惯。
原服務(wù)器:test
新服務(wù)器:learn
1. 工程配置
在新learn服務(wù)器中,下載problem_triage
工程变秦,執(zhí)行clone
命令成榜,同時切換當(dāng)前服務(wù)所在的分支feature/rough_to_fine_svm
:
git clone git@git.cxyx.me:python/problem_triage.git
git branch -a
git checkout feature/rough_to_fine_svm
通過三個環(huán)境腳本,安裝所依賴的Python庫蹦玫,其中赎婚,在更新環(huán)境(update)時雨饺,需要注意。
source scripts/env_prepare.sh # 準(zhǔn)備環(huán)境
source scripts/env_activate.sh # 激活環(huán)境
source scripts/env_update.sh # 更新環(huán)境
全部更新完成的效果:
1.1 導(dǎo)出版本
提前準(zhǔn)備待更新的Python庫惑淳,在原test服務(wù)器的工程中,使用freeze
命令導(dǎo)出到requirements.txt
文件中:
pip freeze >requirements.txt
1.2 缺少smart_update
在執(zhí)行env_update
時饺窿,無法找到smart_update.py
歧焦,則需要提前下載春雨的cy-pypi
源。
同時肚医,設(shè)置當(dāng)前的pip版本為1.5.6绢馍,因為春雨虛擬環(huán)境(env)的安裝腳本是基于pip的1.5.6版本:
pip install pip==1.5.6
在更新Python版本時,除了使用env_update腳本肠套,也可以直接使用pip命令:
pip install -r requirements.txt
1.3 pip源缺少庫版本
如果當(dāng)前的pip源提供的依賴庫的版本較低舰涌,可以使用其他的pip源,如阿里云:
pip install Markdown==2.6.8 -i http://mirrors.aliyun.com/pypi/simple
當(dāng)pip版本較高時你稚,如9.0.1瓷耙,使用陌生的pip源會報錯:
Collecting tensorflow
The repository located at mirrors.aliyun.com is not a trusted or secure host and is being ignored. If this repository is available via HTTPS it is recommended to use HTTPS instead, otherwise you may silence this warning and allow it anyways with '--trusted-host mirrors.aliyun.com'.
Could not find a version that satisfies the requirement tensorflow (from versions: )
No matching distribution found for tensorflow
需要在命令尾部,添加信任pip源的參數(shù):
pip install Markdown==2.6.8 -i http://mirrors.aliyun.com/pypi/simple --trusted-host mirrors.aliyun.com
1.4 pip版本過低
如果提示錯誤https替換http刁赖,如安裝TensorFlow搁痛,即:
Downloading/unpacking tensorflow
http://mirrors.aliyun.com/pypi/simple/tensorflow/ uses an insecure transport scheme (http). Consider using https if mirrors.aliyun.com has it available
Could not find any downloads that satisfy the requirement tensorflow
Cleaning up...
No distributions at all found for tensorflow
Storing debug log for failure in /home/classify/.pip/pip.log
原因是TensorFlow庫需要高版本的pip庫才能安裝,當(dāng)前pip的版本較低宇弛,默認(rèn)是1.5.6鸡典,需要更新pip的版本:
pip install --upgrade pip
1.5 安裝setuptools
在安裝gensim時,錯誤信息提示:setuptools版本過低枪芒,需要重新安裝setuptools彻况。
The required version of setuptools (>=1.3.2) is not available,
and can't be installed while this script is running. Please
install a more recent version first, using
'easy_install -U setuptools'.
服務(wù)器無法使用easy_install
,使用pip
更新安裝setuptools
舅踪。
pip install setuptools --upgrade
如果纽甘,當(dāng)前源的setuptools版本較低,更換阿里云的源硫朦,重新安裝贷腕。
2. 服務(wù)配置
在新learn服務(wù)器中,需要復(fù)制算法模型與配置服務(wù)接口咬展。
2.1 復(fù)制模型
需要復(fù)制粗分模型與Word2Vec模型泽裳,位置:
/home/cxyx/workspace/problem_triage/triage/data/experiments/model/rnn/runs
/home/cxyx/workspace/problem_triage/triage/data/adult/model/rnn/runs
/home/cxyx/workspace/problem_triage/word2vec/data/model
將文件壓縮傳輸,再解壓文件
zip -r ex_fine_model_0802.zip ex_fine_model_0802
unzip ex_fine_model_0802.zip
如果沒有unzip命令破婆,則需要安裝
sudo yum install -y unzip zip
如果無法安裝unzip命令涮总,則使用tar打包,傳輸祷舀,不壓縮:
tar cvf 1493802466.tar 1493802466
tar xvf 1493802466.tar
使用python的HTTP接口瀑梗,在服務(wù)器之間傳輸烹笔,進入文件所在目錄,啟動服務(wù)接口抛丽。
python -m SimpleHTTPServer 9001
在目標(biāo)服務(wù)器的對應(yīng)位置谤职,下載文件,使用AB Test模式亿鲜,需要復(fù)制兩個算法的模型文件允蜈,共四個文件。
wget --limit-rate=3000k test:9001/ex_rough_model_0802.zip
wget --limit-rate=3000k test:9001/ex_w2v_model_0802.zip
wget --limit-rate=3000k test:9001/1493802466.zip
wget --limit-rate=3000k test:9001/word2vec_for_triage.zip
解壓到對應(yīng)目錄即可蒿柳。
2.2 配置服務(wù)
在原test服務(wù)器中饶套,找到未添加至工程的配置文件
git status
在工程的.gitignore
文件中,找到未添加至工程的配置文件
需要修改三個配置文件垒探,即settings.py
妓蛮、config.ini
、supervisord.conf
圾叼。
settings.py
負(fù)責(zé)管理log的存儲位置蛤克,將項目中的settings.test.py
復(fù)制一份,即可褐奥,測試用test咖耘,線上用online:
cp settings.test.py settings.py
config.ini
存放服務(wù)的socket地址或者端口,用于服務(wù)的網(wǎng)絡(luò)訪問撬码,備份位于
problem_triage/conf/rpc
將其中的config.test.ini
復(fù)制成本地的config.ini儿倒,即可。
supervisord.conf
存放服務(wù)的進程信息呜笑,啟動worker的數(shù)量夫否,備份位于:
problem_triage/conf/supervisor
將其中的supervisord.test.conf
復(fù)制成本地的supervisord.conf,即可叫胁。
啟停服務(wù)的腳本:
sh control_lb.sh stop
sh scripts/sup_stop.sh
sh scripts/sup_start.sh
sh control_lb.sh start
RPC服務(wù)的監(jiān)控面板凰慈,https://devops.cxyx.me/dashboard/rpc/