High number of database connects & queries to redirect table

Created on 29 January 2025, 3 months ago

We'll occasionally get a spike in database connections and when we check our db log we see many entries like this one below. There's a CONNECT, a SELECT to the path_alias table, a SELECT to the redirect table, then the connection quits.

The majority of these lookups are for non-existent hashes in the redirect table.

Is this normal?
Is there a way to troubleshoot and eliminate these lookups?

2025-01-29T19:25:05.207792Z	130131070 Connect	somebody@10.10.0.20 on drupaldb using TCP/IP
2025-01-29T19:25:05.208437Z	130131070 Query	SET NAMES utf8mb4
2025-01-29T19:25:05.209084Z	130131070 Query	SET SESSION transaction_isolation='READ-COMMITTED'
2025-01-29T19:25:05.209675Z	130131070 Query	SET sql_mode = 'ANSI,TRADITIONAL'
2025-01-29T19:25:05.221103Z	130131070 Query	SELECT "base_table"."id" AS "id", "base_table"."path" AS "path", "base_table"."alias" AS "alias", "base_table"."langcode" AS "langcode" FROM "path_alias" "base_table" WHERE ("base_table"."status" = '1') AND ("base_table"."alias" LIKE '/assets/js/js\\_SLcjwP2kKKpKwmSnZowXg\\_5o1VpN\\_kEHeLJM1Hbyndc.js' ESCAPE '\\') AND ("base_table"."langcode" IN ('en', 'und')) ORDER BY "base_table"."langcode" ASC, "base_table"."id" DESC
2025-01-29T19:25:05.222728Z	130131070 Query	SELECT rid FROM "redirect" WHERE hash IN ('bTPDZJC-gu2ENPbvnO671sSlp2Kaa1XHIU6EvlL-TKc', 'pYcf-Msub-E_Ej1EKXn9HB0stH9BikS9XcdqaYKF2Zw', 'guj4NDxC-E3oRafQWQfG7u0L5Apv7vEaC0uDKVuQtQA', 'tB211hIvngszCb7x3hz_pq1nKsonQBW2ALBygiW0AWs') ORDER BY LENGTH(redirect_source__query) DESC
2025-01-29T19:25:05.288514Z	130131070 Quit

This may be related to: https://www.drupal.org/project/redirect/issues/3496341 🌱 [meta] Try to reduce database queries from redirect lookups Active

πŸ’¬ Support request
Status

Active

Version

1.11

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States todea

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @todea
  • πŸ‡¨πŸ‡­Switzerland berdir Switzerland

    redirect needs to check every request, it makes sense that most don't exist. The proposed caching might help that you already linked to depending on the path that this involves.

    I don't know why it quits afterwards, but I assume you might be using dynamic page cache and those requests might involve different query strings or something that are a dynamic page cache hit or a 404 page or something then.

    the example here seems to be a link to an asset file, that should only be requested once and then exist on the file system.

    Nothing unexpected here in regards to redirect.

  • πŸ‡ΊπŸ‡ΈUnited States todea

    the example here seems to be a link to an asset file, that should only be requested once and then exist on the file system.

    That's what I was wondering. We have constant requests like this for our aggregated CSS & JS hitting the database.

    We do have dynamic page cache enabled. However, we can try disabling it since the majority of our site is static.

  • πŸ‡¨πŸ‡­Switzerland berdir Switzerland

    > We do have dynamic page cache enabled. However, we can try disabling it since the majority of our site is static.

    That's not my point at all. Nothing wrong with redirect, nothing wrong with Dynamic page cache.

    If it's specifically asset requests that are happening, make sure that those files actually exist on the filesystem afterwards. The idea is that the first request hits Drupal and all following requests are static files. That URL looks unusual, by default it's sites/default/files/assets. Make sure that folder is writable and Drupal puts them in the right place, check your asset stream wrapper configuration.

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

Production build 0.71.5 2024