Jump to content

Recommended Posts

Bonjour la communauté Prestashop,

 

Je vous propose d'ouvrir un fil à propos de Varnish 4.0 qui est disponible depuis 1 mois.

Je l'utilise avec des sites Wordpress, Joomla et le système est parfaitement fonctionnel.

 

A l'époque de Prestashop 1.5 (avec Varnish 3) j'étais arrivé à quelque chose de satisfaisant.

Avec Prestashop 1.6, ce n'est pas le cas.

 

Je vous propose de publier au fil de l'eau mes avancés concernant les fichiers VCL

Bien entendu, si vous avez déjà obtenu des résultats, n'hésitez pas à publier vos éléments.

 

Je mettrai en ligne des premiers éléments dans la journée.

 

Cordialement

Jerome

 

Share this post


Link to post
Share on other sites

Hypothèse : environnement LAMP (php 5.3+ & Apache 2)

 

Installation sur une base UBUNTU SERVER

 

  1. curl http://repo.varnish-cache.org/debian/GPG-key.txt | sudo apt-key add -
  2. echo "deb http://repo.varnish-cache.org/ubuntu/ precise varnish-4.0" | sudo tee -a /etc/apt/sources.list
  3. sudo apt-get update
  4. sudo apt-get install varnish

Edit du fichier Varnish - indiquer le port 80 (http) et la quantité de RAM octroyée à Varnish

 

  1. vi /etc/default/varnish
  2. # Should we start varnishd at boot?  Set to "no" to disable.
    START=yes

    # Maximum number of open files (for ulimit -n)
    NFILES=131072

    # Maximum locked memory size (for ulimit -l)
    # Used for locking the shared memory log in memory.  If you increase log size,
    # you need to increase this number as well
    MEMLOCK=82000
    DAEMON_OPTS="-a *:80 \
                 -T localhost:6082 \
                 -f /etc/varnish/default.vcl \
                 -S /etc/varnish/secret \
                 -s malloc,512m"

Paramétrer APACHE en indiquant votre ip fixe

 

  1. vi /etc/apache2/ports.conf
  2. NameVirtualHost *:8080
    NameVirtualHost <indiquer votre adresseip>:8080
    Listen 8080
    Listen 443

-> option, selon les installations et les panels, il faut vous rendre encore dans /etc/apache2/conf.d et vérifier que les différents fichiers conf contiennent le bon port de redirection à savoir 8080

Exemple :

NameVirtualHost <indiquer votre adresse ip>:8080
Listen <indiquer votre adresse ip>:8080
NameVirtualHost <indiquer votre adresse ip>:8443
Listen <indiquer votre adresse ip>:8443
 

 

Redémarrer l'ensemble pour vérifier le bon fonctionnement des différentes couches :

  1. service apache2 restart
  2. service varnish restart

Share this post


Link to post
Share on other sites

Configuration de Varnish pour Prestashop 1.6

 

:wub:
Attention - version de test non totalement finalisée, mais chacun d'entre nous y met un peu du sien, cela pourra aboutir à quelque chose de stable !!! Faites des tests avec GTmetrix avant et après : vous verrez déjà l'effet booster en route !

 

Tout se passe dans le fichier default.vcl qui se trouve dans  /etc/varnish/default.vcl dont voici le contenu :

 

# Marker to tell the VCL compiler that this VCL has been adapted to the
# new 4.0 format.
vcl 4.0;

# Default backend definition. Set this to point to your content server.
backend default {
    .host = <indiquer votre adresse ip>;
    .port = "8082";
    .connect_timeout = 1s;
    .first_byte_timeout = 30s;
}

acl purge {
    "127.0.0.1";
    "localhost";
    "<indiquer votre adresse ip>";
}
sub vcl_recv {
        if (req.method == "PURGE") {
                if (!client.ip ~ purge) {
                        return(synth(405,"Not allowed."));
                }
                # jump to hit/miss
                return (purge);
        }
        # Handle IPv6
        if (req.http.Host ~ "^ipv6.*") {
            set req.http.host = regsub(req.http.host, "^ipv6\.(.*)","www\.\1");
        }

        if (req.restarts == 0) {
                if (req.http.x-forwarded-for) {
                        set req.http.X-Forwarded-For = req.http.X-Forwarded-For + ", " + client.ip;
                } else {
                        set req.http.X-Forwarded-For = client.ip;
                }
        }
        # remove double // in urls,
        set req.url = regsuball( req.url, "//", "/"      );
        # Properly handle different encoding types
        if (req.http.Accept-Encoding) {
                if (req.url ~ "\.(jpg|jpeg|png|gif|gz|tgz|bz2|tbz|mp3|ogg|swf)$") {
                # No point in compressing these
                        unset 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 {
                        # unkown algorithm
                        unset req.http.Accept-Encoding;
                }
        }

        # Compatiblity with Apache log
        unset req.http.X-Forwarded-For;
        set req.http.X-Forwarded-For = client.ip;
        # Remove has_js and Google Analytics __* cookies.
        if (req.http.cookie) {
         set req.http.Cookie = regsuball(req.http.Cookie, "(^|;\s*)(__[a-z]+|has_js)=[^;]*", "");
        # Remove a ";" prefix, if present.
         set req.http.Cookie = regsub(req.http.Cookie, "^;\s*", "");
        # Remove empty cookies.
         if (req.http.Cookie ~ "^\s*$") {
            unset req.http.Cookie;
         }
        }
 set req.backend_hint = default;

# default
if (req.restarts == 0) {
    if (req.http.x-forwarded-for) {
            set req.http.X-Forwarded-For = req.http.X-Forwarded-For + ", " + client.ip;
    } else {
            set req.http.X-Forwarded-For = client.ip;
    }
}
# pipe on weird http methods
if (req.method !~ "^GET|HEAD|PUT|POST|TRACE|OPTIONS|DELETE$") {
    return(pipe);
}
if (req.method == "GET" && (req.url ~ "^/?mylogout=")) {
    unset req.http.Cookie;
    return (pass);
}
#we should not cache any page for Prestashop backend
if (req.method == "GET" && (req.url ~ "^/admin")) {
    return (pass);
}
#we should not cache any page for customers
if (req.method == "GET" && (req.url ~ "^/authentification" || req.url ~ "^/my-account")) {
    return (pass);
}
#we should not cache any page for customers
if (req.method == "GET" && (req.url ~ "^/identity" || req.url ~ "^/my-account.php")) {
    return (pass);
}
#we should not cache any page for sales
if (req.method == "GET" && (req.url ~ "^/cart.php" || req.url ~ "^/order.php")) {
    return (pass);
}
#we should not cache any page for sales
if (req.method == "GET" && (req.url ~ "^/addresses.php" || req.url ~ "^/order-detail.php")) {
    return (pass);
}
#we should not cache any page for sales
if (req.method == "GET" && (req.url ~ "^/order-confirmation.php" || req.url ~ "^/order-return.php")) {
    return (pass);
}
if (req.method != "GET" && req.method != "HEAD") {
    return (pass);
}
# Do not cache POST request
if (req.method == "POST") {
    return (pipe);
}
# Ignore empty cookies
if (req.http.Cookie ~ "^\s*$") {
   unset req.http.Cookie;
}
set req.url = regsub(req.url, "\.js\?.*", ".js");
set req.url = regsub(req.url, "\.css\?.*", ".css");
set req.url = regsub(req.url, "\.jpg\?.*", ".jpg");
set req.url = regsub(req.url, "\.gif\?.*", ".gif");
set req.url = regsub(req.url, "\.swf\?.*", ".swf");
set req.url = regsub(req.url, "\.xml\?.*", ".xml");
if (req.url ~ "\.(js|css|jpg|jpeg|png|gif|gz|tgz|bz2|tbz|mp3|ogg|swf|pdf)$" && ! (req.url ~ "\.(php)") ) {
    unset req.http.Cookie;
    return (hash);
}
return (hash);
 

}

 

sub vcl_hash {
        hash_data(req.url);
        if (req.http.host) {
                hash_data(req.http.host);
        } else {
                hash_data(server.ip);
        }
        if (req.http.Cookie) {
                hash_data(req.http.Cookie);
        }
        # If the client supports compression, keep that in a different cache
        if (req.http.Accept-Encoding) {
          hash_data(req.http.Accept-Encoding);
        }
        return(lookup);
}
sub vcl_pass {
        set req.http.X-marker = "pass" ;
}

sub vcl_pipe {
    # Note that only the first request to the backend will have
    # X-Forwarded-For set. If you use X-Forwarded-For and want to
    # have it set for all requests, make sure to have:
    # set bereq.http.connection = "close";
    # here. It is not set by default as it might break some broken web
    # applications, like IIS with NTLM authentication.

    #set bereq.http.Connection = "Close";
    return (pipe);
}
sub vcl_backend_response {
        # Bypass cache for files > 10 MB
        if (std.integer(beresp.http.Content-Length, 0) > 10485760) {
                set beresp.uncacheable = true;
                set beresp.ttl = 120s;
                return (deliver);
        }
        if ( ! beresp.http.Content-Encoding ~ "gzip" ) {
                set beresp.do_gzip = true;
        }
        #unset beresp.http.expires;
        if (bereq.url ~ "\.(jpeg|jpg|png|gif|ico|swf|js|css|gz|rar|txt|bzip|pdf)$") {
                 unset beresp.http.set-cookie;
        }
        if (beresp.ttl > 0s ) {
                if (beresp.status >= 300 && beresp.status <= 399) {
                        set beresp.ttl = 10m;
                }
                if (beresp.status >= 399) {
                        set beresp.ttl = 0s;
                }
        }
        if (beresp.status >= 399) {
                unset beresp.http.set-cookie;
        }

        # Maximum 24h de cache
        if (beresp.ttl > 86400s) {
                set beresp.ttl = 86400s;
        }
        if (bereq.http.X-marker == "pass" ) {
                unset bereq.http.X-marker;
                set beresp.http.X-marker = "pass";
                set beresp.ttl = 0s ;
        }

# Only allow cookies to be set if we're in admin area
#if (beresp.http.Set-Cookie && bereq.url !~ "^/wp-(login|admin)") {
#      unset beresp.http.Set-Cookie;
#}
if (bereq.method == "GET" && (bereq.url ~ "^/?mylogout=")) {
    set beresp.ttl = 0s;
    unset beresp.http.Set-Cookie;
    set beresp.uncacheable = true;
    return(deliver);
}

# don't cache response to posted requests or those with basic auth
if ( bereq.method == "POST" || bereq.http.Authorization ) {
     set beresp.uncacheable = true;
     set beresp.ttl = 120s;
     return (deliver);
}
# don't cache search results
if ( bereq.url ~ "\?s=" ){
     set beresp.uncacheable = true;
     set beresp.ttl = 120s;
     return (deliver);
}
# only cache status ok
if ( beresp.status != 200 ) {
     set beresp.uncacheable = true;
     set beresp.ttl = 120s;
     return (deliver);
}
# no cache
if (beresp.http.X-No-Cache) {
    set beresp.uncacheable = true;
    set beresp.ttl = 120s;
    return (deliver);
}
set beresp.uncacheable = true;
return (deliver);
 

}
sub vcl_deliver {
        if (obj.hits > 0){
                set resp.http.X-Varnish-Cache = "HIT";
        } else {
                set resp.http.X-Varnish-Cache = "MISS";
        }
        if (resp.http.X-marker == "pass" ) {
                unset resp.http.X-marker;
                set resp.http.X-Varnish-Cache = "PASS";
        }
        unset resp.http.Via;
        unset resp.http.X-Whatever;
        unset resp.http.X-Powered-By;
        unset resp.http.X-Varnish;
        unset resp.http.Age;
        unset resp.http.Server;
        set resp.http.X-Frame-Options = "SAMEORIGIN";
        set resp.http.X-Xss-Protection = "1; mode=block";
}
sub vcl_synth {
        if (resp.status >= 500 && req.restarts < 4) {
                return (restart);
        }
}
             


Voila !

A vous de jouer !

Share this post


Link to post
Share on other sites
  • 2 weeks later...

Bonjour Jerome, 

 

Je viens de tester ton fichier de configuration sur un varnish4 et je n'ai malheureusement que des MISS ou des PASS.

 

Quels résultats obtiens-tu ?

 

Pour info, je suis sur un nginx + php-fpm. et presta 1.6.

 

Cordialement,

David.

Share this post


Link to post
Share on other sites

bonjour

cela dépends aussi de ton template et des modules que tu utilises

pour ma part, j'ai effectivement encore pas mal de MISS (les pass sont comme demandé présents quand je suis dans le backoffice ou connecté sur un compte utilisateur sur le frontoffice, ce qui est normal). j'ai cependant aussi des hit 

je travaille à l'amélioration des résultats mais les tests sont longs

l'idée est que chacun  apporte sa pierre à l'édifice afin que nous arrivions au final à une solution stable et performante

je travaille aussi à la propagation des bonnes adresses ip

Par contre j'ai finalisé mon chantier pour wordpress et c'est nickel

tu pourras toutefois remarquer que si tu testes ton site prestashop avec GTMETRIX que le niveau de perf général a toutefois bien progressé : pour ma part je suis passé à 95%

 

cordialement

Share this post


Link to post
Share on other sites
  • 2 months later...

Hello,

 

Can you share more info for your presta installation? How was the load time before vanish and how is it now? How many concurrent users do you serve and whats your server specs?

 

Thanks,

C

Share this post


Link to post
Share on other sites

Sorry to enter on a french conversation speaking english, but I think it's better for you then portuguese(my natural language).

 

It's great to know you are trying to make Prestashop work with Varnish. I'm interested in start testing it too.

 

Are all the Prestashop features working fine when running with Varnish or are you experiencing any kind of problems on your store?

 

I tested on a store with Prestashop 1.4.8.2 and it was not allowing to add more then one product to the cart. It kept creating always a new cart with every product. That's why I'm asking if it's working on PS 1.6.

 

Thanks,

Share this post


Link to post
Share on other sites
  • 2 weeks later...

Dear all,

 

My tests with Varnish 4.0.1 are not closed

 

i can't qualify prestashop having some troubles under varnish

Concerning some CMS like Joomla or Wordpress, all works fine

i don't know if the prestashop team works on the compatibilty with varnish but i'm coming back to you when i get a stable platform

 

JP

Share this post


Link to post
Share on other sites
  • 1 month later...

As tu réussit à configurer correctement varnish?

 

 

Sinon penses tu que même si le traffic n'est pas interessant le gain est non négligable ou seulement il interessant d'installer varnsih seulement pour les site à gros traffic?

Share this post


Link to post
Share on other sites
  • 2 months later...

Bonjour,

 

J'ai repris mes tests cette fois-ci avec la dernière version varnish 4.02 (64 bit car l'éditeur ne supporte plus le mode 32-bit)

Les bench AB montrent une croissance forte des capacités du VPS mais aussi les sites Wordpress, Joomla et Prestashop sont globalement plus rapides. c'est significatif

 

Toutefois, sacré Prestashop - autant pour Wordpress + 1 concurrent de PS (Wo...) nickel

Mais avec Prestashop, toujours des pb ...

 

Je ne désespère pas.

 

Si d'autres ont avancé sur les VCL, ce serait sympa de partager !

A vos plumes

 

J

Share this post


Link to post
Share on other sites
  • 4 months later...
  • 5 months later...
  • 4 years later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More