1

I installed varnish on my centos server, but i did not get any more performance, my website loaded in 7 sec before installation it , and after installation it's still 7 sec,
what is the problem?

sub vcl_recv {

    remove req.http.X-Forwarded-For;
    set req.http.X-Forwarded-For = client.ip;

    if(req.http.cookie ~ "userID" || req.url ~ "^/administrator" || req.url ~ "^/component/banners" || req.request == "POST") {
        return (pass);
    }

    if(req.http.x-logged-in == "False" && req.request != "POST"){
        unset req.http.cookie;
    }

    if (req.http.Accept-Encoding) {
      if (req.url ~ "\.(jpg|jpeg|png|gif|gz|tgz|bz2|tbz|mp3|ogg|swf)$") {
        remove req.http.Accept-Encoding;
      } elsif (req.http.Accept-Encoding ~ "gzip") {
        set req.http.Accept-Encoding = "gzip";
      } elsif (req.http.Accept-Encoding ~ "deflate") {
        set req.http.Accept-Encoding = "deflate";
      } else {
        remove req.http.Accept-Encoding;
      }
    }

    if (req.url ~ "\.(js|css|jpg|jpeg|png|gif|gz|tgz|bz2|tbz|mp3|ogg|swf)$") {
        return (lookup);
    }

    if (req.backend.healthy) {
        set req.grace = 5m;
    } else {
        set req.grace = 1h;
    }

    return (lookup);
}

sub vcl_fetch {

    if(req.request != "POST" && beresp.http.x-logged-in == "False") {
        unset beresp.http.Set-Cookie;
    }

    set beresp.grace = 1h;

    if (beresp.status == 503 || beresp.status == 502 || beresp.status == 501 || beresp.status == 500) {
      set beresp.grace = 60s;
      return (restart);
    }

    unset beresp.http.etag;

    if(beresp.http.Cache-Control == "no-cache" || beresp.http.Cache-Control == ""){
        set beresp.http.Cache-Control = "max-age=300, public, must-revalidate";
    }

    set beresp.ttl = 5m;

    return (deliver);
}

and

NFILES=131072
MEMLOCK=82000
NPROCS="unlimited"
RELOAD_VCL=1
VARNISH_VCL_CONF=/etc/varnish/default.vcl
VARNISH_LISTEN_PORT=80
VARNISH_ADMIN_LISTEN_ADDRESS=127.0.0.1
VARNISH_ADMIN_LISTEN_PORT=6082
VARNISH_SECRET_FILE=/etc/varnish/secret
VARNISH_MIN_THREADS=50
VARNISH_MAX_THREADS=1000
VARNISH_THREAD_TIMEOUT=120
VARNISH_STORAGE_FILE=/var/lib/varnish/varnish_storage.bin
VARNISH_STORAGE_SIZE=1G
VARNISH_STORAGE="file,${VARNISH_STORAGE_FILE},${VARNISH_STORAGE_SIZE}"
VARNISH_TTL=120
DAEMON_OPTS="-a ${VARNISH_LISTEN_ADDRESS}:${VARNISH_LISTEN_PORT} \
             -f ${VARNISH_VCL_CONF} \
             -T ${VARNISH_ADMIN_LISTEN_ADDRESS}:${VARNISH_ADMIN_LISTEN_PORT} \
             -t ${VARNISH_TTL} \
             -w ${VARNISH_MIN_THREADS},${VARNISH_MAX_THREADS},${VARNISH_THREAD_TIMEOUT} \
             -u varnish -g varnish \
             -S ${VARNISH_SECRET_FILE} \
             -s ${VARNISH_STORAGE}"

1 Answer 1

1

Are your web pages using headers which indicate cacheable content?

https://stackoverflow.com/questions/9836281/http-headers-influencing-caching-tutorial-documentation#9836997

If the caching instructions in the headers don't allow the pages to be cached, then vanish fetches them from your web server every time, so the web server delay is still there.

Some pages will always need to be fetched from cache. If those pages take 7 seconds to create, you still have a problem.

EDIT:

I suspect your web app is not cache friendly, but the info isn't there in your question to be sure. I don't even really know if you've successfully diverted requests through varnish.

If there's not too much other traffic, then maybe capture some traffic to file with tcpdump, including both the request to varnish and varnish's request to the web server, and the responses, then use something like wireshark to look at all the request and response headers. Maybe you can get some log data from varnish also which might confirm what is and isn't a cache hit.

Go through that tutorial on http headers as necessary to understand what the headers do, and then ask a more specific question if it's still not clear why varnish isn't caching things you think it should.

1
  • so,what is the solution?
    – Chris
    Sep 25, 2014 at 5:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .