Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
416 views
in Technique[技术] by (71.8m points)

memory - TYPO3 Extbase:clearState无法释放内存(TYPO3 Extbase: clearState not freeing memory)

I have an import job for scheduler written with Extbase and memory usage is really high.

(我有一个用Extbase编写的调度程序的导入作业,内存使用率确实很高。)

In TYPO3 7.6, I was able to free memory with

(在TYPO3 7.6中,我能够使用)

$this->objectManager->get(TYPO3CMSExtbasePersistenceGenericPersistenceManager::class)->clearState();

But after upgrading to TYPO3 9.5, "clearState" seems not to work like before, this function just frees a tiny amount of memory.

(但是在升级到TYPO3 9.5之后,“ clearState”似乎无法像以前那样工作,此功能仅释放少量内存。)

I've written a simple example code which demonstrates the problem.

(我编写了一个简单的示例代码来演示该问题。)

This example can run in a Extbase Controller, no need to run it in Scheduler context.

(该示例可以在Extbase控制器中运行,而无需在Scheduler上下文中运行。)

var_dump(memory_get_usage());
$v1 = $this->frontendUserRepository->findAll();
foreach($v1 as $vv1) {
    $a1 = $this->frontendUserRepository->findOneByUid($vv1->getUid());
}
var_dump(memory_get_usage());
$this->objectManager->get(TYPO3CMSExtbasePersistenceGenericPersistenceManager::class)->clearState();
var_dump(memory_get_usage());

Output is int(49013528) int(565877768) int(543894472) : Retrieving users from the database by "findOneByUid" consumes much memory, because the objects are stored in some PHP variable and I like to free this memory.

(输出为int(49013528) int(565877768) int(543894472) :通过“ findOneByUid”从数据库中检索用户会消耗大量内存,因为对象存储在某些PHP变量中,并且我想释放此内存。)

In TYPO3 7, this worked with function "clearState".

(在TYPO3 7中,它与功能“ clearState”一起使用。)

  ask by Sven translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This is the method you're using:

(这是您使用的方法:)


    /**
     * Clears the in-memory state of the persistence.
     *
     * Managed instances become detached, any fetches will
     * return data directly from the persistence "backend".
     *
     * @throws TYPO3CMSExtbasePersistenceGenericExceptionNotImplementedException
     * @internal only to be used within Extbase, not part of TYPO3 Core API.
     */
    public function clearState()
    {
        $this->newObjects = [];
        $this->addedObjects = new ObjectStorage();
        $this->removedObjects = new ObjectStorage();
        $this->changedObjects = new ObjectStorage();
        $this->persistenceSession->destroy();
    }

So in my opinion it's not useful to call it at all as it's just clearing any stack that would be processed with persistAll() I assume.

(因此,我认为完全调用它并没有什么用,因为它只是清除将使用我假设的persistAll()处理的任何堆栈。)

If a stack like that shall be cleared, why it should be written first?

(如果要清除这样的堆栈,为什么要先写呢?)
Perhaps I'm missing the sense of the function but at least it doesn't indeed delete much data usually.

(也许我缺少该功能的含义,但至少通常它并没有真正删除很多数据。)
I'd use the function in an extension perhaps if it turns out that some condition shall reset any prepared database-operations, but that's nothing for a scheduler task and should depend on special conditions instead of systematically just deleting the stack completely.

(我可能会在扩展中使用该函数,如果事实证明某些条件将重置任何准备好的数据库操作,但这对于调度程序任务来说并不重要,并且应该依赖于特殊条件,而不是系统地完全删除堆栈。)

Question is which kind of cache you want to delete, here is a list of the cache-API .

(问题是您要删除哪种缓存, 这是cache-API的列表 。)
And here is still mentioned about the Garbage Collection Task , perhaps that's what you want to achieve.

(这里仍然提到垃圾收集任务 ,也许这就是您想要实现的目标。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...