Comments (7)
Can you verify swapping the "serialized" context coming back from the worker with the original context also does the trick?
It does :)
from grumphp.
Running grumphp in parallel mode opens up a separate process for every task you start. There is communication between those 2 processes and that's probably what is taking up the additional MBs of space.
I'm not sure if that memory needs to get manually freed.
However, grumphp is just a tool that finishes at some point.
At that moment, the memory gets freed nevertheless.
Therefore I am not sure if this really is an issue.
So what do you think about this? Is this really a problem or is the problem rather that you need to increase PHP's memory limit in order to get grumphp running on your project?
from grumphp.
I understand that if they are separate PHP processes, they should have the memory limit on each process.
I try to have the same memory limits in local as in production.
If the separate processes do not take up more than 32MB, it seems strange to me that all the tasks in the different processes take up more than 215MB.
The current limit is 256 MB and if I include more files the memory is exceeded. However, memory runs out when there is only 1 task left to finish.
I understand that the desired behavior would be: release that memory as tasks finish?
from grumphp.
I think the memory goes to the serialized task results. The task result contains the context, which contains the file collection. If not running in parallel this object is passed by reference, but when running in parallel it is serialized for each result. If the amount of files is large (5000 files in my case) and there are many tasks (20 in my case) GrumPHP will run out of memory. I solved it by registering a middleware to replace the file collections with an empty object. I'm not sure if this file collection is used in any way after a task has completed.
from grumphp.
I solved it by registering a middleware to replace the file collections with an empty object.
Can you share your solution?
I'm not sure if this file collection is used in any way after a task has completed.
Currently not in this repository. However it's an official extension point, so one might be using that as a feature.
What I'm wondering is: Once the task has been executed in a separate worker, the serialized version is not being used anymore, meaning that it should be garbage collected at that point. So I assume the problem is that the context in the result is the serialized worker context instead of the initial process' context. So it might make sense to swap it back to the original reference, after which garbage collection kicks in?
from grumphp.
Can you share your solution?
Sure:
class UnsetFilesMiddleware implements TaskHandlerMiddlewareInterface
{
/**
* Unset files from task results.
*
* @param TaskInterface $task
* @param TaskRunnerContext $runnercontext
* @param callable $next
*
* @return Promise
*/
public function handle(TaskInterface $task, TaskRunnerContext $runnercontext, callable $next): Promise
{
$result = $next($task, $runnercontext);
if ($result instanceof Promise) {
$result->onResolve(
function ($exception, $value): void {
if ($value instanceof TaskResult) {
$property = new ReflectionProperty($value, 'context');
$property->setAccessible(true);
$property->setValue($value, new RunContext(new FilesCollection([])));
}
}
);
}
return $result;
}
}
And then registered in grumphp.yml with:
My\UnsetFilesMiddleware:
tags:
- name: grumphp.task_handler
priority: 500
I'm still using version 1.5.1 of Grumphp, not sure if this also compatible with the newest version.
from grumphp.
Can you verify swapping the "serialized" context coming back from the worker with the original context also does the trick?
$property = new ReflectionProperty($value, 'context');
$property->setAccessible(true);
- $property->setValue($value, new RunContext(new FilesCollection([])));
+ $property->setValue($value, $runnerContext);
I'm still using version 1.5.1 of Grumphp, not sure if this also compatible with the newest version.
In 2.0 the async execution system changed but it is still using the context coming back from the worker. So I assume it will have similar issues.
from grumphp.
Related Issues (20)
- PHPMD task does not check all file extensions HOT 5
- Don't do commit message checks on merges? HOT 8
- Grumphp running without `.git` folder? HOT 4
- Print the commit message when failing on `git_commit_message` HOT 4
- how can I use grum with docker-compose ? HOT 3
- Fails to Recognize PHPStan Baseline During Commit Workflow
- Override open_basedir only for grumphp test HOT 2
- Grumphp config using default PHPCS XML and other standard's sniff HOT 2
- Undefined constant PhpParser\ParserFactory::PREFER_PHP7 when using `nikic/php-parser` version 5. HOT 1
- Support multiple php versions for tasks HOT 2
- [Task] Add bin/console task for Symfony HOT 1
- husky/lint-staged compatibility HOT 5
- The application requires the version "^7.2" or greater. HOT 2
- Support for multiple PHPStan tasks HOT 2
- How do you think about a configuration to opt-in to continue the commit if fixer could fix everything automatically? HOT 2
- DistFileLoader doesn't import another file
- Add support for git_pre_push HOT 1
- git_blacklist never runs? HOT 5
- Composer validate task not running when composer.lock changes
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from grumphp.