3月 122012
 

この前作ったvarnishlogを見やすくするツールですが
機能強化しました。

追加機能は

  • vcl_traceの値をVCLソースで表示(@perbuさんからのリクエスト)
  • バックエンドの状態を表示(@dai_yamashitaさんからのリクエスト)
  • です

    vcl_traceの値をVCLソースで表示

    今までvcl_traceの結果は味気ない表示で出していましたが。-fオプションでVCLファイルを指定することで実際のソースコードを表示するようにしました。
    [code=’plain’]
    | trace | vrt_count:1 vcl_line:55 vcl_pos:1
    [/code]
    ↓
    [code=’plain’]
    | trace | set req.http.X-TEST1=campur_xcir.gethash();
    | | ^ (vrt_count:1 vcl_line:55 vcl_pos:1 src_name:input)

    [/code]

    バックエンドの状態を表示

    バックエンドのヘルスチェックの状態を表示するようになりました。
    過去の履歴はとりあえずwindowの4倍です
    [code=’plain’]
    backend status
    ————————————————————

    name | status | past status
    default | healthy | YY
    [/code]

    起動オプション

    またこれらの機能を実現するために起動オプションが追加されました。

    -f [vcl file]

    VCLを指定します。これによりvcl_traceを解決できます。

    -e [varnishd]

    varnishdを指定します。vcl_traceの解決に必要です。

    -cc_command [cc_command]

    varnishのcc_commandで共有ライブラリを使っている場合は指定してください。
    vcl_traceの解決がいらない場合は不要です。

    –(backend|action|variable) [on|off]

    それぞれの情報の表示のon/offができます。
    デフォルトは全てonです

    また機能的に安定しなくてONにはしてないのですが
    [code=’php’]
    define(‘experimental’ , false);
    [/code]
    を
    [code=’php’]
    define(‘experimental’ , true);
    [/code]
    にして
    起動時に–src=onと-f=[vclfile]と-e=[varnishd]を指定するとVCLファイルで実際に通った場所が表示されます([exec])
    [code=’plain’]
    ############################################################
    vcl trace
    [exec] /* “input”*/
    [exec] /*

    ~中略~

    [exec] sub vcl_recv {
    [exec] if (req.restarts == 0) {
    [exec] if (req.http.x-forwarded-for) {
    set req.http.X-Forwarded-For =
    req.http.X-Forwarded-For + “, ” + client.ip;
    [exec] } else {
    [exec] set req.http.X-Forwarded-For = client.ip;
    [exec] }
    [exec] }
    [exec] if (req.request != “GET” &&
    [exec] req.request != “HEAD” &&
    [exec] req.request != “PUT” &&
    [exec] req.request != “POST” &&

    ~後略~
    [/code]

    良かったら使ってみてください
    varnishlogTrans

    2月 092012
     

    Do you use a Varnish? I’ve been using.
    I think to using varnishlog for VCL debugging.

    For example, the output of the varnishlog that include ESI request.

    varnishlog(include ESI)

    [code=’plain’]
    13 BackendOpen b default 192.168.1.199 36011 192.168.1.199 81 ★Open backend here.
    13 TxRequest b GET
    13 TxURL b /test2.html
    13 TxProtocol b HTTP/1.1
    13 TxHeader b User-Agent: Wget/1.12 (linux-gnu)
    13 TxHeader b Accept: */*
    13 TxHeader b Host: 192.168.1.199:6081
    13 TxHeader b X-Varnish: 171551254
    13 TxHeader b Accept-Encoding: gzip
    13 RxProtocol b HTTP/1.1
    13 RxStatus b 200
    13 RxResponse b OK
    13 RxHeader b Date: Sat, 28 Jan 2012 05:05:59 GMT
    13 RxHeader b Server: Apache/2.2.15 (Scientific Linux)
    13 RxHeader b Last-Modified: Sat, 23 Jul 2011 08:09:05 GMT
    13 RxHeader b ETag: “5a28-51-4a8b8187f8177”
    13 RxHeader b Accept-Ranges: bytes
    13 RxHeader b Content-Length: 81
    13 RxHeader b Connection: close
    13 RxHeader b Content-Type: text/html; charset=UTF-8
    13 Fetch_Body b 4(length) cls 0 mklen 1
    13 Length b 81
    13 BackendClose b default ★Close backend here.
    13 BackendOpen b default 192.168.1.199 36012 192.168.1.199 81 ★Open backend for ESI request here.
    13 TxRequest b GET
    13 TxURL b /test3.html
    13 TxProtocol b HTTP/1.1
    13 TxHeader b User-Agent: Wget/1.12 (linux-gnu)
    13 TxHeader b Accept: */*
    13 TxHeader b Host: 192.168.1.199:6081
    13 TxHeader b X-Varnish: 171551254
    13 TxHeader b Accept-Encoding: gzip
    13 RxProtocol b HTTP/1.1
    13 RxStatus b 200
    13 RxResponse b OK
    13 RxHeader b Date: Sat, 28 Jan 2012 05:05:59 GMT
    13 RxHeader b Server: Apache/2.2.15 (Scientific Linux)
    13 RxHeader b Last-Modified: Sat, 23 Jul 2011 08:08:59 GMT
    13 RxHeader b ETag: “5a29-14-4a8b81829c835”
    13 RxHeader b Accept-Ranges: bytes
    13 RxHeader b Content-Length: 20
    13 RxHeader b Connection: close
    13 RxHeader b Content-Type: text/html; charset=UTF-8
    13 Fetch_Body b 4(length) cls 0 mklen 1
    13 Length b 20
    13 BackendClose b default ★Close backend here.
    12 SessionOpen c 192.168.1.199 55115 :6081
    12 ReqStart c 192.168.1.199 55115 171551254 ★Start Request (/test2.html)
    12 RxRequest c GET
    12 RxURL c /test2.html
    12 RxProtocol c HTTP/1.0
    12 RxHeader c User-Agent: Wget/1.12 (linux-gnu)
    12 RxHeader c Accept: */*
    12 RxHeader c Host: 192.168.1.199:6081
    12 RxHeader c Connection: Keep-Alive
    12 VCL_call c recv 1 7.1
    12 VCL_Log c a
    12 VCL_trace c 2 9.1
    12 VCL_Log c b
    12 VCL_trace c 3 11.1
    12 VCL_Log c a
    12 VCL_return c lookup
    12 VCL_call c hash 18 85.5
    12 Hash c /test2.html
    12 VCL_trace c 19 87.9
    12 Hash c 192.168.1.199:6081
    12 VCL_return c hash
    12 VCL_call c miss 22 99.5 fetch
    12 Backend c 13 default default ★Call backend.
    12 TTL c 171551254 RFC 120 -1 -1 1327727160 0 1327727159 0 0
    12 VCL_call c fetch 4 18.1 deliver
    12 ObjProtocol c HTTP/1.1
    12 ObjResponse c OK
    12 ObjHeader c Date: Sat, 28 Jan 2012 05:05:59 GMT
    12 ObjHeader c Server: Apache/2.2.15 (Scientific Linux)
    12 ObjHeader c Last-Modified: Sat, 23 Jul 2011 08:09:05 GMT
    12 ObjHeader c ETag: “5a28-51-4a8b8187f8177”
    12 ObjHeader c Content-Type: text/html; charset=UTF-8
    12 VCL_call c deliver 26 116.5 deliver
    12 TxProtocol c HTTP/1.1
    12 TxStatus c 200
    12 TxResponse c OK
    12 TxHeader c Server: Apache/2.2.15 (Scientific Linux)
    12 TxHeader c Last-Modified: Sat, 23 Jul 2011 08:09:05 GMT
    12 TxHeader c ETag: “5a28-51-4a8b8187f8177”
    12 TxHeader c Content-Type: text/html; charset=UTF-8
    12 TxHeader c Date: Sat, 28 Jan 2012 05:05:59 GMT
    12 TxHeader c X-Varnish: 171551254
    12 TxHeader c Age: 0
    12 TxHeader c Via: 1.1 varnish
    12 TxHeader c Connection: close
    12 VCL_call c recv 1 7.1 ★Start ESI log.
    12 VCL_Log c a
    12 VCL_trace c 2 9.1
    12 VCL_Log c b
    12 VCL_trace c 3 11.1
    12 VCL_Log c a
    12 VCL_return c lookup
    12 VCL_call c hash 18 85.5
    12 Hash c /test3.html
    12 VCL_trace c 19 87.9
    12 Hash c 192.168.1.199:6081
    12 VCL_return c hash
    12 VCL_call c miss 22 99.5 fetch
    12 Backend c 13 default default
    12 TTL c 171551254 RFC 120 -1 -1 1327727160 0 1327727159 0 0
    12 VCL_call c fetch 4 18.1 deliver
    12 ObjProtocol c HTTP/1.1
    12 ObjResponse c OK
    12 ObjHeader c Date: Sat, 28 Jan 2012 05:05:59 GMT
    12 ObjHeader c Server: Apache/2.2.15 (Scientific Linux)
    12 ObjHeader c Last-Modified: Sat, 23 Jul 2011 08:08:59 GMT
    12 ObjHeader c ETag: “5a29-14-4a8b81829c835”
    12 ObjHeader c Content-Type: text/html; charset=UTF-8
    12 VCL_call c deliver 26 116.5 deliver
    12 Length c 20
    12 ReqEnd c 171551254 1327727159.889132023 1327727159.890880346 -0.001736164 nan nan ★Request end.
    12 SessionClose c EOF mode
    12 StatSess c 192.168.1.199 55115 0 1 1 0 0 2 282 20
    0 CLI – Rd ping
    0 CLI – Wr 200 19 PONG 1327727160 1.0
    [/code]

    little too difficult for me.
    Therefore, I tried to make a tool to format and display.
    Continue reading »

    2月 052012
     

    Varnish redirect is pain.

    [code=’plain’]
    sub vcl_recv {
    if (req.http.user-agent ~ “iP(hone|od)”) {
    error 750 “Moved Temporarily”;
    }
    }

    sub vcl_error {
    if (obj.status == 750) {
    set obj.http.Location = “http://www.example.com/iphoneversion/”;
    set obj.status = 302;
    return(deliver);
    }
    }
    [/code]
    (via:Redirecting using VCL)
    I just want to redirect. but should write code in two action.
    This is it lack of maintenance, and I do not like.
    I tried to make a vmod_redirect can be easily redirect.
    Continue reading »

    2月 052012
     

    Varnishでリダイレクトを行うのは結構めんどくさいです。
    たとえばuser-agentにiphoneかipodを含む場合にそれ用のページにリダイレクトする場合は以下のようになります
    [code=’plain’]
    sub vcl_recv {
    if (req.http.user-agent ~ “iP(hone|od)”) {
    error 750 “Moved Temporarily”;
    }
    }

    sub vcl_error {
    if (obj.status == 750) {
    set obj.http.Location = “http://www.example.com/iphoneversion/”;
    set obj.status = 302;
    return(deliver);
    }
    }
    [/code]
    (via:Redirecting using VCL)

    ただリダイレクトしたいだけなのに二箇所のアクションでコードを書かなくてはいけません。
    これは保守性に欠けると思いますし個人的にあまり好みではありません。

    そこで簡単にリダイレクトができるvmod_redirectを作って見ました。
    Continue reading »

    10月 022011
     

    バリバリチューニングしてパフォーマンスあげようぜ!というイベント
    チューニンガソン2に行って来ました。
    今回はn0tsさんとペアで参加してきました。(n0tsさんの記事はこちら)
    結果は9位と何とか10位以内に入りとても嬉しかった反面、
    幾つか遣り残したことあってもうちょい時間があれば!というのもありました。

    時系列的にこんなことやってました
    速度はメモってないのでアレですが・・・
    Continue reading »

     Posted by at 3:52 PM
    9月 122011
     

    夏コミで同人誌でだしたVarnishCache入門ですがPDFで公開します。

    幾つか公開したかった理由はあったのですが、実際コミケまで足を運んで買っていただいた方にちょっと申し訳ないかなと
    電子出版での有料配布も考えていたのですが
    64P程度で大げさかなというのと、もう一ヶ月経って3.0.1も出たしいいかなと思い公開します。
    Continue reading »