我花了最后2个小时试图找到我的内存泄漏.
>优化了学说批量处理
>优化我的分离和所有教条注释的东西
>优化了sql Logger
>剧本仍在泄露
>决定将日志记录注释掉,因为无论如何我都无能为力
事实证明
>超过40k次迭代,无需记录每个n但模数为50,启动mem:28 mb end mem: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;
我的monolog配置:
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]
有任何建议要纠正吗?
解决方法:
找到了解决方案.我不能告诉你这种内存泄漏发生的确切原因,但是根据this;在命令中添加–no-debug选项可以解决问题.它实际上做了,它甚至减少了2mb的内存.干杯!