New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: Try to parallelize linting with amphp #4838
Conversation
@kelunik @trowski could someone of you give me a hand on how this could work. it seems to work more or less, but I am not sure it works in parallel as it should be.
do you have any hints for me? |
@@ -14,9 +14,10 @@ | |||
} | |||
], | |||
"require": { | |||
"php": "^5.6 || ^7.0", | |||
"php": "^7.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will work on how the compat with old php can/should look like, after I get it working on current php versions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might want to see #4810.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we don't want PHP 5, then why do we even need a parallel linter? We can use the tokenising linter on PHP 7?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we even need a parallel linter? We can use the tokenising linter on PHP 7?
I had the theory that tokenized linting in parallel process is faster then doing it in a single process
it looks like the above reported errors are gone. it seems the linter does no longer report errors, when invalid files are checked though. a collegue told me he is getting a "too many open files" error when running the fixer on macOS. |
src/Linter/PooledLinter.php
Outdated
|
||
public function __construct() | ||
{ | ||
$this->processPool = new DefaultPool(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would allow a Amp\Parallel\Worker\Pool
instance to be passed via the constructor. If one isn't passed, use the one returned from Amp\Parallel\Worker\pool()
.
This can happen if
On a quick glance, I'm assuming some implementation of
Seems the errors are reported as exceptions that likely cannot be serialized, such as |
Just wondering, wouldn't it be easier to make PHP CS Fixer more friendly with multiple parallel instances so that it can be used with e.g. GNU Parallel? Maybe it already is but I never tried it myself. |
src/Linter/PooledLintFileTask.php
Outdated
*/ | ||
public function run(Environment $environment) { | ||
$linter = new TokenizerLinter(); | ||
return $linter->lintFile($this->path); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return $linter->lintFile($this->path); | |
return $linter->lintFile($this->path)->check(); |
src/Linter/PooledLintSourceTask.php
Outdated
*/ | ||
public function run(Environment $environment) { | ||
$linter = new TokenizerLinter(); | ||
return $linter->lintSource($this->source); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return $linter->lintSource($this->source); | |
return $linter->lintSource($this->source)->check(); |
private $promise; | ||
|
||
/** | ||
* @param Promise<TokenizerLintingResult> $promise |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* @param Promise<TokenizerLintingResult> $promise | |
* @param Promise $promise |
src/Linter/PooledLintingResult.php
Outdated
/** | ||
* @var TokenizerLintingResult | ||
*/ | ||
$result = \Amp\Promise\wait($this->promise); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$result = \Amp\Promise\wait($this->promise); | |
// will throw on error | |
\Amp\Promise\wait($this->promise); |
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function check() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should return :void
src/Linter/PooledLintingResult.php
Outdated
{ | ||
if (null === $this->isSuccessful) { | ||
/** | ||
* @var TokenizerLintingResult |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* @var TokenizerLintingResult | |
* @var bool |
its not easy to handle a exception thrown within a task on the caller site. therefore we transform it to a string a re-create the exception later on.
As far as I can tell it seems to work now. After I changed the tasks to no longer throw Exception accross process boundaries it works. actually it got not faster on my 2 core workstation.. need to test again on a machine with more cpu cores. with this patch:
without this patch:
|
@staabm , you won't see an improvement when parallelizing TokenizerLinter ( ref https://github.com/FriendsOfPHP/PHP-CS-Fixer/pull/4838/files#r386713529 ) you can see improvement If you would parallelize fixing (one process/thread fixing one file with all rules, other process/thread fixing another files) |
the comment referenced does not mention why parallel linting cannot be faster?
I tried this before.. the main problem we face is, that we cannot use Exception objects in IPC messages. that means that we would need to do the exception handling in the workers and concurrently write into the cacheManager (or alternatively use a separate "error-object" which supports IPC but would then dont include a proper stacktrace etc). |
Superceeded by #5390 |
trying to work on some parallelization, so linting could happen on several CPUs