On twitter

@Lydia618 相差不遠了 (茶)

follow me on twitter

[django] johnny cache 4

現在有自己的 django project 在 running 的好處就是可以隨便試一些東西, 昨天晚上看到了 Johnny Cache 這篇文章, 馬上就用 pip 裝了起來, 裝上 stickeraction, 儘管原本對 loading 最重的部份都已經用了 memcache 做處理, 沒想到 mysql queries 馬上就往下掉。

不過其實我還沒去看他的作法 XD 反正他都說有在 production 跑了 (笑)

Anyway, 基本上他的作法主要還是對 queryset 做 cache, 其實先前 pownce 的 mmalone 就有寫了 queryset caching 的 example app, 只是裝上之後得換掉 ModelManager, 有點麻煩, 而 johnny cache 的作法僅是在 settings.py 裡面加進幾行而已, transparent 得多了, Johnny Cache 這篇文章的 comments 裡面也有提到另一個 django-cache-machine

不過雖然 mysql 的 loading 往下掉, 可是 context switches 跟 interrupts 還有 cpu 都往上飆勒, 在多跑幾天看看。

March 2nd, 2010 Programming, django Tags: ,

4 Responses to “[django] johnny cache”

  1. jmoiron says:

    Hi @tzangms,

    A few things happen with Johnny Cache:

    * Every request is a few cache loads for table generation keys.
    * Every SELECT that goes to the DB is also a cache miss.

    CPU usage going up is probably because of more frequent cache usage. Total SELECT query counts dropping (not just mysql query cache hits) might be because Johnny can cache some queries that mysql’s query set cache won’t cache.

    As for context switching, Memcached is handling a lot more requests now, so the OS scheduler will swap between mysql & memcached more often (their SELECTs will signal more often). It is a little hard to get it just right on one server ^_^

  2. tzangms says:

    @jmoiron

    Cool! thanks for your explaination. :D

  3. micmic3 says:

    問一下那個 mysql querys by day 的圖是怎麼產生的

  4. tzangms says:

    我是用 munin 來做的 http://munin.projects.linpro.no/

Leave a Reply

Partners of Oceanic / 人生海海

jiwosca