Problem/Motivation
The method Drupal\Core\DrupalKernel::handle() does more then only handle the user request. When Drupal is run with Apache or NginX this is not a problem. The Swoole module boot Drupal core, keeps it in memory and then feeds it requests at supersonic speeds. The more that is preloaded, the less that has to be done when the user request is to be executed. The Swoole module requires that the site_path is set in advance. The Swoole module wants to skip calling: static::bootEnvironment();, $this->initializeSettings($request); and $this->boot(); on every user request. It is just not needed and slows down the handling of a user request. The problem is that the Swoole module now needs to call the method Drupal\Core\DrupalKernel::handleException() directly and the method is protected.
Proposed resolution
Change the method Drupal\Core\DrupalKernel::handle() to make it work with the Swoole module.
Remaining tasks
TBD
User interface changes
None
API changes
See proposed solution.
Data model changes
None
Release notes snippet
TBD
| Comment | File | Size | Author |
|---|---|---|---|
| #21 | interdiff-3279192-19-21.txt | 582 bytes | daffie |
| #21 | 3279192-21.patch | 2.64 KB | daffie |
Comments
Comment #2
daffie commentedThe patch with testing.
Comment #3
geek-merlinThe rationale makes sense.
Code-wise, the patch trivially does what it announces.
It contains a test that is green.
No BC breaking API change, so no change record needed.
1) Technically a red test-only patch is needed. So NW for that.
I don't see a reason this can not go to 9.x (but may overlook sth) so changing to 9.5.x.
THX for the terrific work daffie!
Comment #4
daffie commentedAdded a change record, because we are doing a API addition.
Added a tests only patch, which should fail the testbot.
@geek-merlin: Thanks for the review!
Comment #6
daffie commentedThe constant Symfony\Component\HttpKernel\HttpKernelInterface::MAIN_REQUEST in Symfony 6 was named Symfony\Component\HttpKernel\HttpKernelInterface::MASTER_REQUEST in Symfony 4, which is used by Drupal 9.
Comment #7
daffie commentedForgot the interdiff file.
Comment #9
geek-merlinAll from #3 resolved, red test plus CR, so RTBC.
Comment #11
daffie commentedBack to RTBC
Comment #12
geek-merlin@daffie: The UI says it "re-tests (only the red patch) every 2 days". Maybe uploading first green then red patch might prevent that bumping back and forth.
Comment #13
alexpottGiven that \Drupal\Core\DrupalKernel::bootEnvironment() has protection and so does ::boot() in terms of calling again wouldn't it be better to change ::handle?
If we change the try{} block to
I think this will mean the Swoole doesn't have to know so much about the internals of getting a response whilst making it easier for ::handle() to be re-entrant without doing unnecessary work.
Comment #14
daffie commented@alexpott: Totally not a solution that I had thought of, but works for me and the Swoole module. The Swoole module can call static::bootEnvironment() and $this->boot(), before calling $this->handle() when an user request is made. Thank you very much for this solution!
Comment #15
daffie commentedComment #16
andypostYay, that looks cleaner!
Btw not sure check for
CLIis handy, Octane has roadrunner's implementation as well + reactphp with fibers also will be blocked as it running via CLIComment #17
alexpottI think we can do even better here tbh...
I we change \Drupal\Core\Installer\InstallerRedirectTrait::shouldRedirectToInstaller to do:
Note we'll need to add ConnectionNotDefinedException to the use statements. Then \Drupal\Core\DrupalKernel::handle() can be...
It's tempting to move the
inside the
if (!$this->booted) {too. Not sure about that... maybe a follow-up.Comment #18
andypostI hope it could help to solve related #2613044: Requests are pushed onto the request stack twice, popped once
Comment #19
ravi.shankar commentedMade changes as per comment #17, please review.
Comment #20
andypostComment #21
daffie commentedFixing the style guide violation.
@alexpott: Thank you for your input in this issue!
Comment #22
geek-merlinCode-wise i can confirm that #17 review is done in #19 / #21 (+cs-fix).
Dunno why the php7 tests fail:
Comment #23
pingwin4egRe PHP 7.3: I see the same 43 errors in PhpRequirementsTest locally without this patch, on bare Drupal 9.5.x, so it's not related. Not sure if there's an open issue for that though.
Update: There is an open issue for that - #3261447-55: Add an API for dynamically setting recommended and supported PHP versions based on known and predicted PHP release schedules.
Comment #24
pingwin4egRe PHP 7.4 & PgSQL 9.5:
So I requeued PHP 7.3 & 8.1 with PgSQL 10 - there's no option for PHP 7.4 with PgSQL 10 for some reason.
Comment #25
pingwin4egTests passed.
Comment #26
daffie commented@pingwin4eg: You are right. I used the wrong PostgreSQL version for the testbot.
The code in the patch from comment #21 is the same as the patch from comment #19 with a small guide style fix. The code from the patch is from @alexpott fro the comments #13 and #17. Therefor I can review the patch.
All the code changes looks good to me. The code changes are only a small refacturing to make it easier for the swoole module to use it.
For me it is RTBC.
Comment #27
alexpottCommitted and pushed 61e4c24929 to 10.0.x and dcca2f9041 to 9.5.x. Thanks!