Problem

Without proper caching, Drupal is SLOW, just like many extensible PHP frameworks. Despite the great cache tag feature of Drupal 8, not everything can be fully cached.
One major problem is Drupal's bootstrap is very resource intensive. Regardless of how much time we put into optimizing it, it can only become slightly faster. The reason for this as i believe is because we're using the wrong approach. Bootstrapping the whole application for every request is just wrong. Things get even worse when one wants to use Drupal as headless rest API for a something like a progressive application with many small simultaneous requests.

Why is this critical

The web is becoming much faster and the content extremely customized. In many cases caching just wouldn't cut it.
just to name few related technologies: Progressive Apps, HTTP2, ioT, REST, Li-Fi, 5G, etc.
With Drupal headless initiative which makes using Drupal for modern web much easier and semantic versioning which makes it possible to add many new features to core every several months, can Drupal really compete with Walled Garden ? Will 200-300ms for dynamics content acceptable for users and clients ? Drupal can be used for sites with heavy traffic and dynamic content, but if we put aside how challenging it's, it can never deliver the same performance as more modern Web solutions written by likes of Node.js

I think this is important enough to become an initiative.

Solution

It's simple, not to bootstrap Drupal every time. Up until few years ago there wasn't any reliable solution fast enough to worth the effort. But now there are several open source projects already in production (PHP-PM, PHPFastCGI, Icicle, AppServer.io , etc). And it is fast, we're talking about 10-30ms and few kilobytes of memory usage without any caching or optimization against 100-150ms and megabyes of memory usage (The numbers come from my experiment with ReactPHP HTTP server and a custom Silex application). This is without any optimization, just changing the approach! But when application bootstraps only once and objects are persistent, a lot of things can be greatly optimized.

Demonstration

I haven't been able to find any benchmarks for Drupal, but for other frameworks the are several :

More information on wiki page : https://groups.drupal.org/node/417723

Work already done

There has been several attempts, discussions and experiments so far using different approaches :

Roadmap

Comments

sinasalek’s picture

ReactPHP take a very different approach to PHP's performance problem, it's more memory efficient and can be used in combination with HHVM.
It's i believe how it should be, Drupal as we all know has a very expensive bootstrapping specially when many modules are installed so the performance boost we get from using ReactPHP is amazingly high! it's not comparable to any other solution available right now 1000x - 2000x boost and even more if the application is written in an asynchronous way.
Sine Drupal 8 is service based and using symphony components as core it seems possible and within reach
Also event driven design is not only for ReactPHP, there are other solutions and more will come in the future
It would be great if we could have opinion of some of core developer regarding how difficult this task is and how we can help to make it happen

sinasalek’s picture

sinasalek’s picture

There are also libraries for supporting push technology (web socks) using reactphp which eliminate the need for nodejs. Since it's already in PHP this support can be added to Drupal out of the box.
https://groups.drupal.org/node/192173
http://socketo.me/

sinasalek’s picture

A symfony bundle to run symfony under reactphp https://github.com/Blackshawk/SymfonyReactorBundle
Realtime chat using Laravel4 and Reactphp https://medium.com/laravel-4/eaa550829538

sinasalek’s picture

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

sinasalek’s picture

Title: Make drupal compatible w ReactPHP (faster than HHVM) » Make Drupal compatible persistent app servers like ReactPHP and PHP-PM

Correcting the title
This is still the best way to significantly improve Drupal's performance.
New attempt on this https://github.com/php-pm/php-pm-drupal

sinasalek’s picture

Note that this is not possible without patching the core https://github.com/php-pm/php-pm-drupal/tree/master/patches

sinasalek’s picture

Version: 8.2.x-dev » 8.3.x-dev

Targeting against 8.3.x

sinasalek’s picture

Wrong update

sinasalek’s picture

Issue summary: View changes

Updating the summary

sinasalek’s picture

Issue summary: View changes
dawehner’s picture

sinasalek’s picture

Title: Make Drupal compatible persistent app servers like ReactPHP and PHP-PM » Make Drupal compatible with persistent app servers like ReactPHP and PHP-PM
sinasalek’s picture

sinasalek’s picture

Title: Make Drupal compatible with persistent app servers like ReactPHP and PHP-PM » Make Drupal compatible with persistent app servers like ReactPHP, PHP-PM, PHPFastCGI
Issue summary: View changes
kentr’s picture

@dawehner, @sinasalek I'll add my patch.

Glad to see that support for the PHP-PM integration is growing.

fgm’s picture

Tried it today, got a bunch of problems:

* the second patch in kentr/stop_using-2505339-24.patch no longer applies on 8.3.x HEAD
* php-pm/React/RequestParser uses non-existent React\Http\RequestParser , which seems to have been replaced by RequestHeaderParser
* php-pm/httpKernel-adapter/Bridges/HttpKernel::mapRequest() uses non existent methods getFiles() and getPost() on React\Http\Request

The two last ones look like depending on an incorrect version of React.

kentr’s picture

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

ivanjaros’s picture

Having Drupal support ReactPHP will be insane! Both child issues are "basically" done. 8.5 is closing in...can't wait.

Nice, up-to-date, overview: https://www.youtube.com/watch?v=fQxxm4vD8Ok

Also, the second part of this is awesome: https://www.youtube.com/watch?v=VjJBR8YAxoE

andypost’s picture

2 related issues are not done
- #2613044: Requests are pushed onto the request stack twice, popped once is very close, just needs to explain chosen approach
- second one needs tests #2708827: Allows DrupalKernel::handle to handle more than one requests (rough support for PHP-PM)

Also it's not clear how to handle static vars that still used by core & sessions

dawehner’s picture

RIght, we should basically try to identify every place where we have leaking state in our system. It would be great to collect them all. #2760167: Add \Drupal\Core\Messenger\Messenger solves one of those cases ...

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.