【问题标题】:Memory leak symfony and monolog and console内存泄漏 symfony 和独白和控制台
【发布时间】:2016-06-28 21:09:54
【问题描述】:

我花了过去 2 个小时试图找到我的内存泄漏。

  • 优化了学说批量处理
  • 优化了我的分离和所有教义注释的东西
  • 优化了 SQL 记录器
  • 脚本仍在泄漏
  • 决定注释掉日志记录,因为无论如何我无能为力

原来是这样

  • 超过 40k 次迭代,没有在每个 n 处记录但在模数 50 处,开始内存:28 mb 结束内存:30mb
  • 超过 5k 次迭代,在每个 n 处记录,没有模数,开始 mem:28mb,结束 mem 38mb。

例子

 # 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;

我的独白配置:

 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]

有什么建议可以纠正这个问题吗?

【问题讨论】:

    标签: php symfony memory-leaks doctrine-orm monolog


    【解决方案1】:

    找到了解决方案。我不能告诉你发生这种内存泄漏的确切原因,但是根据this;将--no-debug 选项添加到您的命令可以解决问题。它确实做到了,它甚至将内存减少了 2mb。干杯!

    【讨论】:

      【解决方案2】:

      除了@delmalki 的回答,您可能还想检查您是否有任何fingers_crossed 处理程序并设置buffer_size

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

      【讨论】:

        猜你喜欢
        • 2020-06-03
        • 2013-12-29
        • 2012-07-05
        • 2012-07-30
        • 2012-11-16
        • 1970-01-01
        • 2010-12-02
        • 2013-11-08
        • 2016-05-03
        相关资源
        最近更新 更多