Explorar el Código

控制tensorflow使用的核数

luojiehua hace 2 años
padre
commit
d69bfb983b

+ 2 - 1
BiddingKG/dl/interface/predictor.py

@@ -27,11 +27,12 @@ import calendar
 import datetime
 # import fool   # 统一用 selffool ,阿里云上只有selffool 包
 
-cpu_num = 5
+cpu_num = int(os.environ.get("CPU_NUM"))
 sess_config = tf.ConfigProto(
                         inter_op_parallelism_threads = cpu_num,
                         intra_op_parallelism_threads = cpu_num,
                         log_device_placement=True)
+sess_config = None
 
 from threading import RLock
 dict_predictor = {"codeName":{"predictor":None,"Lock":RLock()},

+ 2 - 2
BiddingKG/readme/start.md

@@ -8,7 +8,7 @@ cd /data/python
 #关闭接口
 ps -ef | grep run_extract_server | grep -v grep | cut -c 9-16| xargs kill -9
 #启动接口
-nohup /data/anaconda3/envs/py37/bin/gunicorn -w 17 --limit-request-fields 0 --limit-request-line 0 -t 1000 -b 0.0.0.0:15030 run_extract_server:app >> extract.log &
+nohup /data/anaconda3/envs/py37/bin/gunicorn -w 17 --limit-request-fields 0 --limit-request-line 0 -t 1000 --keep-alive 600 -b 0.0.0.0:15030 run_extract_server:app >> extract.log &
 
 #19022启动要素提取接口
 #切换目录
@@ -16,4 +16,4 @@ cd /data/python
 #关闭接口
 ps -ef | grep run_extract_server | grep -v grep | cut -c 9-16| xargs kill -9
 #启动接口
-nohup /data/anaconda3/envs/py37/bin/gunicorn -w 4 --limit-request-fields 0 --limit-request-line 0 -t 1000 -b 0.0.0.0:15030 run_extract_server:app >> extract.log &
+nohup /data/anaconda3/envs/py37/bin/gunicorn -w 4 --limit-request-fields 0 --limit-request-line 0 -t 1000  --keep-alive 600 -b 0.0.0.0:15030 run_extract_server:app >> extract.log &

+ 7 - 1
BiddingKG/run_extract_server.py

@@ -16,8 +16,14 @@ os.environ["KERAS_BACKEND"] = "tensorflow"
 
 app = Flask(__name__)
 app.config['JSON_AS_ASCII'] = False
-os.environ["OMP_NUM_THREADS"] = "4" # 1为一个核,设置为5的时候,系统显示用了10个核,不太清楚之间的具体数量关系
 
+limit_num = "4"
+os.environ["OMP_NUM_THREADS"] = limit_num # 1为一个核,设置为5的时候,系统显示用了10个核,不太清楚之间的具体数量关系
+os.environ["OMP_NUM_THREADS"] = limit_num # export OMP_NUM_THREADS=1
+os.environ["OPENBLAS_NUM_THREADS"] = limit_num # export OPENBLAS_NUM_THREADS=1
+os.environ["MKL_NUM_THREADS"] = limit_num # export MKL_NUM_THREADS=1
+os.environ["VECLIB_MAXIMUM_THREADS"] = limit_num # export VECLIB_MAXIMUM_THREADS=1
+os.environ["NUMEXPR_NUM_THREADS"] = limit_num # export NUMEXPR_NUM_THREADS=1
 
 import time
 import uuid