Problem/Motivation

While investigating #3436146: Introduce a list of "frequent cache tags" to reduce lookup query amount I was reminded about the problem with last write timestamp, which currently also causes a separate cache tag lookup for the cache bin because of our implementation of invalidate/delete on the whole bin.

We can likely identify those specific cache reads and handle them differently, essentially as a standalone lookup and not a full cache get. Possibly even a bulk load for common ones as suggested by that core issue.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Issue fork redis-3498940

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

berdir created an issue. See original summary.

berdir’s picture

I think there's actually one more lookup for each last write timestamp, the cache tag IIRC is for invalidateAll() which is almost never used, and there is a separate delete flag that's not a tag.

berdir’s picture

berdir’s picture

Status: Active » Needs review

Created a merge requests, seems to be working pretty well.

berdir’s picture

Tested this a bit more, have to clean the returned cache tags so they aren't picked up by the fast chained backend:

Impact of this as a diff of the MONITOR output:

--- compare/monitor_before.txt  2025-01-18 13:48:27.451401512 +0100
+++ compare/monitor_after.txt   2025-01-18 13:49:58.731385550 +0100
@@ -1,12 +1,8 @@
 "HGETALL" "core:container:service_container:prod:11.2-dev::Linux:a:4:{i:0;s:40:\"/var/www/html/sites/default/services.yml\";i:1;s:44:\"/var/www/html/sites/develop
 "GET" "core:cachetags:x-redis-bin:container"
 "GET" "core:container:_redis_last_delete_all"
-"HGETALL" "core:config:last_write_timestamp_cache_config"
-"GET" "core:cachetags:x-redis-bin:config"
-"GET" "core:config:_redis_last_delete_all"
-"HGETALL" "core:discovery:last_write_timestamp_cache_discovery"
-"GET" "core:cachetags:x-redis-bin:discovery"
-"GET" "core:discovery:_redis_last_delete_all"
+"GET" "core:last_write_timestamp_cache_config"
+"GET" "core:last_write_timestamp_cache_discovery"
 "HGETALL" "core:access_policy:access_policies:drupal:[user.is_super_user]=1:[user.roles]=authenticated,administrator"
 "GET" "core:cachetags:x-redis-bin:access_policy"
 "GET" "core:access_policy:_redis_last_delete_all"
@@ -15,9 +11,7 @@
 "HGETALL" "core:data:route:[language]=en:[query_parameters]=:/"
 "MGET" "core:cachetags:route_match" "core:cachetags:x-redis-bin:data"
 "GET" "core:data:_redis_last_delete_all"
-"HGETALL" "core:bootstrap:last_write_timestamp_cache_bootstrap"
-"GET" "core:cachetags:x-redis-bin:bootstrap"
-"GET" "core:bootstrap:_redis_last_delete_all"
+"GET" "core:last_write_timestamp_cache_bootstrap"

This saves 3x2 GET commands for the config, discovery and bootstrap cache bins during bootstrap roughly up until dynamic page cache.

Complete output after with this:

"HGETALL" "core:container:service_container:prod:11.2-dev::Linux:a:4:{i:0;s:40:\"/var/www/html/sites/default/services.yml\";i:1;s:44:\"/var/www/html/sites/develop
"GET" "core:cachetags:x-redis-bin:container"
"GET" "core:container:_redis_last_delete_all"
"GET" "core:last_write_timestamp_cache_config"
"GET" "core:last_write_timestamp_cache_discovery"
"HGETALL" "core:access_policy:access_policies:drupal:[user.is_super_user]=1:[user.roles]=authenticated,administrator"
"GET" "core:cachetags:x-redis-bin:access_policy"
"GET" "core:access_policy:_redis_last_delete_all"
"HGETALL" "core:access_policy:access_policies:drupal:[languages:language_interface]=en:[user.is_super_user]=1:[user.roles]=authenticated,administrator"
"MGET" "core:cachetags:config:user.role.authenticated" "core:cachetags:config:user.role.administrator" "core:cachetags:access_policies"
"HGETALL" "core:data:route:[language]=en:[query_parameters]=:/"
"MGET" "core:cachetags:route_match" "core:cachetags:x-redis-bin:data"
"GET" "core:data:_redis_last_delete_all"
"GET" "core:last_write_timestamp_cache_bootstrap"

There are still 2 cache tag lookups for the bin-tag that powers invalidateAll(), on container and access_policy. I'll create a separate issue to allow to opt-out of the current invalidateAll() implementation and handle it as a deleteAll().

I also want to investigate the access policy implementation.

  • berdir committed d9ae0f9f on 8.x-1.x
    Issue #3498940 by berdir: Optimize bin cache tags and last write...
berdir’s picture

Status: Fixed » Closed (fixed)

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