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

$this->kernel->invalidateContainer(); increases Drush/Drupal bootstrap by 300% #2658

Closed
OnkelTem opened this issue Mar 8, 2017 · 8 comments

Comments

@OnkelTem
Copy link
Contributor

OnkelTem commented Mar 8, 2017

I was debugging Drush 8.1.10 bootstrap to figure out why it works slower then before even on basic operations like drush status and came up to the reason. Now before Drush starts Drupal kernel in \Drush\Boot\DrupalBoot8::bootstrap_drupal_full it invalidates the container making Drupal to build it from scratch.

I'm sure this has been done for a good reason but I can't find appropriate issue. But one thing worries me: it is a huge makeweight to every drush run. Look, before we could use Drush w/o this invalidation and it worked just fine. Now we need to rebuild container for every even tiny operation which costs us 250-300% of execution time grow (calculated on drush status).

So my question is: do we really needed it?

Can't it be at least OPTIONAL and enabled by some --force-rebuild global switch? And even without one, we can always do drush cr if it's really needed.

@weitzman
Copy link
Member

weitzman commented Mar 8, 2017

Thanks for working on speeding up Drush. Could you submit a PR and see if tests still pass?

@OnkelTem
Copy link
Contributor Author

OnkelTem commented Mar 8, 2017

I'm not sure is it ok to just roll it back because there was a whole commit dedicated to exactly this change (though it doesn't seem to be logged here on github):

$ git show c288ed8 
commit c288ed8c71025ee35b2281e73781d6d6baa5c385
Author: Greg Anderson <[email protected]>
Date:   Fri May 6 15:14:49 2016 -0700

    Taking rebuild container out just caused other problems; perhaps $kernel->invalidateContainer() will do the trick.

diff --git a/lib/Drush/Boot/DrupalBoot8.php b/lib/Drush/Boot/DrupalBoot8.php
index 2323d1e..4185964 100644
--- a/lib/Drush/Boot/DrupalBoot8.php
+++ b/lib/Drush/Boot/DrupalBoot8.php
@@ -142,6 +142,7 @@ class DrupalBoot8 extends DrupalBoot {
     if (!drush_get_context('DRUSH_QUIET', FALSE)) {
       ob_start();
     }
+    $this->kernel->invalidateContainer();
     $this->kernel->boot();
     $this->kernel->prepareLegacyRequest($this->request);
     if (!drush_get_context('DRUSH_QUIET', FALSE)) {

Then in the master branch it appears in 6c09849
Here is the line: 6c09849#diff-517ac014255a6c264d4f6a240dbe0e98R146. This was part of PR #2103

So the patch is actually simple. I'd prefer asking @greg-1-anderson about the reason and is it appropriate to roll the change back?

@OnkelTem OnkelTem changed the title $this->kernel->invalidateContainer(); increases Drupal bootstrap by 300% $this->kernel->invalidateContainer(); increases Drush/Drupal bootstrap by 300% Mar 8, 2017
@greg-1-anderson
Copy link
Member

I don't remember exactly what the reasoning was here, but without invalidateContainer(), in @weitzman's PR, we get:

Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException: You have requested a non-existent service "drush.service.consolecommands". in Drupal\Component\DependencyInjection\Container->get() (line 157 of /tmp/drush-sut/web/core/lib/Drupal/Component/DependencyInjection/Container.php).

I guess Drush 8 doesn't do this because it isn't trying to add services to the container. Maybe there is some other way we could do this. Drupal Console makes heavy use of services; there might be some info to glean there.

@weitzman
Copy link
Member

weitzman commented Mar 8, 2017

@OnkelTem If you could help get our tests to pass without the invalidateContainer() call it would be much appreciated.

@OnkelTem
Copy link
Contributor Author

OnkelTem commented Mar 9, 2017

@weitzman Ok, I'll try to figure it out today.

@develCuy
Copy link

develCuy commented Apr 25, 2017

@greg-1-anderson I get the same when trying to run drush 8.1.11 from /usr/local/src/...

Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException: You have requested a non-existent service "drush.service.consolecommands". in                                        [error]
Drupal\Component\DependencyInjection\Container->get() (line 157 of /var/www/drupal8/core/lib/Drupal/Component/DependencyInjection/Container.php) #0
/usr/local/src/composer/vendor/drush/drush/lib/Drush/Boot/DrupalBoot8.php(163): Drupal\Component\DependencyInjection\Container->get('drush.service.c...')
#1 /usr/local/src/composer/vendor/drush/drush/includes/bootstrap.inc(354): Drush\Boot\DrupalBoot8->bootstrap_drupal_full()
#2 /usr/local/src/composer/vendor/drush/drush/includes/bootstrap.inc(473): drush_bootstrap(5, 5)
#3 /usr/local/src/composer/vendor/drush/drush/lib/Drush/Boot/BaseBoot.php(53): drush_bootstrap_to_phase(5)
#4 /usr/local/src/composer/vendor/drush/drush/includes/preflight.inc(66): Drush\Boot\BaseBoot->bootstrap_and_dispatch()
#5 /usr/local/src/composer/vendor/drush/drush/drush.php(12): drush_main()
#6 {main}.
Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException: You have requested a non-existent service "drush.service.consolecommands". in /var/www/drupal8/core/lib/Drupal/Component/Dep
endencyInjection/Container.php on line 157 #0 /usr/local/src/composer/vendor/drush/drush/lib/Drush/Boot/DrupalBoot8.php(163): Drupal\Component\DependencyInjection\Container->get('drush.service.c...')
#1 /usr/local/src/composer/vendor/drush/drush/includes/bootstrap.inc(354): Drush\Boot\DrupalBoot8->bootstrap_drupal_full()
#2 /usr/local/src/composer/vendor/drush/drush/includes/bootstrap.inc(473): drush_bootstrap(5, 5)
#3 /usr/local/src/composer/vendor/drush/drush/lib/Drush/Boot/BaseBoot.php(53): drush_bootstrap_to_phase(5)
#4 /usr/local/src/composer/vendor/drush/drush/includes/preflight.inc(66): Drush\Boot\BaseBoot->bootstrap_and_dispatch()
#5 /usr/local/src/composer/vendor/drush/drush/drush.php(12): drush_main()
#6 {main}
Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException: You have requested a non-existent service "drush.service.consolecommands". in Drupal\Component\DependencyInjection\Container->ge
t() (line 157 of /var/www/drupal8/core/lib/Drupal/Component/DependencyInjection/Container.php).
Drush command terminated abnormally due to an unrecoverable error.

Bug is gone when reverting to 8.1.10

@scubafly
Copy link

scubafly commented May 4, 2017

Got exactly the same message as develCuy with drush 8.1.11 when I run drush status
If anybody needs me to try something to fix this, let me know.

@melodyjuranville
Copy link

Hello,
Got the same message today, when I run drush status :

Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException: You have requested a non-existent service "drush.service.consolecommands". in Drupal\Component\DependencyInjection\Container->get() (line 157 of [...]/core/lib/Drupal/Component/DependencyInjection/Container.php).

Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException: You have requested a non-existent service "drush.service.consolecommands". in [...]/core/lib/Drupal/Component/DependencyInjection/Container.php on line 157

Drush command terminated abnormally due to an unrecoverable error.

I can't progress anymore on my project, anybody have find a fix ?

Thanks for your help.

mikeker pushed a commit to mikeker/drush that referenced this issue Aug 10, 2017
…-ops#2663)

# Conflicts:
#	lib/Drush/Drupal/DrushServiceModfier.php
#	lib/Drush/Drupal/DrushServiceModifier.php
#	src/Drupal/DrushServiceModfier.php
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

No branches or pull requests

6 participants