dragon4808 2016-03-13 23:28
浏览 54
已采纳

内存泄漏symfony和monolog和控制台

I spent the last 2 hours trying to find my memory leak.

  • Optimized the doctrine bulk processing
  • Optimized my detach and all that doctrine annotation stuff
  • Optimized the 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
  • Over 5k iterations with logging at each n, no modulus, start mem:28mb, end 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 ?

  • 写回答

2条回答 默认 最新

  • doushanmo7024 2016-03-14 00:05
    关注

    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. It actually did and it even reduced the memory by 2mb. Cheers !

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c