ez unconference - z publish top-performance through mastery (and extension) of the cache layers

Post on 05-Dec-2014

43.844 Views

Category:

Technology

2 Downloads

Preview:

Click to see full reader

DESCRIPTION

 

TRANSCRIPT

222 Rond point Ernest GarnierImmeuble Arche Jacques Cœur

34000 Montpellier04 99 13 68 60

EZ PUBLISH TOP-PERFORMANCETHROUGH MASTERY (AND EXTENSION) OF THE CACHE LAYERS

23/10/2012

1 KALIOP.COM

eZ UnConference. Oct 2012

Gilles GuirandCTO KaliopeZ Publish board member@gandbox

Gilles Ballinilead engineer Kaliop

AGENDA

AGENDA

Context

CACHE-BLOCK concepts & Issues

HOWTO build the perfect pagelayout :

0 SQL query (home) / 1 SQL query (others) never more than 100 template-block files ! save millions of SQL queries save I/O & Gigabytes of storage … save the eZ Publish reputation

2

222 Rond point Ernest GarnierImmeuble Arche Jacques Cœur

34000 Montpellier04 99 13 68 60

CONTEXT

23/10/2012

3 KALIOP.COM

eZ UnConference. Oct 2012

CONTEXT

Sometimes…

EZ Publish produce 30 Gbytes of template-block files

EZ Publish never stop to increase the number of cache files

EZ Publish produce millions of SQL queries per day

EZ Publish crash on cache expiry events (subtree expiry)

EZ Publish crash the hosting (beginning of the war!)

4

CONTEXT

& Sometimes... the end customer ask

Is it an eZ Publish kernel issue OR a lack of knowledge from the developers team ?

Is it so difficult to manage the eZ Publish cache system ?

All crashes seems to be related to that

Because the GAP between eZ4 & eZ5, is it not the time to evaluate new CMS competitors ?

5

CONTEXT

& most of times... a very huge optimization is possible in a quick time, to avoid all theses issues & crashes

especially with the viewcache & the cache-block settings

6

222 Rond point Ernest GarnierImmeuble Arche Jacques Cœur

34000 Montpellier04 99 13 68 60

CACHE-BLOCK CONCEPTS & ISSUES

23/10/2012

7 KALIOP.COM

eZ UnConference. Oct 2012

CACHE-BLOCK

What for ?

8

Template-block cache = cache files related to cache-block, also called « template cache » ( common mistake with the template compilation )

Template-block cache is an HTML (or other) cache of a template part ( cache-block

← Illustration : Łukasz Serwatkahttp://share.ez.no/learn/ez-publish/ez-publish-performance-optimization-part-3-of-3-practical-cache-and-template-solutions/(page)/2

CACHE-BLOCK

Main parameters

9

KEY value

(none)

Custom value, array

module_result.uri+Others ( users, extra )

Expiry rules

(none) → 2 hoursexpiry=3600

(none) → on content updateignore_content_expiry

subtree_expiry=123subtree_expiry=/news

CACHE-BLOCK

Most of time, a pagelayout looks like that (ezdemo exemple) :

{cache-block keys=array( $module_result.uri, $basket_is_empty, $current_user.contentobject_id ,

$extra_cache_key )}

<!-- HEAD / HEADER -->

{cache-block keys=array( $module_result.uri, $user_hash, $extra_cache_key )}

<!-- TOP MENU -->

{/cache-block}

{/cache-block}

{$module_result.content}

{cache-block keys=array( $module_result.uri, $user_hash, $access_type.name, $extra_cache_key )}

<!-- FOOTER -->

{/cache-block}

10

CACHE-BLOCK

Impact of common parameters

The « URI key » parameter : stupid but signifiant simulation

{cache-block keys=array( $module_result.uri, $user_hash, $extra_cache_key )}<!-- TOP MENU -->{/cache-block}

A classic Web site, with 1000 nodes, news folder ( year, month archives ), products catalog ( filters ), calendar, forum, 2 siteaccess...

Could generate 10 000 « indexable » several URI ( google bot )

A cache-block ( only 1 URI key ) to cache the global menu, who is generating 300 SQL queries

No « expiry » or « ignore_content_expiry » parameters : so the cache-block expires every 2 hours (or on content publication)

11

CACHE-BLOCK

Impact of common parameters

The « URI key » parameter : stupid but signifiantsimulation

So... 300 SQL queries * 12 expiration per day * 10 000 URI = 36 millions of SQL queries per day...

So... 30 000 template-block files ( 3 cache-block )

12

CACHE-BLOCK

Easy to say... but how to avoid ?

The « keys » parameter :

Please AVOID :{cache-block keys=$uri_string}...{/cache-block}

Use instead :{cache-block ignore_content_expiry expiry=86400

keys=$my_custom_limited_range_key}...{/cache-block}

13

1 template-block file for each URI !!!

Only possible states of your content inside your block

CACHE-BLOCK

What is the main motivation for using an URI Key ?

easy for caching values which could be different for each URI ( title, metas, ezjscore script & css includes, breadcrumbs, main menu, right column... )

found exemple on ezwebin, ezdemo ( is it not the best code exemples ? )

working fine on my workstation, so move on

not my priority, because not visible, i have IE6/7/8/9/10 CSS issues to resolve first

14

CACHE-BLOCK

How eZ stores the template-block cache

15

CACHE-BLOCK

How eZ stores the template-block cache

16

222 Rond point Ernest GarnierImmeuble Arche Jacques Cœur

34000 Montpellier04 99 13 68 60

HOW TO BUILD THE PERFECT PAGELAYOUT

23/10/2012

17 KALIOP.COM

eZ UnConference. Oct 2012

PERFECT PAGELAYOUT

Which values I have to expose ?

18

PERFECT PAGELAYOUT

Which values I have to evaluate ?

19

PERFECT PAGELAYOUT

Is there an out of the box tool for that ?

20

PERFECT PAGELAYOUT

How ezpagedata works ?

21

PERFECT PAGELAYOUT

FULL view exemple : node/view/full.tpl

{* Title *}

{ezpagedata_set( 'title', $node.name|concat( ' - ', ezini( 'SiteSettings', 'SiteName', 'site.ini' ) ) )}

pagelayout.tpl

{* Title *}

{if is_set( ezpagedata().persistent_variable.title )}

<title>{ezpagedata().persistent_variable.title|wash}</title>

{else}

<title>{ezini( 'SiteSettings', 'SiteName', 'site.ini' )}</title>

{/if}

22

PERFECT PAGELAYOUT

FULL view exemple : node/view/full.tpl

{* metadata *}{ezpagedata_append( 'metadata',

hash( 'description', $my_page_description,‘keywords', $my_keywords ) )}

pagelayout.tpl

{* metadata *}{foreach ezpagedata().persistent_variable.metadata as $name =>$content}

<meta name="{$name|wash}" content="{$content|wash}" />{/foreach}

23

PERFECT PAGELAYOUT

FULL view exemple : node/view/full.tpl

{* Breadcrumbs *}{set-block variable=breadcrumbs}

{foreach $node.path as $subpath}...

{/foreach}...{/set-block}{ezpagedata_set( 'breadcrumbs', $breadcrumbs )}

Pagelayout.tpl{if is_set( ezpagedata().persistent_variable.breadcrumbs )}

<p>{ezpagedata().persistent_variable.breadcrumbs}</p>{/if}

24

PERFECT PAGELAYOUT

FULL view exemple : node/view/full.tpl

{* Javascript / CSS inclusion *}

{ezscript_require( array( 'myscript1.js', 'myscript2.js' ) )}

{ezcss_require( array( 'style.css' ) )}

No more ezpagedata() ?

No, ezjscore share the same persistent variables array,

and use variables names : 'css_files', 'js_files'

25

PERFECT PAGELAYOUT

FULL view exemple : node/view/full.tpl

{* Javascript / CSS inclusion *}

{ezcss_require( array( 'style.css', 'style2.css' ) )}

pagelayout.tpl

{def $css_cache_keys = persistent_cache_keys( ezpagedata(), 'css_files' )}

{cache-block keys=$css_cache_keys ignore_content_expiry

expiry=86400}

{ezcss_load( array( ezini( 'StylesheetSettings', ' FrontendCSSFileList','design.ini' ) ) )}

{/cache-block}

{undef $css_cache_keys}

26

PERFECT PAGELAYOUT

FULL view exemple : node/view/full.tpl

public static function persistent_cache_keys( $namedParameters )

{$pageData = $namedParameters['pagedata'];$cacheType = $namedParameters['type'];$keys = $pageData['persistent_variable'][$cacheType];if ( empty( $keys ) ){

$keys = array( 'nokey' );}$operatorValue = array_unique( $keys );sort( $operatorValue );return $operatorValue;

}

27

PERFECT PAGELAYOUT

Is possible to evaluate the key without a template operator ?

YES :keys=first_set( ezpagedata().persistent_variable.js_files,

array('0') )|unique()|asort()

But when a template code is not enough readable, istill prefer to read PHP

28

PERFECT PAGELAYOUT

Am i done ?

NO, use the same logical for the main menu :

FULL : Set your « current section » CSS value, et set a persistent_variable

Pagelayout : get back your persistent_variable & use it like a cache-block key Use the same logical for the right colunm, the footer or whatever which is more easy to evaluate inside the full view

29

PERFECT PAGELAYOUT

Am i done ?

Use the same logical for the right colunm, the footer or whatever which is more easy to evaluate inside the full view

30

222 Rond point Ernest GarnierImmeuble Arche Jacques Cœur

34000 Montpellier04 99 13 68 60

CONCLUSION

23/10/2012

31 KALIOP.COM

eZ UnConference. Oct 2012

CONCLUSION

Conclusion

Need cache-blocks only for css & jsembedding, main menu, right column, footer... and never need an URI key

32

CONCLUSION

Conclusion

0 SQL query (home) / 1 SQL query (others)

never more than 100 template-block files !

save millions of SQL queries ( on expiry )

save I/O & Gigabytes of storage

… save the eZ Publish reputation

33

top related