Add the option to cache drupal_get_filename()

Created on 26 February 2015, over 9 years ago
Updated 20 July 2023, about 1 year ago

drupal_get_path() has quite a few IO calls that aren't needed on sites after they have been deployed. Even if the static cache is hit, there's a few calls to file_exists() that get called anyways. For sites that are deployed with version control or something similar, we know that code isn't changing under us without an update and cache clear being run.

The attached patch adds optional caching support to drupal_get_filename(). I've kept it off by default as it could be a major DXWTF for local environments, and quite confusing for anyone who might be manually creating code files on servers. On one large code base, I'm getting a 20% performance improvement on an uncached anonymous page after the drupal_get_path() cache is warmed.

Here's ab results against a real site implementation. This is inside a vagrant VM, but the code is sync'ed with rsync so IO is against the local disk image and not over the network.

This is ApacheBench, Version 2.3 <$Revision: 1554214 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking local.sitename.com (be patient).....done


Server Software:        Apache/2.4.7
Server Hostname:        local.sitename.com
Server Port:            80

Document Path:          /an-awesome-url
Document Length:        90716 bytes

Concurrency Level:      1
Time taken for tests:   256.821 seconds
Complete requests:      100
Failed requests:        0
Total transferred:      9127100 bytes
HTML transferred:       9071600 bytes
Requests per second:    0.39 [#/sec] (mean)
Time per request:       2568.206 [ms] (mean)
Time per request:       2568.206 [ms] (mean, across all concurrent requests)
Transfer rate:          34.71 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.1      0       0
Processing:  2450 2568 259.4   2540    5095
Waiting:     2385 2493 257.5   2466    5007
Total:       2450 2568 259.4   2540    5095

Percentage of the requests served within a certain time (ms)
  50%   2540
  66%   2555
  75%   2567
  80%   2576
  90%   2609
  95%   2647
  98%   2701
  99%   5095
 100%   5095 (longest request)

After this patch, and setting $conf['cache_drupal_get_filename'] = TRUE;.

This is ApacheBench, Version 2.3 <$Revision: 1554214 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking local.sitename.com (be patient).....done


Server Software:        Apache/2.4.7
Server Hostname:        local.sitename.com
Server Port:            80

Document Path:          /an-awesome-url
Document Length:        90716 bytes

Concurrency Level:      1
Time taken for tests:   202.005 seconds
Complete requests:      100
Failed requests:        0
Total transferred:      9127100 bytes
HTML transferred:       9071600 bytes
Requests per second:    0.50 [#/sec] (mean)
Time per request:       2020.047 [ms] (mean)
Time per request:       2020.047 [ms] (mean, across all concurrent requests)
Transfer rate:          44.12 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1  11.7      0     117
Processing:  1948 2019  86.4   2009    2819
Waiting:     1877 1945  85.6   1936    2744
Total:       1948 2020  86.9   2009    2819

Percentage of the requests served within a certain time (ms)
  50%   2009
  66%   2023
  75%   2031
  80%   2036
  90%   2054
  95%   2074
  98%   2120
  99%   2819
 100%   2819 (longest request)

I haven't looked at D8 yet to see if this is needed, but if this passes 7.x tests to make sure the idea isn't horribly broken I'll forward port it.

Feature request
Status

Needs work

Version

11.0 🔥

Component
File system 

Last updated about 22 hours ago

Created by

🇨🇦Canada deviantintegral

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024