zuul-web: rework caching

mod_mem_cache was removed in Apache 2.4 so all the bits of
configuration gated by the IfModule are currently irrelevant.

The replacement is socache, the in-memory version is "shmcb" (can also
hook up to memcache, etc.).  Enable the socache module, and switch the
cache matching parts to use socache and then fall-back to disk cache
(this is what it says this will do in the manual [1])

The other part of this is to turn the CacheQuickHandler off.  The
manual says about this [2]

  In the default enabled configuration, the cache operates within the
  quick handler phase. This phase short circuits the majority of
  server processing, and represents the most performant mode of
  operation for a typical server. The cache bolts onto the front of
  the server, and the majority of server processing is avoided.

I won't claim to fully understand how our mod_rewrite rules and
mod_proxy all hang together with phases and what-not.  But emperically
with this turned on (default) we do not seem to get any caching on the
tenant status pages, and with it turned off we do.

I've deliberately removed IfModule gating as well.  This actually hid
the problem and made it much more difficult to diagnose; it is much
better if these directives just fail to start Apache if we do not have
the modules we expect to have.

[1] https://httpd.apache.org/docs/2.4/mod/mod_cache_socache.html
[2] https://httpd.apache.org/docs/2.4/mod/mod_cache.html#cachequickhandler

Change-Id: I4e5f803b9d4fb6c2351cf151a085b93a7fd20f60
This commit is contained in:
Ian Wienand 2020-09-14 13:48:37 +10:00
parent 0177b40618
commit 8a2289f70a
3 changed files with 41 additions and 50 deletions

View File

@ -17,6 +17,7 @@
- ssl
- cache
- cache_disk
- cache_socache
- headers
- name: Remove old apache config

View File

@ -12,7 +12,6 @@
</VirtualHost>
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName zuul.openstack.org
ServerAdmin webmaster@openstack.org
@ -50,26 +49,24 @@
AddOutputFilterByType DEFLATE application/json text/css text/javascript application/javascript
<IfModule mod_cache.c>
CacheDefaultExpire 5
<IfModule mod_mem_cache.c>
# TODO: Should we cache the rest of the API too?
CacheEnable mem /api/status
CacheEnable mem /static/
# 80MB max cache size. 10 objects at 8MB max each.
MCacheSize 81920
MCacheMaxObjectCount 10
MCacheMinObjectSize 1
# 8MByte max size per cache entry
MCacheMaxObjectSize 8388608
MCacheMaxStreamingBuffer 8388608
</IfModule>
<IfModule mod_cache_disk.c>
CacheEnable disk /api/status
CacheEnable disk /static/
CacheRoot /var/cache/apache2/mod_cache_disk
CacheMaxFileSize 10000000
</IfModule>
</IfModule>
# Enable SHM backend for socache
CacheSocache shmcb
# Anything bigger should fall through to disk
CacheSocacheMaxSize 102400
# This is required to match on rewrites correctly
CacheQuickHandler off
# Disk cache settings
CacheRoot /var/cache/apache2/mod_cache_disk
CacheMaxFileSize 10000000
<LocationMatch "^/api/tenant/.*/status">
CacheEnable socache
CacheEnable disk
</LocationMatch>
<Location "/static">
CacheEnable socache
CacheEnable disk
</Location>
</VirtualHost>
</IfModule>

View File

@ -12,7 +12,6 @@
</VirtualHost>
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName zuul.opendev.org
ServerAdmin webmaster@openstack.org
@ -48,30 +47,24 @@
AddOutputFilterByType DEFLATE application/json text/css text/javascript application/javascript
<IfModule mod_cache.c>
CacheDefaultExpire 5
<IfModule mod_mem_cache.c>
# TODO: Should we cache the rest of the API too?
<LocationMatch "^/api/tenant/.*/status">
CacheEnable mem
</LocationMatch>
CacheEnable mem /static/
# 80MB max cache size. 10 objects at 8MB max each.
MCacheSize 81920
MCacheMaxObjectCount 10
MCacheMinObjectSize 1
# 8MByte max size per cache entry
MCacheMaxObjectSize 8388608
MCacheMaxStreamingBuffer 8388608
</IfModule>
<IfModule mod_cache_disk.c>
<LocationMatch "^/api/tenant/.*/status">
CacheEnable disk
</LocationMatch>
CacheEnable disk /static/
CacheRoot /var/cache/apache2/mod_cache_disk
CacheMaxFileSize 10000000
</IfModule>
</IfModule>
# Enable SHM backend for socache
CacheSocache shmcb
# Anything bigger should fall through to disk
CacheSocacheMaxSize 102400
# This is required to match on rewrites correctly
CacheQuickHandler off
# Disk cache settings
CacheRoot /var/cache/apache2/mod_cache_disk
CacheMaxFileSize 10000000
<LocationMatch "^/api/tenant/.*/status">
CacheEnable socache
CacheEnable disk
</LocationMatch>
<Location "/static">
CacheEnable socache
CacheEnable disk
</Location>
</VirtualHost>
</IfModule>