navigation

WPMU Object Cache using APC

This is part of the caching for WPMU section of this blog, make sure to browse the other subpages for more information !

WordPressMU comes built-in with an Object Cache. First of all, a small explanation : how is it different from the first two caches we talked about (mysql query cache and PHP cache) ? Well, mysql caches the result sets from SQL queries. The PHP cache caches the compiled version of your scripts in memory. The WPMU object cache is built in the code of WordPress, and it is a way to cache PHP objects (arrays etc.).

For instance, it caches site options, so that it is not necessary to run the same SQL queries everytime you want to fetch these options (which is basically, all the time). Instead these options are put in the cache and read from it systematically. In a similar manner, blog-specific options are stored in the Object Cache. It can save you a lot of SQL queries to use the object cache. The following diagram shows the decrease in number of SQL queries run on one of unblog’s database servers once the object cache was turned on :

mysqlload.jpg

Almost 50% less queries than the previous day, without the cache. Great ! So this object cache will lower your SQL load. But wait until you rush turning this on, and read on a bit more.

By default, if you enable the object cache in WPMU, it will use flat files on the disk to store the cached information. Look into the wp-content/cache folder, and you’ll see something along the lines of :

cache.jpg

This shows you the structure of the cache on disk (the readable named folders are the global objects caches, the random one contains the cached objects of a given specific blog).

All this is great, but to decide whether or not you want the object cache enabled, you need to be sure that it will actually be positive on your server. Basically, enabling the object cache :

- Results in less SQL queries. In most cases those queries would have been served from the query cache (in memory).

- Results in more disk accesses. Every time the cache is accessed, files are read on disk, and everytime the cache is written, files are written to disk.

The problem is, SQL/memory might not be your architecture’s bottleneck, and disk access might well be. With bloggers constantly uploading and downloading files, hard drives have shown in our experience to be an important bottleneck in performance. In unblog.fr’s architecture, we have made extensive tests with the object cache, which has shown to slightly decrease the load on the database machines (only slightly because most of the queries were served from cache and quite fast), but also slightly increase the load on HTTP servers due to more disk accesses. Since our HTTP servers were more loaded than our SQL servers, we ended up turning off the cache.

So TEST the object cache if you’re going to use the file/disk storage medium. You might end up turning it off.

But wait, is there no way to make this object cache worth a penny ? Actually yes, there is.

The good thing about the object cache is that is allows you to override the default storage medium (files on disk) with your own. This means that with a couple of lines of PHP, instead of storing cached objects on disk, you can do it in memory, for instance by using APC’s user variable cache or the popular Memcached.

Memcached is a distributed system, which means it can be handy if you have multiple load-balanced HTTP servers. However it is slightly slower than APC’s cache, and needs you to run the memcached deamon on all your machines. If you want to go the Memcached route, you can try out Ryan Boren‘s plugin, although be careful because we did not test this with WordPress MU and can’t guarantee it will work as-is. It is known that memcached is the object cache storage used on wordpress.com.

For unblog.fr, we have preferred to use APC as our object cache, because it can be used as an opcode cache in the meantime, and because of slightly better performance. We started from the WordPress plugin by Mark Jaquith and modified by Eric Byers and we added some modifications/improvements to make it work better and work with WPMU. The original version was emptying the whole of APC’s cache when flushing cache (including the script caches) instead of just the object cache, and had a couple of other issues.
Download here our version (tested in WPMU). Then drop the object-cache.php file in wp-content, and add :

define(« ENABLE_CACHE » ,true);

to your wp-config.php file.

You will probably need to increase how much shared memory you allocate to APC in order to avoid segmentation faults, as we mentionned here.

This solution will give you optimal performance, by limiting the load on your DB servers, without increasing it on your HTTP servers thanks to the memory storage offered by APC. Champagne !

Commentaires»

1 2 3 13
  1. i dont see any posting date?
    is this post updated?
    does this work with the latest wpmu?

    tnx.

  2. got this error:

    Warning: Cannot modify header information – headers already sent by (output started at /website/wordpress-mu/wp-content/object-cache.php:184) in /website/wordpress-mu/wp-content/plugins/wp-super-cache/wp-cache-phase2.php on line 48

  3. I noticed that the ENABLE_CACHE definition is not necessary. It works without any defines. However, please note that the cache does not work with multiple WordPress installations running. You need to define some global prefix for each installation to every key.

    — object-cache.php.orig Thu Feb 18 13:07:15 2010
    +++ object-cache.php Thu Feb 18 13:07:05 2010
    @@ -23,10 +23,15 @@
    Adapted global groups to WPMU
    Fixed key creation a bit
    */

    +// define a global cache prefix for multiple WP installations
    +// (simply define one in wp-config.php)
    +if ( !defined(WP_OBJECT_CACHE_KEY_PREFIX) ) {
    + define(WP_OBJECT_CACHE_KEY_PREFIX,  »);
    +}

    // gracefully revert to default cache if APC is not installed
    if ( !function_exists(‘apc_store’) ) {
    include_once(ABSPATH . WPINC . ‘/cache.php’);
    } else {
    @@ -139,11 +144,11 @@
    else
    $prefix = $blog_id . ‘-’;
    if(  » != $key )
    $key = ‘-’ . $key;

    - return « $prefix$group$key »;
    + return WP_OBJECT_CACHE_KEY_PREFIX. »$prefix$group$key »;
    }

    function replace($id, $data, $group = ‘default’, $expire = 0) {
    return $this->set($id, $data, $group, $expire);
    }

  4. Thanks admin for this post. really appreciated

  5. ПРОДВИЖЕНИЕ ИНТЕРНЕТ-МАГАЗИНА раскрутка сайта in Яндекс, Google, Rambler Bing апорт Mail
    The search engine Яндекс, Google, Rambler Bing апорт Mail is one of the four leaders popular among Russian-speaking population. If your target audience is the older generation or the youth, absorbed in services Яндекс, Google, Rambler Bing апорт Mail , then offer you a promotion site in this system.
    Features of promotion of sites in the Яндекс, Google, Rambler Bing апорт Mail :
    Indexing of new pages is extremely slow.
    Яндекс, Google, Rambler Bing апорт Mail attendance is recorded in the allocation of pages of site positions in the SERP.
    Site promotion takes a long time.
    Promotion of a site in Яндекс, Google, Rambler Bing апорт Mail approximately similar to the promotion of other search engines. Unique content, titles and meta tags for each page of the site, inbound links from sites thought perelinkovka copyright and other works – all increase the ranking for keywords in the Яндекс, Google, Rambler Bing апорт Mail .
    If you want visible results to promote your site in search engine Яндекс, Google, Rambler Bing апорт Mail , please contact our company: we will achieve as quickly as possible to improve your site’s position in search results to fit your needs.
    Specificity of site promotion in Яндекс, Google, Rambler Bing апорт Mail
    Statistics show that currently Яндекс, Google, Rambler Bing апорт Mail – the fourth most popular search engine used by the Russian-speaking audience of the Internet. Unfortunately, the audience this year is reduced. Nevertheless, Яндекс, Google, Rambler Bing апорт Mail has its admirers. Typically, Яндекс, Google, Rambler Bing апорт Mail users prefer older, for a long time using the Internet, as well as part of the youth, which involved services, such as Яндекс, Google, Rambler Bing апорт Mail ICQ and so on. If such people are the target audience of your site, promotion Яндекс, Google, Rambler Bing апорт Mail you need. In other cases, you can decide whether you need a comprehensive website promotion, that is, coverage of the three most popular search engines: Яндекс, Google, Rambler Bing апорт Mail, Яндекс, Google, Rambler Bing апорт Mailand Яндекс, Google, Rambler Bing апорт Mail , or you stop for a promotion in a single search engine.
    Promotion of a site in Яндекс, Google, Rambler Bing апорт Mail has a number of features. First of all, many optimizers indicate that ranking algorithms Яндекс, Google, Rambler Bing апорт Mail obsolete. It is characterized by low speed indexing pages and update the search database. That is why many ПРОДВИЖЕНИЕ ИНТЕРНЕТ-МАГАЗИНАs do not give any guarantees on the promotion of sites in the Яндекс, Google, Rambler Bing апорт Mail . But it is only those optimizers that rely on quick results. A promotion in Яндекс, Google, Rambler Bing апорт Mail takes a long time. Typically, to achieve sustainable results can only be for six months or more.
    Of course, Яндекс, Google, Rambler Bing апорт Mail , as for any search engine, what is important internal and external factors. One of the most important factors for successful promotion of a Яндекс, Google, Rambler Bing апорт Mail – the number and rate of growth of external links. Compared with the more popular search engines Яндекс, Google, Rambler Bing апорт Mail uses outdated search algorithms and ranking. Therefore, methods of promotion in the Яндекс, Google, Rambler Bing апорт Mail differ significantly from the methods used for other search engines.
    Unfortunately, the speed of indexing pages in the Яндекс, Google, Rambler Bing апорт Mail and the frequency of issue for updates to this search engine are unpredictable. Described features of the search engine significantly impede the work of the optimizer. Nevertheless, as practice shows, to achieve good results in the promotion Яндекс, Google, Rambler Bing апорт Mail possible. http://SEO-miheeff.ru
    While moving a site under the Яндекс, Google, Rambler Bing апорт Mail is important to consider the main features of this engine. First, Яндекс, Google, Rambler Bing апорт Mail indexes new pages very slowly. That is why on the fast promotion in the Яндекс, Google, Rambler Bing апорт Mail of speech does not go. Attaches great importance to the uniqueness of Яндекс, Google, Rambler Bing апорт Mail placed on the website texts. Яндекс, Google, Rambler Bing апорт Mail – one of the few search engines, which have not yet abandoned the attendance records of pages in the calculation of their popularity.

  6. Live each day as if it were your last, but learn from each day as if you will live forever.

  7. Оказываем помощь: открыть Брокерскую компанию, открыть Дилинговый центр.
    Короткие сроки. Полный спектр услуг. Бесплатная тех. поддержка.
    Минимальные затраты на начальном этапе от 15 000 долларов
    Принимайте верное решение, получите полную информацию о том как
    открыть свою компанию на рынке Форекс и уже завтра получите свой бизнес на Форекс!
    Мы работаем для вас! Связь с нами по скайпу: hi-tech-fx

  8. Привет! Вы знакомы с биржей sape?

  9. Оказываем помощь: открыть Брокерскую компанию, открыть Дилинговый центр.
    Короткие сроки. Полный спектр услуг. Бесплатная тех. поддержка.
    http://hi-tech-fx.com/
    Минимальные затраты на начальном этапе от 15 000 долларов
    Принимайте верное решение, получите полную информацию о том как
    открыть свою компанию на рынке Форекс и уже завтра получите свой бизнес на Форекс!
    Мы работаем для вас! Связь с нами по скайпу: hi-tech-fx

  10. Hello to the by everybody on this fair forum. Let me loan a beforehand myself. I am connoisseur and i am competition this website :
    dizi izle
    Waiting for all these friends.
    Regards

  11. DLC FT INVEST объявляет о проведении Акций!

    Весь Март месяц 2013 года советник MTS-MC LIGHT по цене 20.13$
    Абонентская плата 20.13$ в месяц! За год всего 240$

    Начинайте строить свой бизнес и получать прибыль прямо сейчас!
    http://dlcft.ru/

  12. Hi there! I could have sworn I’ve been to this blog before but after reading through some of the post I realized it’s new to me.
    Nonetheless, I’m definitely delighted I found it and I’ll be book-marking and
    checking back frequently!

    Visit my page :: broker option binaire

  13. The other day, while I was at work, my cousin stole my iPad
    and tested to see if it can survive a forty foot drop, just so she can be a
    youtube sensation. My iPad is now broken and she has 83 views.

    I know this is totally off topic but I had to share it with someone!

  14. This ԁeѕign iѕ speсtacular!
    You mοst certainly knoω how to keеp a
    rеader entertaіnеd. Between your wit anԁ
    your νidеos, ӏ was almost moved to start my own blοg (well,
    almoѕt…НaHa!) Wondеrful job.
    I гeally lоved what you hаd to saу, and mοrе than that, how you preѕented
    it. Too cοol!

  15. Attractive section of content. I just stumbled upon
    your site and in accession capital to assert that
    I get actually enjoyed account your blog posts.
    Any way I will be subscribing to your augment and even I achievement you access consistently fast.

  16. This page certainly has all the information I wanted concerning this subject
    and didn’t know who to ask.

  17. Write more, thats all I have to say. Literally, it seems as though you relied on the video to make your point.
    You obviously know what youre talking about, why waste your intelligence on just
    posting videos to your blog when you could be giving us something enlightening to read?

  18. Hello! Do you use Twitter? I’d like to follow you if that would be okay.

    I’m absolutely enjoying your blog and look forward to
    new updates.

  19. This is a topic that is near to my heart…
    Cheers! Exactly where are your contact details though?

1 2 3 13

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