url_alias queries take up too much time

merlinofchaos - February 4, 2006 - 00:47
Project:Drupal
Version:4.7.2
Component:path.module
Category:bug report
Priority:normal
Assigned:Unassigned
Status:duplicate
Description

On a site with a large menu there can be many url_alias queries. Now, at 1ms or less per query, individually they aren't a big deal, but even modest sites quickly get 30-40 of them on every page hit, and I can envision scenarios where you might see hundreds of them.

My solution is to create a cache that keeps the ones that get hit a lot, without burdening the system for the ones that get hit less often.

This patch is, at the moment, incomplete, but I wanted to get some community evaluation before I put the niceties on it.

It needs:

  • Documentation of the functions that were added
  • a form field in system_settings to control the cache size

This patch caches the url_alias map, and additionally keeps the last time a given alias was hit. It writes the cache on page exit; when it does so, if the number of items in the cache exceeds the threshold (defaulting to 500 items), it prunes items least recently hit first. This means that items that appear commonly on menus, that are hit often, will remain; items that are hit only on some nodes will quickly get pruned off.

On my test site this has the effect of shaving about 70ms off of every page view -- this is very significant on light pages, and of minor but still important significance on heavy pages.

I'd love to see a few people try this out and see what they thing, and ensure that my implementation is correct.

AttachmentSize
cache-url-alias.patch3.37 KB

#1

merlinofchaos - February 4, 2006 - 00:48

Oh yes, one addition:

The system needs to update the cache (or invalidate it) when path aliases are modified; that also is missing from this patch.

#2

Dries - February 4, 2006 - 10:03

Code style nit: we try not to glue words together (lasthit) and try not to abbreviate words.

Did you benchmark this?

#3

Wesley Tanaka - February 4, 2006 - 10:58
Status:needs review» duplicate

This has previously been reported here: http://drupal.org/node/40860

#4

Dries - June 29, 2006 - 06:07
Version:4.7.0-beta4» 4.7.2

See also at http://buytaert.net/drupal-database-interaction ...

 
 

Drupal is a registered trademark of Dries Buytaert.