简体   繁体   English

内存泄漏 symfony 和 monolog 和控制台

[英]Memory leak symfony and monolog and console

I spent the last 2 hours trying to find my memory leak.我花了最后 2 个小时试图找到我的内存泄漏。

  • Optimized the doctrine bulk processing优化了学说批量处理
  • Optimized my detach and all that doctrine annotation stuff优化了我的分离和所有教义注释的东西
  • Optimized the SQL Logger优化 SQL Logger
  • The script was still leaking脚本仍然泄漏
  • Decided to comment out the logging because there wasn't much I could do anyway决定注释掉日志,因为我无能为力

Turns out that原来如此

  • Over 40k iterations without logging at each n but at modulus 50, start mem: 28 mb end mem: 30mb超过 40k 次迭代,每个 n 没有记录,但模数为 50,开始内存:28 mb 结束内存:30 mb
  • Over 5k iterations with logging at each n, no modulus, start mem:28mb, end mem 38mb.超过 5k 次迭代,记录每个 n,无模数,开始 mem:28mb,结束 mem 38mb。

Example例子

 # this leaks
 # start mem: 28 mb end mem: 38mb, n = 5k
 foreach ($this->queryData->iterate() as $j => $data):
            declare(ticks = 1);
            self::$currentAd++;
            $this->em->detach($data[0]);
            $this->logger->info(LogUtility::getMemoryUsage() . " (" . self::$currentAd .")");
            if(self::$currentAd === 40000 ):
                break(2);
            endif;
  endforeach;

 # this doesn't leak
 # start mem: 28 mb end mem: 30mb, n = 40k
 foreach ($this->queryData->iterate() as $j => $data):
            declare(ticks = 1);
            self::$currentAd++;
            $this->em->detach($data[0]);
            if(self::$currentAd % 50 == 0):
                  $this->logger->info(LogUtility::getMemoryUsage() . " (" . self::$currentAd .")");
            endif;
            if(self::$currentAd === 40000 ):
                break(2);
            endif;
  endforeach;

my monolog config:我的独白配置:

 handlers:
    test:
        type:   stream
        path:   "%kernel.logs_dir%/immobilier/test.log"
        level:  debug
        channels: test
  console:
        type:   console
        bubble: false
        verbosity_levels:
            VERBOSITY_VERBOSE: INFO
            VERBOSITY_VERY_VERBOSE: DEBUG
        channels: [test]

Any suggestions to correct this ?有什么建议可以纠正这个问题吗?

Found the solution. 找到了解决方案。 I can't tell you the exact reasons why such memory leak happen, however according to this ; 我无法告诉你这种内存泄漏发生的确切原因,但是根据这一点 ; Adding the --no-debug option to your command solves the problem. 在命令中添加--no-debug选项可以解决问题。 It actually did and it even reduced the memory by 2mb. 它实际上做了,它甚至减少了2mb的内存。 Cheers ! 干杯!

Funny thing is when I add that option the memory usage actually doubles. 有趣的是,当我添加该选项时,内存使用量实际上增加了一倍。 Calling Garbage collection does not seem to solve this issue either. 调用垃圾收集似乎也没有解决这个问题。

In addition to @delmalki's answer, you might want to check if you have any fingers_crossed handler and set the buffer_size : 除了@ delmalki的答案之外,您可能想要检查是否有任何fingers_crossed处理程序并设置buffer_size

monolog:
    handlers:
        main:
            type: fingers_crossed
            action_level: critical
            handler: grouped
            excluded_404s:
                - ^
            buffer_size: 30

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM