navigation

Reverse-Proxy Cache and WPMU

This is our latest article in the WordPress MU Caching section, make sure you checked out the others !

This article is the less versatile of the ones I wrote in this section, because it will only be interesting to you if you if you have (or plan to have) a multi-server architecture. In this case it’s likely you’ve separated HTTP and SQL servers, and if your platform is big enough that you have multiple HTTP servers. Then, you need a way to dispatch users across the different HTTP servers. While you may have a load balancer, which is the most robust solution to do this (and the single point of failure the least likely to fail), another solution is to use a reverse proxy on a front server. This server can handle all incoming requests, and then route them to abackend HTTP server.

There’s plenty of things you can have the reverse proxy do that will decrease the load on your backend servers without endangering too much its stability, like security (IP banning etc.), content compression (gzip), and another very interesting one is caching.
It is one of the biggest flows in wordpress in my opinion that whenever you load a static file (image, music, office document, etc.), it has to go through PHP and then run many SQL queries just to load this static file. This prevents you, if you don’t want to hack the files manipulating uploads, from using a lightweight HTTP server to serve those static files, and this generates unnecessary load on your machines. Using a cache at the reverse proxy level can help solve this problems : basically the first time a static file is accesse, it will get cached on the reverse proxy server, and all subsequent requests to this file will be served directly from the front end machine, without needing php or mysql.

There are many software solutions for reverse proxies, including Apache 2 with mod_proxy, lighttpd, Squid or Nginx (this last doesn’t have the caching option though).

It’s fairly easy to configure apache 2 with mod_proxy, to give an idea here is a sample configuration :


# Cache static files on disk

CacheRoot /home/cache
CacheMaxFileSize 1000000
CacheEnable disk /files
CacheDirLevels 2
CacheDirLength 1

# Cache avatars in memory

MCacheMaxObjectCount 10000
MCacheSize 50000
CacheEnable mem /wp-content/avatars

Some warnings :

Caching files on the reverse proxy machine may mean lots of disk accesses for this machine, so make sure it has fast disks and/or cache what can be in memory rather than on disk.

Caching can cause problems if for instance you need to remove a blog that is against the law. Its files will stay in cache until purged, so removing them right away might mean flushing your cache completely.

Apache doesn’t have implemented yet a garbage collection for mod_cache. To prevent your cache from getting too big and/or full of useless files run something like this in cron :

30 3 * * * root /usr/sbin/tmpwatch -fud 72 /home/cache/ >/dev/null 2>/dev/null

This will remove from your cache the files that were not accessed in the past 72 hours.

Happy proxying :) .

Commentaires»

1 17 18 19
  1. If you desire to take a great deal from this post then you have to apply such techniques to your
    won webpage.

    Here is my site :: tinh bot nghe

  2. I really love your website.. Great colors & theme.
    Did you create this site yourself? Please reply back as I’m
    trying to create my own personal website and want to find out where you got this from or exactly what the
    theme is named. Thank you!

    my website; tim gai goi ha noi

  3. Wonderful work! This is the particular information that will
    be shared over the internet. Disgrace on Google for not any
    longer positioning this submit higher! Come on over and talk to my website .
    Thanks =)

    My web blog ArianneTVega

  4. Do you have a spam problem on this website; I also am a blogger, and I was curious about your situation;
    we have created some nice methods and we are looking
    to swap strategies with others, be sure to shoot me an email if
    interested.

    My homepage: MerriGDarras

  5. After looking into a few the articles or content on your site, I honestly appreciate your technique of blogging.
    I book marked it to my bookmark website list and will also be checking back soon. Please go to my web site
    too and let me know your opinion.

    Here is my website … PorterOCelis

  6. Hey there! This post could not be written any better!
    Reading through this post reminds me of my good old room mate!
    He always kept talking about this. I will forward this article to him.

    Fairly certain he will have a good read. Thank you for sharing!

    Here is my blog – IELTS Sharjah

1 17 18 19

Laisser un commentaire

Le Web Rémunéré |
les codes pokemon |
........l'univers de TINTIN... |
Unblog.fr | Créer un blog | Annuaire | Signaler un abus | nateeve05.blogee.com
| BOUCHEKFA
| riadsfes