Skip to content

VMOD overhead

Carlos Abalde edited this page Dec 23, 2015 · 6 revisions

VCL is a domain-specific language designed to define Varnish request handling and caching policies. VMODs are extensions useful to extend what you can do using VCL; for example, accessing to a key-value database like Redis. However, it's important to understand the implications of using a VMOD, specially how a VMOD can degrade the performance of your caching layer.

@davidfb and me crunched some numbers that may help you understand the impact of integrating queries to a Redis database in your VCL logic. Please, beware this is not a serious benchmark, but it's definitely something which your may want to consider.

Scenario

  • Ubuntu Trusty, Intel Core i3-3220 CPU @ 3.30GHz × 4 (64 bits), 7.5GB RAM.
  • Varnish Cache 4.0.3 (default configuration).
  • Redis 3.0.6 (single server & persistence disabled).
  • Redis VMOD 0.3.4 using private contexts.
  • Warming up + ab -n 100000 -c 1 http://192.168.4.104:6081/

Results (msec / HTTP req)

# cmds SET GET EVAL
0 0.636 0.636 0.636
1 0.686 0.675 0.725
2 0.725 0.722 0.809
4 0.783 0.780 0.898
8 0.984 0.976 1.187

VCL

vcl 4.0;

import redis;

backend default {
    .host = "127.0.0.1";
    .port = "80";
}

sub vcl_init {
    new db = redis.db("127.0.0.1:6379", 500, 0, 0, 0, false, 1, false, 0);
}

sub vcl_recv {
    return (synth(200, "OK"));
}

sub vcl_synth {
    if (req.url == "/stats") {
        synthetic(db.stats());
    } else {
        #db.command("SET");
        #db.push("foo");
        #db.push("Hello world!");
        #db.execute();
        #db.free();

        #db.command("GET");
        #db.push("foo");
        #db.execute();
        #db.free();

        #db.command("EVAL");
        #db.push({"
        #    redis.call('SET', KEYS[1], ARGV[1]);
        #    redis.call('EXPIRE', KEYS[1], ARGV[2]);
        #"});
        #db.push("1");
        #db.push("foo");
        #db.push(req.xid);
        #db.push("1");
        #db.execute();
        #db.free();

        synthetic("");
    }

    return (deliver);
}
Clone this wiki locally