基于flask搭建预测服务时,采取多进程的方式预测,压测时偶发出core
Created by: yc556600
- 版本、环境信息: 1)PaddlePaddle版本:paddlepaddle==1.6.2 Flask==1.1.1 2)利用multiprocessing开启30个进程,每个进程设置CPU_NUM=1 3)系统环境:CentOS release 6.3 (Final),Python3.6 -预测信息 基于https://github.com/PaddlePaddle/models/tree/develop/PaddleNLP/PaddleLARK/BERT 这份代码改造的flask预测服务,单条访问预测服务都很正常,但进行服务压测时会偶发出core,日志报错信息如下:
W0114 19:00:03.200219 28049 init.cc:206] *** Aborted at 1578999603 (unix time) try "date -d @1578999603" if you are using GNU date ***
W0114 19:00:03.203387 28049 init.cc:206] PC: @ 0x0 (unknown)
W0114 19:00:03.204293 28049 init.cc:206] *** SIGSEGV (@0xac0) received by PID 27988 (TID 0x7f4c29221700) from PID 2752; stack trace: ***
W0114 19:00:03.207324 28049 init.cc:206] @ 0x7f4ca639e390 (unknown)
W0114 19:00:03.210443 28049 init.cc:206] @ 0x7f4ca58ec81d getenv
W0114 19:00:03.214633 28049 init.cc:206] @ 0x7f4b73bea0a9 mkl_serv_getenv
W0114 19:00:03.215040 28049 init.cc:206] @ 0x7f4b7240c7a7 mkl_read_threads_env
W0114 19:00:03.218943 28049 init.cc:206] @ 0x7f4b7240ab3c mkl_serv_domain_get_max_threads
W0114 19:00:03.222363 28049 init.cc:206] @ 0x7f4b72295a09 mkl_vml_serv_threader_s_2i_1o
W0114 19:00:03.226331 28049 init.cc:206] @ 0x7f4b721f0452 vsAdd
W0114 19:00:03.229763 28049 init.cc:206] @ 0x7f4bda2d2db7 paddle::operators::ElementwiseAddKernel<>::Compute()
W0114 19:00:03.231962 28049 init.cc:206] @ 0x7f4bda2d3163 _ZNSt17_Function_handlerIFvRKN6paddle9framework16ExecutionContextEEZNKS1_24OpKernelRegistrarFunctorINS0_8platform8CPUPlaceELb0ELm0EINS0_9operators20ElementwiseAddKernelINS7_16CPUDeviceContextEfEENSA_ISB_dEENSA_ISB_iEENSA_ISB_lEEEEclEPKcSI_iEUlS4_E_E9_M_invokeERKSt9_Any_dataS4_
W0114 19:00:03.235483 28049 init.cc:206] @ 0x7f4bda98615b paddle::framework::OperatorWithKernel::RunImpl()
W0114 19:00:03.240427 28049 init.cc:206] @ 0x7f4bda986ae1 paddle::framework::OperatorWithKernel::RunImpl()
W0114 19:00:03.243085 28049 init.cc:206] @ 0x7f4bda982540 paddle::framework::OperatorBase::Run()
W0114 19:00:03.246613 28049 init.cc:206] @ 0x7f4bda761a6b paddle::framework::details::ComputationOpHandle::RunImpl()
W0114 19:00:03.251855 28049 init.cc:206] @ 0x7f4bda75fe1c paddle::framework::details::OpHandleBase::Run()
W0114 19:00:03.255731 28049 init.cc:206] @ 0x7f4bda71b306 paddle::framework::details::FastThreadedSSAGraphExecutor::RunOpSync()
W0114 19:00:03.259115 28049 init.cc:206] @ 0x7f4bda71a05f paddle::framework::details::FastThreadedSSAGraphExecutor::RunOp()
W0114 19:00:03.260519 28049 init.cc:206] @ 0x7f4bda71a329 _ZNSt17_Function_handlerIFvvESt17reference_wrapperISt12_Bind_simpleIFS1_ISt5_BindIFZN6paddle9framework7details28FastThreadedSSAGraphExecutor10RunOpAsyncEPSt13unordered_mapIPNS6_12OpHandleBaseESt6atomicIiESt4hashISA_ESt8equal_toISA_ESaISt4pairIKSA_SC_EEESA_RKSt10shared_ptrINS5_13BlockingQueueImEEEEUlvE_vEEEvEEEE9_M_invokeERKSt9_Any_data
W0114 19:00:03.264247 28049 init.cc:206] @ 0x7f4bd9415383 std::_Function_handler<>::_M_invoke()
W0114 19:00:03.267794 28049 init.cc:206] @ 0x7f4bd927e337 std::__future_base::_State_base::_M_do_set()
W0114 19:00:03.269546 28049 init.cc:206] @ 0x7f4ca639ba99 __pthread_once_slow
W0114 19:00:03.270622 28049 init.cc:206] @ 0x7f4bda715962 _ZNSt13__future_base11_Task_stateISt5_BindIFZN6paddle9framework7details28FastThreadedSSAGraphExecutor10RunOpAsyncEPSt13unordered_mapIPNS4_12OpHandleBaseESt6atomicIiESt4hashIS8_ESt8equal_toIS8_ESaISt4pairIKS8_SA_EEES8_RKSt10shared_ptrINS3_13BlockingQueueImEEEEUlvE_vEESaIiEFvvEE6_M_runEv
W0114 19:00:03.274158 28049 init.cc:206] @ 0x7f4bd927fe24 _ZZN10ThreadPoolC1EmENKUlvE_clEv
W0114 19:00:03.274966 28049 init.cc:206] @ 0x7f4b87502c80 (unknown)
W0114 19:00:03.276629 28049 init.cc:206] @ 0x7f4ca63946ba start_thread
W0114 19:00:03.278246 28049 init.cc:206] @ 0x7f4ca59ba41d clone
W0114 19:00:03.279760 28049 init.cc:206] @ 0x0 (unknown)
预测服务代码主要分两步,1.初始化加载模型,2.接收query,按句切分后多进程调用预测方法,如下
def infer(self, line, prob):
start = datetime.datetime.now()
predict_exe = fluid.ParallelExecutor(
use_cuda=self.args.use_cuda, main_program=self.predict_prog)
self.predict_data_loader.set_batch_generator(
self.processor.data_generator(
batch_size=self.args.batch_size, phase='test', epoch=1, shuffle=False, line=line))
self.predict_data_loader.start()
end = datetime.datetime.now()
all_results = []
xxx_results = []
while True:
try:
results = predict_exe.run(fetch_list=[self.probs.name])
all_results.extend(results[0].tolist())
xxx_results.extend(results)
except fluid.core.EOFException:
self.predict_data_loader.reset()
break