swoole / swoole-src

🚀 Coroutine-based concurrency library for PHP
https://www.swoole.com
Apache License 2.0
18.48k stars 3.16k forks source link

swoole+gearman,使用时,出现worker进程卡死 #706

Closed liupdhc closed 8 years ago

liupdhc commented 8 years ago

通过ps查看,发现有一部分worker不再处理请求。使用strace -p查看

strace -p 25886
Process 25886 attached
restart_syscall(<... resuming interrupted call ...>

一直卡在这。使用pstack 25886:

#0  0x00007f60e0bcac20 in __poll_nocancel () from /lib64/libc.so.6
#1  0x00007f60d67e3e8f in gearman_wait (universal=...) at libgearman/universal.cc:316
#2  0x00007f60d67dbbef in gearman_connection_st::recv_socket (this=this@entry=0x23dd7e0, data=0x23dfde9, data_size=8192, ret=@0x7ffe970b59cc: GEARMAN_SUCCESS) at libgearman/connection.cc:1198
#3  0x00007f60d67dbefa in gearman_connection_st::receiving (this=0x23dd7e0, packet_arg=..., ret=@0x7ffe970b59cc: GEARMAN_SUCCESS, recv_data=recv_data@entry=true) at libgearman/connection.cc:1013
#4  0x00007f60d67d9cdc in _client_run_tasks (exit_task=0x23e7ed0, client_shell=<optimized out>) at libgearman/client.cc:1545
#5  gearman_client_run_block_tasks (client=client@entry=0x23dc650, exit_task=exit_task@entry=0x23e7ed0) at libgearman/client.cc:1757
#6  0x00007f60d67da4b2 in _client_do_background (client_shell=<optimized out>, command=GEARMAN_COMMAND_SUBMIT_JOB_BG, function=..., unique=..., workload=..., job_handle=0x233a9e0 "\340\200:\002") at libgearman/client.cc:255
#7  0x00007f60d67da5fa in gearman_client_do_background (client_shell=client_shell@entry=0x23a6790, function_name=<optimized out>, unique=0x0, workload_str=0x23a6b60, workload_size=80, job_handle=job_handle@entry=0x233a9e0 "\340\200:\002") at libgearman/client.cc:783
#8  0x00007f60d6a04edb in zif_gearman_client_do_background (ht=<optimized out>, return_value=0x23afba8, return_value_ptr=<optimized out>, this_ptr=<optimized out>, return_value_used=<optimized out>) at /var/soft/gearman-1.1.2/php_gearman.c:2140
#9  0x00000000007eb9c6 in zend_call_function (fci=fci@entry=0x7ffe970b5cf0, fci_cache=fci_cache@entry=0x7ffe970b5cc0) at /var/soft/php-5.6.18/Zend/zend_execute_API.c:847
#10 0x00000000007006f2 in zif_call_user_func_array (ht=<optimized out>, return_value=0x23a2370, return_value_ptr=<optimized out>, this_ptr=<optimized out>, return_value_used=<optimized out>) at /var/soft/php-5.6.18/ext/standard/basic_functions.c:4786
#11 0x000000000089f36f in zend_do_fcall_common_helper_SPEC (execute_data=<optimized out>) at /var/soft/php-5.6.18/Zend/zend_vm_execute.h:558
#12 0x0000000000830448 in execute_ex (execute_data=0x7f60e333c960) at /var/soft/php-5.6.18/Zend/zend_vm_execute.h:363
#13 0x00000000007eba63 in zend_call_function (fci=fci@entry=0x7ffe970b6030, fci_cache=<optimized out>, fci_cache@entry=0x7ffe970b6000) at /var/soft/php-5.6.18/Zend/zend_execute_API.c:829
#14 0x0000000000811775 in zend_call_method (object_pp=object_pp@entry=0x7ffe970b60e0, obj_ce=<optimized out>, obj_ce@entry=0x17e8008, fn_proxy=fn_proxy@entry=0x17e8160, function_name=function_name@entry=0xd630f3 "__call", function_name_len=function_name_len@entry=6, retval_ptr_ptr=retval_ptr_ptr@entry=0x7ffe970b6108, param_count=param_count@entry=2, arg1=arg1@entry=0x2395dc0, arg2=0x23b3290) at /var/soft/php-5.6.18/Zend/zend_interfaces.c:97
#15 0x0000000000820cbc in zend_std_call_user_call (ht=<optimized out>, return_value=0x2395df0, return_value_ptr=0x7f60e333c740, this_ptr=0x2398588, return_value_used=<optimized out>) at /var/soft/php-5.6.18/Zend/zend_object_handlers.c:931
#16 0x000000000089f36f in zend_do_fcall_common_helper_SPEC (execute_data=<optimized out>) at /var/soft/php-5.6.18/Zend/zend_vm_execute.h:558
#17 0x0000000000830448 in execute_ex (execute_data=0x7f60e333c758) at /var/soft/php-5.6.18/Zend/zend_vm_execute.h:363
#18 0x00000000007eba63 in zend_call_function (fci=fci@entry=0x7ffe970b63d0, fci_cache=<optimized out>, fci_cache@entry=0x7ffe970b63a0) at /var/soft/php-5.6.18/Zend/zend_execute_API.c:829
#19 0x00000000007006f2 in zif_call_user_func_array (ht=<optimized out>, return_value=0x23771e0, return_value_ptr=<optimized out>, this_ptr=<optimized out>, return_value_used=<optimized out>) at /var/soft/php-5.6.18/ext/standard/basic_functions.c:4786
#20 0x000000000089f36f in zend_do_fcall_common_helper_SPEC (execute_data=<optimized out>) at /var/soft/php-5.6.18/Zend/zend_vm_execute.h:558
#21 0x0000000000830448 in execute_ex (execute_data=0x7f60e333c590) at /var/soft/php-5.6.18/Zend/zend_vm_execute.h:363
#22 0x00000000007eba63 in zend_call_function (fci=fci@entry=0x7ffe970b6690, fci_cache=<optimized out>, fci_cache@entry=0x0) at /var/soft/php-5.6.18/Zend/zend_execute_API.c:829
#23 0x00000000007ebc4e in call_user_function_ex (function_table=<optimized out>, object_pp=object_pp@entry=0x0, function_name=<optimized out>, retval_ptr_ptr=retval_ptr_ptr@entry=0x7ffe970b6728, param_count=param_count@entry=2, params=params@entry=0x7ffe970b6730, no_separation=no_separation@entry=0, symbol_table=symbol_table@entry=0x0) at /var/soft/php-5.6.18/Zend/zend_execute_API.c:617
#24 0x00007f60d55b6fc1 in http_onReceive (serv=<optimized out>, req=<optimized out>) at /var/soft/swoole-src-swoole-1.8.5-stable/swoole_http_server.c:1188
#25 0x00007f60d55d5d59 in swWorker_onTask (factory=factory@entry=0x7f60d46b7430, task=task@entry=0x7ffe970b67c0) at /var/soft/swoole-src-swoole-1.8.5-stable/src/network/Worker.c:192
#26 0x00007f60d55d6081 in swWorker_onPipeReceive (reactor=<optimized out>, event=0x7ffe970b8820) at /var/soft/swoole-src-swoole-1.8.5-stable/src/network/Worker.c:542
#27 0x00007f60d55c8a19 in swReactorEpoll_wait (reactor=0x7f60d47e8000, timeo=<optimized out>) at /var/soft/swoole-src-swoole-1.8.5-stable/src/reactor/ReactorEpoll.c:258
#28 0x00007f60d55d6bf0 in swWorker_loop (factory=factory@entry=0x7f60d46b7430, worker_id=worker_id@entry=7) at /var/soft/swoole-src-swoole-1.8.5-stable/src/network/Worker.c:489
#29 0x00007f60d55d4250 in swManager_spawn_worker (factory=0x7f60d46b7430, worker_id=7) at /var/soft/swoole-src-swoole-1.8.5-stable/src/network/Manager.c:682
#30 0x00007f60d55d4647 in swManager_start (factory=factory@entry=0x7f60d46b7430) at /var/soft/swoole-src-swoole-1.8.5-stable/src/network/Manager.c:135
#31 0x00007f60d55c5ce2 in swFactoryProcess_start (factory=0x7f60d46b7430) at /var/soft/swoole-src-swoole-1.8.5-stable/src/factory/FactoryProcess.c:86
#32 0x00007f60d55cbd79 in swServer_start (serv=serv@entry=0x7f60d46b7000) at /var/soft/swoole-src-swoole-1.8.5-stable/src/network/Server.c:634
#33 0x00007f60d55b2ee7 in zim_swoole_http_server_start (ht=<optimized out>, return_value=0x7f60e33760b0, return_value_ptr=<optimized out>, this_ptr=0x7f60e31ac920, return_value_used=<optimized out>) at /var/soft/swoole-src-swoole-1.8.5-stable/swoole_http_server.c:1677
#34 0x000000000089f36f in zend_do_fcall_common_helper_SPEC (execute_data=<optimized out>) at /var/soft/php-5.6.18/Zend/zend_vm_execute.h:558
#35 0x0000000000830448 in execute_ex (execute_data=0x7f60e333c258) at /var/soft/php-5.6.18/Zend/zend_vm_execute.h:363
#36 0x00000000007fc050 in zend_execute_scripts (type=type@entry=8, retval=retval@entry=0x0, file_count=file_count@entry=3) at /var/soft/php-5.6.18/Zend/zend.c:1341
#37 0x000000000079b122 in php_execute_script (primary_file=primary_file@entry=0x7ffe970baf80) at /var/soft/php-5.6.18/main/main.c:2610
#38 0x00000000008a0f91 in do_cli (argc=3, argv=0x1131b00) at /var/soft/php-5.6.18/sapi/cli/php_cli.c:994

经过一段时间后所有worker不能工作。。使用swoole-1.8.5,php5.6.19

matyhtf commented 8 years ago

gearman_wait 它自己进入循环了,无法交出控制器,会导致Swoole的Worker进程逻辑无法执行。建议使用addProcess创建一个单独的子进程去执行gearman的操作。