2

Hello to serverfault users,

I would like to kindly ask someone to help me configure varnish for magento.

Using command: varnishtop -i TxHeader -I Cookie , following info show:

TxHeader Cookie: frontend=965b5...(*lots of numbers); adminhtml=3ae65...(*lots of numbers); EXTERNAL_NO_CACHE=1

"(*lots of numbers)" is just my adding to the info

How can I remove this cookies using Varnish VCL configuration to cache the page?

Thanks for any help in this case!, would be greatly appreciated!

Tomas

Tomas
  • 21
  • 1
  • 3

2 Answers2

1

According to the Varnish-cache documentation you can use something like this. I've use similiar setups on other sites and it works like a charm!

sub vcl_recv {
  if (req.http.cookie) {
    set req.http.cookie = ";" + req.http.cookie;
    set req.http.cookie = regsuball(req.http.cookie, "; +", ";");
    set req.http.cookie = regsuball(req.http.cookie, ";(frontend|adminhtml|EXTERNAL_NO_CACHE)=", "; \1=");
    set req.http.cookie = regsuball(req.http.cookie, ";[^ ][^;]*", "");
    set req.http.cookie = regsuball(req.http.cookie, "^[; ]+|[; ]+$", "");

    if (req.http.cookie == "") {
      remove req.http.cookie;
    }
  }
}
pkhamre
  • 6,120
  • 3
  • 17
  • 27
  • Thank you very much. I would try this setup and let you know! Your answer is greatly appreciated! – Tomas Mar 08 '12 at 11:40
  • if you simply want to remove the cookie entirely then the regsuball(...) is redundant, but please leave it in the answer as it's still a good vcl example for cookie modification if needed. – Oneiroi Mar 08 '12 at 12:30
  • I've tested this configuration and I can see now, that adminhtml cookie dissapears from TxHeader, but frontend cookie remains. Openning another browser and visiting the site as new user increases only cache_miss number in varnishstat. – Tomas Mar 08 '12 at 14:00
  • I can see now improved htirate ratio and pinging the site from pingdom is raising cache_hit numbers. Loading time is 1.5s in average. Do you think its a log time for magento? Should it be under 1 second? – Tomas Mar 08 '12 at 14:22
  • I am not sure with Magento, but on average I think 1.5s is a quite high loadtime. I'm glad the answer could get you further. – pkhamre Mar 09 '12 at 09:22
  • There is one problem I've mentioned and I can't understand. When I come to the site as new user, cache_miss numbers grow. When I reload the page with F5, cache_hit numbers grow instead. Then I try visiting the same page from another computer (I'm assuimg, that previous user laods varnish's cache), the problem is, cache_miss numbers are growing again. So it is like every time someone visits the site, nothing is cached and its reusing backend over and over again. Getting frustrated about this, loading time is always pretty high - in average 1.5-2 seconds. I also use APC and Memcached. – Tomas Mar 09 '12 at 12:07
  • Post your entire VCL? – pkhamre Mar 15 '12 at 11:32
  • Ok, I will post it in few hours. We installed also Memcached and APC and it's now in average 900-950ms. Do you think it's a decent loading time for user? Thank you! – Tomas Mar 19 '12 at 08:36
  • Pkharme this is my VCL > http://pastebin.com/wEpq5iHX .(We use two IPs - x and z, because of SSL for magento) – Tomas Mar 20 '12 at 09:31
1

It sounds awfully like your VCLs are wrong as your cache isn't consistent across multiple computers.

I'm not sure what VCLs you are using, but I would suggest reading this

http://www.sonassihosting.com/blog/magento-performance/magento-performance-optimization-with-varnish-cache-4/

There are working and tested VCLs for Magento 1.4 and Varnish 2 that provide the results you are looking there

Ben Lessani
  • 5,244
  • 17
  • 37
  • Thank you for your answer. Unfortunatelly, this code is outdated. New Varnish uses different code for its configuration file VCL. – Tomas Mar 13 '12 at 13:26
  • Correct, it is for Varnish 2.x - but is a known working configuration that we use on several extremely high traffic sites. – Ben Lessani Mar 13 '12 at 18:00
  • Thank you for an update. I use Magento 1.6.1.0 and Varnish 3.0.2. If you know some good working config for this set-up, please, let me know! ;) – Tomas Mar 15 '12 at 16:08
  • Well, we don't use Varnish 3 in production, as our Varnish 2 VCLs work extremely well. My suggestion would be not to use Varnish 3 unless a) you know how to write the VCLs accurately yourself, or b) you have an explicit reason to do so (eg. ESI) – Ben Lessani Mar 15 '12 at 17:13
  • Thank you for an explanation. We get it to work quite well now. We also installed APC and Memcached, and now it seems to load pretty well (it could be always better of course:)). Loading time is now in average 900-950ms. Do you think it's pretty good loading speed in average? Thank you! – Tomas Mar 19 '12 at 08:34
  • 900-950ms is not using Varnish. It should be nearer 10-20ms - see http://www.apart4u.co.uk/ or http://www.apart4u.co.uk/washer-dryer-spares.html – Ben Lessani Mar 19 '12 at 14:10
  • Thanks Sonassi for explanation. I visited the site and it's blazing fast! I used Pingdom to see some numbers and apart4u.co.uk gave me in average 600-700ms(Europe ping). Our site is showing 900-950ms. So I've assumed it is in average about 300ms slower, so I think our Varnish configuration functions quite well(Varnishstat shows lots of hits - hit/miss ratio is about 4:1). But I'm pretty sure that something is still misconfigured. We use Zopim live chat on our site, so maybe this can be the effect of slowerness(?!). Anyway this is my VCL in full > http://pastebin.com/wEpq5iHX .(We use two IPs) – Tomas Mar 20 '12 at 09:28