Documentation for Confluence 5.7.
Documentation for Confluence Cloud and earlier versions of Confluence is available too.

Skip to end of metadata
Go to start of metadata

To improve performance of a large Confluence site, we recommend that you move the caching of static content from the JVM into Apache. This will prevent the JVM from having a number of long running threads serving up static content.

Static content in Confluence includes most JavaScript, CSS and image files which are included with the application or an installed plugin. This content will be cached by Apache in this configuration. User-provided content like space logos, attachments or embedded images are not considered static content and will not be cached.

Note: This page documents a configuration of Apache, rather than of Confluence itself. Atlassian will support Confluence with this configuration, but we cannot guarantee to help you debug problems with Apache. Please be aware that this material is provided for your information only, and that you use it at your own risk.

Configuring Apache mod_disk_cache

 To configure Apache to cache static Confluence content:

  1. Add a mod_disk_cache stanza to the virtual host configuration:

    <IfModule mod_disk_cache.c>
      # "/s" is where Confluence serves "static" stuff. Instruct Apache to cache it:
      CacheEnable disk /s
      CacheIgnoreHeaders Set-Cookie
      CacheRoot "/var/cache/mod_proxy"
    </IfModule>
  2. Configure Apache to load mod_disk_cache. For example, in our server configuration this is done in /etc/httpd/conf/httpd.conf:

    LoadModule disk_cache_module modules/mod_disk_cache.so
  3. Restart Apache after both modifications are complete.

Notes

  • Please refer to the Apache documentation for mod_disk_cache.
  • If you encounter problems where users are served stale content, you may need to purge the Apache cache directory (/var/cache/mod_proxy in the above configuration) after a Confluence or plugin upgrade. This is a simple 3 step process:
    • Shut down Apache.
    • Clear the cache directory. For example: sudo rm -r /var/cache/mod_proxy/*
    • Restart Apache.
  • Ensure that you are running the htcacheclean daemon in order to prevent excessive use of disk space. In our situation we ran it like this:

    sudo htcacheclean -d30 -n -t -p /var/cache/mod_proxy -l 512M

    This will purge content once the cache reaches 512M every 30 minutes.  See the Apache documentation for htcacheclean for details of the options.

  • No labels

9 Comments

  1. As an alternative to htcacheclean, consider setting "MCacheSize 512000".

    1. The MCacheSize directive is limited to use with Apache's mod_mem_cache whereas this document is specifically about leveraging persistent file system cache via Apache's mod_disk_cache.  Unfortunately mod_disk_cache doesn't have a directly configurable upper bound on the amount of disk space it will consume, hence the need for the htcacheclean helper process.  However, if you know your cache size is relatively small and have the RAM to spare, then running mod_mem_cache could work very well for you.

  2. I would like to use a controlled upstream proxy/caching server to cache Atlassian static content.  Is there any way to modify the cache-related http headers to allow this? (I see how the disk cache would work on a local Apache httpd installation, but I would like to support Atlassian tools behind a set of remote reverse proxy / load-balancers.)

    1. You might consider asking your question at http://answers.atlassian.com/ to cast a wider net of potential "answerers."

  3. Consider adding "htcacheclean -d30 -n -t -p /var/cache/mod_proxy -l 512M" to /etc/rc.local so that htcacheclean will run after a reboot.

  4. Is this Apache config for setting up mod_disk_cache specific to only Confluence or is it also relevant for JIRA? Does JIRA serve static content and does it make sense to use this same configuration for the intended performance benefits of not using the JVM for caching?

    1. Using cache is also recommended for JIRA by several best practices like Performance Tuning Atlassian #3 .

      If possible play with it on a test system. Use JIRA Data Generator and a monitoring like javamelody to see the impact on your setup.

  5. Should not the /images subdirectory be similarly cached? Any others?

  6. I just did some testing with our Confluence testing environment:

    • Windows Server 2008 R2 (Running on VMware)
      • 4GB RAM
    • Apache HTTPD 2.4.9 32bit
      • All traffic is served via https
      • Apache is terminating the SSL connections
    • Confluence 5.7.1 64bit (Tomcat 7.0.52)
      • JVM Heap 1024MB - 2535MB

    Configuration 1:

    Apache & Tomcat are connected via mod_jk, no Apache caching is used.

    Configuration 2:

    Apache & Tomcat are connected via mod_proxy_ajp, Apache mod_cache & mod_cache_disk is used with default configuration:

    cacheEnable /s "d:/Apache/cache"
    cacheEnable /confluence/s "d:/Apache/cache"

    Configuration 3:

    Apache & Tomcat are connected via mod_proxy_http. Apache mod_cache & mod_cache_disk is used with default configuration:

    cacheEnable /s "d:/Apache/cache"
    cacheEnable /confluence/s "d:/Apache/cache"

    Result:

    Apache disk caching is working in configuration 2&3 as cache directory is filling up with files.

    I found out that the load time of various Confluence pages are about 3-4 times faster when using configuration 1 (without any caching on Apache side), even when reloading the same page more than once.

    This result was verified on our production site with a fixed JVM heap of 8GB. We expected to see a speed up using Apache side caching but this was definitely not the case.

    I assume that caching on Tomcat/Confluence side has improved a lot with 5.7. Please note that Apache HTTPD & Confluence are running on the same machine on both setups (Test & Production). Database is MySQL 5.6.22 running on a remote DB-Server.

    So, I guess, there is no general suggestion but do some testing on your own environment. Comments & remarks from your side are very welcome!