Forums / Developer / eZ Publish 4 performance & Varnish

eZ Publish 4 performance & Varnish

Author Message

Pablo Pernot

Tuesday 31 March 2009 8:19:39 am

Hi,

I'm using ez 4.0.3 and I'm NOT using ezvlogin
BUT

I added to the index.php


// added rev. 21377 from nextgen: trunk/index.php

        $currentUser = eZUser::currentUser();
        $ini = eZINI::instance();
        $wwwDir = eZSys::wwwDir();
        // On host based site accesses this can be empty, causing the cookie to be set
        //for the current dir,
        // but we want it to be set for the whole eZ publish site
        $cookiePath = $wwwDir != '' ? $wwwDir : '/';

        if ( $currentUser->isLoggedIn() )
        {
             setcookie( 'is_logged_in', 'true', 0, $cookiePath );
             header( 'Etag: ' . $currentUser->attribute( 'contentobject_id' ) );
        }
        else
        {
             setcookie( 'is_logged_in', false, 0, $cookiePath );
        }
// END rev. 21377.


thanks for the help

Pablo Pernot
http://www.smartview.fr
http://www.areyouagile.com

Pablo Pernot

Tuesday 31 March 2009 8:29:54 am

If I put an ugly :

var_dump( $currentUser->isLoggedIn()); 

I noticed I'm first connected (return true) then I redirected to the login page.
Somewhere I lose the connected state.

I also get 2 warnings about session :

session_module_name() [<a href='function.session-module-name'>function.session-module-name</a>]: A session is active. You cannot change the session module's ini settings at this time. in /********/lib/ezutils/classes/ezsession.php on line 319

A session had already been started - ignoring session_start() in /********/lib/ezutils/classes/ezsession.php on line 372

Pablo Pernot
http://www.smartview.fr
http://www.areyouagile.com

Pablo Pernot

Tuesday 31 March 2009 9:39:45 am

Gosh... I get it.

session was at auto-start in php.ini.....

Pablo Pernot
http://www.smartview.fr
http://www.areyouagile.com

Ivo Lukac

Wednesday 13 May 2009 7:03:34 am

Hello everyone,

Just want to share some things which we discovered. We have a web with nice number of visitor so we plan to use varnish for better performance. Problem is that this web has also non-anonymous users. We want to make varnish cache anonymous only. For testing purposes first we upgrade it to eZ 4.1.1 and compiled varnish 2 from source.
Then we configured everything following:
http://ez.no/developer/contribs/documentation/varnish_and_ez_publish_setup_guide

First tests showed that using varnish is much faster of course. On very old and bad PC with virtual ubuntu machine we had about 300 trans/sec (siege test).
Also we verified that 'is_logged_in' cookie introduced in eZ 4.1 functions well with varnish configuration.

Problem was that this setup was not functioning well from the client side: after user logs in client web browser starts to cache (it receives cache and max-age headers ) and then if the user logs out browser is showing that cached pages (with user details).
We considered several solutions:
- to make user details with ajax (to much work),
- to rewrite cache headers for client in varnish (to difficult, we are varnish beginners),
- to use s-maxage header (didn't find any information about how varnish support this),
but none of them was optimal.

So we finally found rather easy solution:
- on eZ side we disabled all custom headers and use default (let varnish do everything and client will receive no-cache headers)
- in varnish configuration we changed order of execution in vcl_fetch like this:

sub vcl_fetch {
        # default time to live for cache objects
        set obj.ttl = 300s;
        if (obj.http.Set-Cookie ~ "is_logged_in=deleted(.*)") {
                deliver;
        }
        if (obj.http.Set-Cookie) {
                pass;
        }
        if (req.request == "GET" && req.url ~ "\.(css|js|gif|jpg|jpeg|bmp|png|ico|wmf|svg|swf|ico|mov|avi|wmv)$") {
                set obj.ttl = 600s;
                deliver;
        }
        if (!obj.cacheable) {
                pass;
        }
        deliver;
}

So noncacheable objects are passed but only after we cache anonymous pages and css, js and multimedia stuff.

We will test this more, but for now it seems to work very nice.

Cheers

http://www.linkedin.com/in/ivolukac
http://www.netgen.hr/eng/blog
http://twitter.com/ilukac

André R.

Wednesday 13 May 2009 7:44:06 am

You can also test using the OnlyForAnonymous setting for http headers, it was introduced in 4.0.2.

[HTTPHeaderSettings]
OnlyForAnonymous=enabled

Logged in users will get default headers instead when this is enabled.

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

Ivo Lukac

Wednesday 13 May 2009 10:07:10 am

Khm khm :)

Andre, thanks, I will check it out.
Could be that this is exactly what we need, didn't see that setting before.

http://www.linkedin.com/in/ivolukac
http://www.netgen.hr/eng/blog
http://twitter.com/ilukac