Optimize bin cache tags and last write timetamp

Created on 11 January 2025, 3 months ago

Problem/Motivation

While investigating Introduce a list of "common cache tags" to reduce lookup query amount Active 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

📌 Task
Status

Active

Version

1.0

Component

Code

Created by

🇨🇭Switzerland berdir Switzerland

Live updates comments and jobs are added and updated live.
  • Performance

    It affects performance. It is often combined with the Needs profiling tag.

Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @berdir
  • 🇨🇭Switzerland berdir Switzerland

    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.

  • 🇨🇭Switzerland berdir Switzerland
  • Merge request !49bypass regular cache for last write timestamps → (Merged) created by berdir
  • 🇨🇭Switzerland berdir Switzerland

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

  • 🇨🇭Switzerland berdir Switzerland

    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.

  • Pipeline finished with Skipped
    3 months ago
    #399677
    • berdir committed d9ae0f9f on 8.x-1.x
      Issue #3498940 by berdir: Optimize bin cache tags and last write...
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024