Php_codesniffer: [Wiki] Add more information about `parallel` option

Created on 21 Oct 2017  Â·  6Comments  Â·  Source: squizlabs/PHP_CodeSniffer

I've just been looking into the parallel running option a bit more and am left with some questions.

  • When should you use this option ?
  • Does it work equally well with phpcs as well as phpcbf ?
  • What things should you take into consideration when determining the amount of parallel processes to use ?
  • What can go wrong ? Are there any type of sniffs which would be incompatible with parallel processing ?
  • Any thing else which behaves differently if parallel processing is turned on ?

It might be useful to add a section to the Wiki Advanced Usage page about this.

Documentation

Most helpful comment

I just tried running PHPCS against Customize Posts and get the following results with parallel:

Processes | Time
--------| -----
1 | 0m11.076s
2 | 0m6.577s
4 | 0m4.404s
8 | 0m3.731s
16 | 0m3.665s

So yeah, wow, it can really speed up processing. There is a logarithmic relationship between parallel process count and the overall time it takes.

All 6 comments

I just tried running PHPCS against Customize Posts and get the following results with parallel:

Processes | Time
--------| -----
1 | 0m11.076s
2 | 0m6.577s
4 | 0m4.404s
8 | 0m3.731s
16 | 0m3.665s

So yeah, wow, it can really speed up processing. There is a logarithmic relationship between parallel process count and the overall time it takes.

If you're running on a VM, remember to allocate more cores. Using --parallel=16 with 1 core, a phpcs run across WordPress took 1m38.95s. With 4 cores, it took 0m36.3s.

When you write the output into a report the only thing you see on the console is one result for each process. That means that instead of having one output for each file you suddenly only have n outputs (where nis the number of processes up to a certain upper limit it seems).

My concrete use-case was that I set the parallel-value to 75 but only seem to have gotten 73 processes. More interestingly that was exactly the number of files within the top level of my given path… So instead of checking for the parallel-value I spent an hour debugging why phpcs is not parsing the given folder recursively…

Perhaps the output could be changed from a . or E to – lets say a P? To show that this is a process returning and not a file having issues or not…

Or perhaps at least state that information in the (currently not existing) documentation 😉

Hi All, Im quite interested in using the --parallel Option when running CI as we have 4 Cores that we can use on our GItlab CI server.

However, if I add --parallel=4 to the command line or add <arg name="parallel" value="4" /> there is no time difference from 1 to 4 cores. Am I doing something wrong?

@darthvader666uk make sure PHP is compiled with PCNTL support, or the CLI setting wont do anything. Once you have it, you should only see 4 dots in the verbose output instead of 1 per file:

$ phpcs --parallel=100 --no-cache
............................................................  60 / 489 (12%)
............................................................ 120 / 489 (25%)
............................................................ 180 / 489 (37%)
............................................................ 240 / 489 (49%)
............................................................ 300 / 489 (61%)
............................................................ 360 / 489 (74%)
............................................................ 420 / 489 (86%)
............................................................ 480 / 489 (98%)
.........                                                    489 / 489 (100%)

Time: 6.28 secs; Memory: 28MB
$ phpcs --parallel=4 --no-cache
.... 4 / 4 (100%)

Time: 2.45 secs; Memory: 6MB

thank you @gsherwood ! I have enabled PCNTL support in my docker image and worked!

Someone I missed that information! Sorry about that.

Was this page helpful?
0 / 5 - 0 ratings