Create the database driver for MySQLi for async queries

Created on 21 January 2022, almost 3 years ago
Updated 25 January 2023, almost 2 years ago

Problem/Motivation

Running database queries as async queries lets us run them in parallel instead of sequentially. For pages with multiple "larger" queries this can speed up rendering such a page significantly. The problem is that the 3 by core supported database driver are all PDO drivers which do not support async queries. The PHP MySQLi extension does support async queries.
The other thing we need is PHP 8.1 with the Fiber functionality. Creating a database driver for MySQLi is the first step we need to make to start using async queries in Drupal.

@catch explained it as following:

Let's take something like https://www.drupal.org/dashboard โ†’ - there's four or five different views on there in blocks.

If you hit a completely cold cache, you have to execute all the views building those blocks, including both the listing query, then rendering the entities within them.

The idea being explored is that for each lazy builder - let's assume we're able to loop over them, you'd render it up until you have to run a views listing query. When it's time to run that query (or whatever appropriate point to delegate to the Fiber), it's done inside a Fiber with a non-blocking query. You then ::suspend() the Fiber and return to the main process, and start the next lazy builder, if that also has to run a views listing query, you'd also run it non blocking and ::suspend(), then you loop over all the lazy builders again to see if the various queries have come back, then render the results for anything that has, then continue polling until everything is rendered.

The page still can't finish rendering until the slowest query is finished, but if you have five slow queries that take 500ms each, then you might be able to run them all at once in the space of 600ms-1s instead of definitely having to run them sequentially in 2.5s. While you're running those simultaneous queries, you can also get on with PHP/CPU-intensive tasks like rendering - assuming we're able to arrange things so that these can be interleaved.

Fibers only allow us to paralellize i/o, not CPU, because there's not any parallel execution at all, so it has to be something like an async MySQL or SOLR query or http request to make any difference, and there has to be something to be getting on with while it's running - either more i/o or something else.

Proposed resolution

For adding the MySQLi database driver we need the following:

  1. Create the MySQLi database driver which should extend the MySQL database driver.
  2. Add the PHP MySQLi extension as a requirement to the core MySQL and MySQLi database drivers.
  3. โœจ Introduce database driver extensions and autoload database drivers' dependencies Fixed which makes extending one database driver on another database driver a lot easier.

Remaining tasks

TBD

User interface changes

TBD

API changes

None

Data model changes

None

Release notes snippet

TBD

๐Ÿ“Œ Task
Status

Active

Version

10.0 โœจ

Component
Databaseย  โ†’

Last updated about 5 hours ago

  • Maintained by
  • ๐Ÿ‡ณ๐Ÿ‡ฑNetherlands @daffie
Created by

๐Ÿ‡ณ๐Ÿ‡ฑNetherlands daffie

Live updates comments and jobs are added and updated live.
  • Needs release manager review

    It is used to alert the release manager core committer(s) that an issue significantly affects the overall technical debt or release timeline of Drupal, and their signoff is needed. See the governance policy draft for more information.

  • Needs product manager review

    It is used to alert the product manager core committer(s) that an issue represents a significant new feature, UI change, or change to the "user experience" of Drupal, and their signoff is needed. If an issue significantly affects the usability of Drupal, use Needs usability review instead (see the governance policy draft for more information).

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024