[英]Memory leak symfony and monolog and console
I spent the last 2 hours trying to find my memory leak.我花了最后 2 个小时试图找到我的内存泄漏。
Turns out that原来如此
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.