swoft-cloud / swoft

🚀 PHP Microservice Full Coroutine Framework
https://swoft.org
Apache License 2.0
5.58k stars 788 forks source link

内存泄露 #1390

Open 583128870 opened 3 years ago

583128870 commented 3 years ago
Q A
Bug report? yes/no
Feature request? yes/no
Swoft version 2.1
Swoole version 4.4.18
PHP version 7.2.33
Runtime environment Docker etc.

Describe the bug 服务进程内存随着时间无上限增长

Expected behavior 本地模拟每秒10个并发情况 且开启task进程;使用Swoole Tracker进行监测 Screenshots If applicable, add screenshots to help explain your problem.

Details 内存泄露记录 The Possible Leak As Malloc Size Keep Growth: /var/www/swoft/vendor/swoft/server/src/Server.php:545 => Growth Times : [1764]; Growth Size : [7460160] /var/www/swoft/vendor/swoft/stdlib/src/Helper/ArrayHelper.php:930 => Growth Times : [6]; Growth Size : [576] /var/www/swoft/vendor/swoft/stdlib/src/Helper/ArrayHelper.php:281 => Growth Times : [6]; Growth Size : [384] /var/www/swoft/vendor/monolog/monolog/src/Monolog/Formatter/NormalizerFormatter.php:88 => Growth Times : [1289]; Growth Size : [6534838296] /var/www/swoft/vendor/monolog/monolog/src/Monolog/Formatter/NormalizerFormatter.php:95 => Growth Times : [1289]; Growth Size : [567432] /var/www/swoft/vendor/monolog/monolog/src/Monolog/Formatter/LineFormatter.php:102 => Growth Times : [1289]; Growth Size : [1824984] /var/www/swoft/vendor/monolog/monolog/src/Monolog/Formatter/LineFormatter.php:103 => Growth Times : [1289]; Growth Size : [736128] /var/www/swoft/vendor/swoft/log/src/Handler/FileHandler.php:137 => Growth Times : [1289]; Growth Size : [1334232] /var/www/swoft/vendor/swoft/log/src/Handler/FileHandler.php:139 => Growth Times : [1289]; Growth Size : [720792] /var/www/swoft/vendor/swoft/log/src/Handler/FileHandler.php:102 => Growth Times : [1289]; Growth Size : [720792] /var/www/swoft/vendor/swoft/log/src/Handler/FileHandler.php:104 => Growth Times : [1289]; Growth Size : [214704] /var/www/swoft/vendor/swoft/log/src/Handler/FileHandler.php:203 => Growth Times : [1289]; Growth Size : [92016] /var/www/swoft/vendor/swoft/log/src/Handler/FileHandler.php:204 => Growth Times : [1289]; Growth Size : [966168] /var/www/swoft/vendor/swoft/log/src/Handler/FileHandler.php:215 => Growth Times : [1289]; Growth Size : [1150200] /var/www/swoft/vendor/swoft/log/src/Handler/FileHandler.php:216 => Growth Times : [1289]; Growth Size : [260712] /var/www/swoft/vendor/swoft/framework/src/Co.php:162 => Growth Times : [1289]; Growth Size : [107352] /var/www/swoft/vendor/swoft/log/src/Logger.php:448 => Growth Times : [1289]; Growth Size : [46008]

//服务配置
  'httpServer'         => [
        'class'    => HttpServer::class,
        'port'     => 18306,
        'listener' => [
             'rpc' => bean('rpcServer'),
            // 'tcp' => bean('tcpServer'),
        ],
        'process'  => [
            // 'monitor' => bean(\App\Process\MonitorProcess::class)
            // 'crontab' => bean(CrontabProcess::class)
        ],
        'on'       => [
            // SwooleEvent::TASK   => bean(SyncTaskListener::class),  // Enable sync task
            SwooleEvent::TASK   => bean(TaskListener::class),  // Enable task must task and finish event
            SwooleEvent::FINISH => bean(FinishListener::class)
        ],
        /* @see HttpServer::$setting */
        'setting'  => [
            'task_worker_num'       => 12,
//            'task_max_request'       => 1000,
            'task_enable_coroutine' => true,
            'worker_num'            => 6,

//路由代码
    /**
     * 测试
     * @RequestMapping(route="test",method={"GET"})
     * @return string
     * @throws \Swoft\Task\Exception\TaskException
     */
    public function test(){
     return   Task::async('testTask', 'list', [1]);
    }

// 任务代码
 * @Task(name="testTask")
 */
class TestTask
{
    /**
     * @TaskMapping(name="list")
     *
     * @param int    $id
     * @param string $default
     *
     * @return array
     */
    public function getList(int $id, string $default = 'def'): array
    {
        return [
            'list'    => [1, 3, 3],
            'id'      => $id,
            'default' => $default
        ];
    }

Provide minimal script to reproduce the issue


//泄露内存最多的 包代码,感觉像无限在往数组里加值
/var/www/swoft/vendor/monolog/monolog/src/Monolog/Formatter/NormalizerFormatter.php:88 => Growth Times : [1289]; Growth Size : [6534838296]

 if (is_array($data)) {
            $normalized = array();

            $count = 1;
            foreach ($data as $key => $value) {
                if ($count++ > 1000) {
                    $normalized['...'] = 'Over 1000 items ('.count($data).' total), aborting normalization';
                    break;
                }

                $normalized[$key] = $this->normalize($value, $depth+1);
            }

            return $normalized;
        }
inhere commented 3 years ago

log 配置的输出 json 吗