Skip to content
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

[Wiki] Add more information about parallel option #1732

Closed
jrfnl opened this issue Oct 21, 2017 · 11 comments
Closed

[Wiki] Add more information about parallel option #1732

jrfnl opened this issue Oct 21, 2017 · 11 comments

Comments

@jrfnl
Copy link
Contributor

jrfnl commented Oct 21, 2017

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.

@westonruter
Copy link
Contributor

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.

@pento
Copy link

pento commented Nov 28, 2017

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.

jrfnl referenced this issue in Yoast/whip Jun 10, 2018
@heiglandreas
Copy link

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 😉

@darthvader666uk
Copy link

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?

@gsherwood
Copy link
Member

@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

@darthvader666uk
Copy link

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

Someone I missed that information! Sorry about that.

@pfrenssen
Copy link
Contributor

pfrenssen commented Jun 25, 2021

I've been testing this to see if some recommendations can be made about the number of processes to run in parallel, but it seems to be not straightforward. On less powerful machines the process seems to be CPU bound, and I had good success with running --parallel={number_of_cores} but this isn't the case up on machines with new, powerful CPUs and fast storage. On a 32 core machine with a PCIe-4.0 NVMe I could raise the number of parallel processes to 120 before it started to slow down again.

Maybe a good recommendation could be:

A good initial value is the number of available processor cores. If the system has fast storage then this can be increased further.

@divinity76
Copy link

a good initial value is phpcs --parallel=$(nproc)

@mabar
Copy link

mabar commented May 23, 2022

phpcs --parallel=$(shell nproc || sysctl -n hw.logicalcpu || echo 4) for compatibility with Mac and fallback for anything else (Windows)

@divinity76
Copy link

@mabar cool! i think the windows equivalent is

powershell "Get-WmiObject Win32_Processor | Select-Object -ExpandProperty NumberOfCores .trim"

maybe

phpcs --parallel=$(shell nproc || sysctl -n hw.logicalcpu || powershell "Get-WmiObject Win32_Processor | Select-Object -ExpandProperty NumberOfCores .trim" || echo 4 )

@jrfnl
Copy link
Contributor Author

jrfnl commented Dec 2, 2023

Closing as replaced by PHPCSStandards/PHP_CodeSniffer#10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Ready for Release
Development

No branches or pull requests

9 participants