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

Cleanup processes output handling #5569

Merged
merged 1 commit into from Sep 2, 2016

Conversation

nicolas-grekas
Copy link
Contributor

@nicolas-grekas nicolas-grekas commented Aug 2, 2016

I was playing with a blackfire profile done on a composer install and figured out that fread was called 90k times. After investigating, it turns out that unzip's output is ignored by composer, but it's not by the underlying Symfony Process object.

Let's pipe its output to /dev/null (not on windows of course).

Meanwhile, some code needed a related cleanup, here it is :)

@@ -72,11 +72,11 @@ protected function extract($file, $path)
if (self::$hasSystemUnzip && !(class_exists('ZipArchive') && Platform::isWindows())) {
$command = 'unzip '.ProcessExecutor::escape($file).' -d '.ProcessExecutor::escape($path);
if (!Platform::isWindows()) {
$command .= ' && chmod -R u+w ' . ProcessExecutor::escape($path);
$command .= ' >/dev/null && chmod -R u+w ' . ProcessExecutor::escape($path);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the main point of this patch.

Copy link
Member

@alcohol alcohol Aug 2, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about just passing -qq to unzip? Should be cross platform compatible then even.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it portable?

Copy link
Member

@alcohol alcohol Aug 2, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would expect it to be. But I do not have any Windows machines in close proximity :-(
Let me go check some colleagues around here..

Edit: found a windows machine, but it did not have unzip.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just looked on my Windows VM, looks OK

@alcohol
Copy link
Member

alcohol commented Aug 2, 2016

LGTM

@@ -70,13 +70,13 @@ protected function extract($file, $path)
$processError = null;

if (self::$hasSystemUnzip && !(class_exists('ZipArchive') && Platform::isWindows())) {
$command = 'unzip '.ProcessExecutor::escape($file).' -d '.ProcessExecutor::escape($path);
$command = 'unzip -qq '.ProcessExecutor::escape($file).' -d '.ProcessExecutor::escape($path);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-qq to discard outputs

@romainneutron
Copy link
Contributor

What about using Process::disableOutput?

@nicolas-grekas
Copy link
Contributor Author

Process::disableOutput disables both stdout and stderr, but in this case we want to disable only stdout...

nicolas-grekas added a commit to symfony/symfony that referenced this pull request Aug 3, 2016
…las-grekas)

This PR was merged into the 2.7 branch.

Discussion
----------

[Process] Fix double-fread() when reading unix pipes

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

While looking at the blackfire profile of a `composer install`, I was able to reduce the number of calls to `fread` from 90k to 60k using this patch (and from 60k to <1k with composer/composer#5569 but that's another story).

In fact, we should continue reading only if there might be something next, which won"t be the case if the buffer has not been filled.

Commits
-------

ac17617 [Process] Fix double-fread() when reading unix pipes
symfony-splitter pushed a commit to symfony/process that referenced this pull request Aug 3, 2016
…las-grekas)

This PR was merged into the 2.7 branch.

Discussion
----------

[Process] Fix double-fread() when reading unix pipes

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

While looking at the blackfire profile of a `composer install`, I was able to reduce the number of calls to `fread` from 90k to 60k using this patch (and from 60k to <1k with composer/composer#5569 but that's another story).

In fact, we should continue reading only if there might be something next, which won"t be the case if the buffer has not been filled.

Commits
-------

ac17617 [Process] Fix double-fread() when reading unix pipes
@nicolas-grekas
Copy link
Contributor Author

ping @Seldaek , this is an easy pick :)

@Seldaek
Copy link
Member

Seldaek commented Sep 2, 2016

Am I missing something or is this enabling output on all these process calls? Because by default ProcessExecutor will echo all output unless you pass it a second $output argument in which case it captures it.

@nicolas-grekas
Copy link
Contributor Author

nicolas-grekas commented Sep 2, 2016 via email

@Seldaek
Copy link
Member

Seldaek commented Sep 2, 2016

As per https://github.com/composer/composer/blob/master/src/Composer/Util/ProcessExecutor.php#L67 and https://github.com/composer/composer/blob/master/src/Composer/Util/ProcessExecutor.php#L102, no..

$e = new Composer\Util\ProcessExecutor();
$e->execute('echo FOO');

$e = new Composer\Util\ProcessExecutor();
$e->execute('echo BAR', $output);
$ php test.php
FOO

This is basically potentially causing a huge mess of output as far as I can tell. I don't know if you tested it at all.. but anyway we can add the -qq on the zip and rar calls, that sounds fine, it should limit the amount of writes they do and therefore the amount of fread needed. The rest I'd rather not do it unless there is a very good reason, because it won't change the amount of fread the Process component does.

@nicolas-grekas
Copy link
Contributor Author

nicolas-grekas commented Sep 2, 2016 via email

@Seldaek
Copy link
Member

Seldaek commented Sep 2, 2016

Thanks :) Looks good now, and here's a good reminder to everyone that there is no such thing as an "easy pick" when it comes to reviewing :p

@Seldaek Seldaek merged commit 4861b74 into composer:master Sep 2, 2016
@Seldaek Seldaek added this to the 1.3 milestone Sep 2, 2016
@nicolas-grekas nicolas-grekas deleted the clean-proc-output branch September 2, 2016 19:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants