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

onWorkerError回调,是否正常退出?还有内存泄露的疑问,谢谢 #390

Closed yiliaofan closed 8 years ago

yiliaofan commented 9 years ago

日志如下:

[2015-11-06 10:23:30] logid:0 ERROR worker_id: 7, woker_pid: 9096, exit_code: 0
[2015-11-06 10:23:30] logid:0 ERROR worker_id: 15, woker_pid: 9102, exit_code: 0
[2015-11-06 10:23:30] logid:0 ERROR worker_id: 6, woker_pid: 9115, exit_code: 0
[2015-11-06 10:23:30] logid:0 ERROR worker_id: 19, woker_pid: 9114, exit_code: 0
[2015-11-06 10:23:30] logid:0 ERROR worker_id: 17, woker_pid: 9104, exit_code: 0
[2015-11-06 10:23:30] logid:0 ERROR worker_id: 8, woker_pid: 9123, exit_code: 0
[2015-11-06 10:23:30] logid:0 ERROR worker_id: 5, woker_pid: 9100, exit_code: 0
[2015-11-06 10:23:30] logid:0 ERROR worker_id: 14, woker_pid: 9122, exit_code: 0
[2015-11-06 10:23:30] logid:0 ERROR worker_id: 17, woker_pid: 9133, exit_code: 0
[2015-11-06 10:23:30] logid:0 ERROR worker_id: 4, woker_pid: 9117, exit_code: 0
[2015-11-06 10:23:30] logid:0 ERROR worker_id: 8, woker_pid: 9106, exit_code: 0
[2015-11-06 10:23:30] logid:0 ERROR worker_id: 13, woker_pid: 9130, exit_code: 0
[2015-11-06 10:23:30] logid:0 ERROR worker_id: 5, woker_pid: 9129, exit_code: 0
[2015-11-06 10:23:31] logid:0 ERROR worker_id: 9, woker_pid: 9134, exit_code: 0
[2015-11-06 10:23:31] logid:0 ERROR worker_id: 4, woker_pid: 9140, exit_code: 0
[2015-11-06 10:23:31] logid:0 ERROR worker_id: 7, woker_pid: 9167, exit_code: 0
[2015-11-06 10:23:31] logid:0 ERROR worker_id: 16, woker_pid: 9101, exit_code: 0
[2015-11-06 10:23:31] logid:0 ERROR worker_id: 12, woker_pid: 9153, exit_code: 0
[2015-11-06 10:23:31] logid:0 ERROR worker_id: 18, woker_pid: 9142, exit_code: 0
[2015-11-06 10:23:31] logid:0 ERROR worker_id: 12, woker_pid: 9152, exit_code: 0
[2015-11-06 10:23:31] logid:0 ERROR worker_id: 13, woker_pid: 9139, exit_code: 0

逻辑大概是:  event work接请求,然后抛出到task worker异步对图片的处理。。我压测后出现上面的log;

另外,在写这块的逻辑时,发现在task worker有内存泄露, 通过在onTask回调里面,强制unset解决,还有问题 这块内存泄露问题比较大,一般在event/task worker在写逻辑的时候有什么注意事项么?谢谢~

用的版本是:1.7.17和1.7.18测试的

非常感谢~ @matyhtf 老大,有空帮看下,谢谢~

yiliaofan commented 9 years ago

竟然内存报错:

[06-Nov-2015 18:45:10 Asia/Shanghai] PHP Fatal error:  Allowed memory size of 33554432 bytes exhausted (tried to allocate 1048577 bytes) in /home/work/ww/vendor/guzzlehttp/psr7/src/Stream.php on line 211

@matyhtf 老大,多谢啊

cariers commented 9 years ago

这个不一定是扩展的内存泄露, 可能是/guzzlehttp/psr7/src/Stream.php 这个中的静态变量或是数据 push 之类引起的,swoole 要注意对某些变量做 追加的操作

yiliaofan commented 9 years ago

多谢 @ewenlaz ~

还真是Stream.php报错了。。 @matyhtf 老大,这块可能的原因是?我使用完都unset或者=null处理了

如下log:

[06-Nov-2015 23:26:11 Asia/Shanghai] PHP Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 1048577 bytes) in /home/work/ww/vendor/guzzlehttp/psr7/src/Stream.php on line 211 [06-Nov-2015 23:26:13 Asia/Shanghai] PHP Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 1048577 bytes) in /home/work/ww/vendor/guzzlehttp/psr7/src/Stream.php on line 211

同时在使用的过程中发现gmagick,长时间运行有可能coredump,没办法用回了gd库,多谢~

matyhtf commented 9 years ago

检查对全局变量和类静态变量的使用 。

yiliaofan commented 9 years ago

检查是有静态变量的引用,如下:

$client = self::$client;
$client->doprocess();
unset($client);
后来改成
$client =  new Client();
$client->doprocess();
unset($client);
还是有内存增长的现象,但一般增长到一个值后,逐渐稳定下来。。

这块防止内存泄露,可否说的详细点,具体在worker/task里,有什么需要注意的? @matyhtf 谢谢~!

matyhtf commented 8 years ago

Task进程可以设置task_max_request解决内存泄漏问题。