Problem/Motivation

In his presentation at drupal dev days @fgm asked the audience how many queries it takes to deliver a cached page. I was not sure, I never bothered to profile that. I knew that the one to cache_page is not the only one, because in core hook_boot is also executed and in order to retrieve the hook implementations, at least one additional cache_get is necessary. Also variable_initialize() adds another cache_get().

In Authcache we do not run hook_boot at all, therefore I did not expect any room for optimization here.

Turns out that we can do much better, especially after the bootstrap cache was cleared as a result of a variable_set(). This happens during every cron when using core cron (hint: use a better cron module). In addition there are a gazillion of contrib modules which use variable_set() in the most inappropriate places.

The solution is to avoid initializing variables when delivering cached pages. This avoids all queries but the ones which are really needed for caching, 1 (for anonymous users) and 2 (for authenticated due to the key-retrieval mechanism). In HEAD 3 and 4 respectively are executed if the bootstrap cache is warm. Avoiding those two extra queries increases performance by 30% when delivering cached pages on my machine.

The difference is even bigger when the bootstrap cache was cleared before. In that case delivery of a cached page triggers a variable cache rebuild which involves locking (just search the web for drupal semaphore deadlock in order to estimate the consequences this can have). In that case up to 10 queries are executed, 4 of them inserts/deletes before delivery of a cached page is even attempted.

Proposed resolution

Introduce a setting authcache_builtin_cache_without_variables. If the flag is set to TRUE from within settings.php, then variables are not initialized when delivering cached pages.

Remaining tasks

User interface changes

API changes

Comments

znerol’s picture

Status: Active » Needs review
StatusFileSize
new818 bytes

Note that this only helps if you use the database backend. When using contrib caches, it is recommended to follow Authcache 2 tuning guide - avoid the database.

znerol’s picture

Issue summary: View changes
wim leers’s picture

Wow!

@fgm++ :)

znerol’s picture

StatusFileSize
new1.96 KB
new1.16 KB

Adding docs.

  • znerol committed d6efe15 on 7.x-2.x
    Issue #2480741 by znerol: Introduce an option to deliver cached pages...
znerol’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.