【发布时间】: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