ivan chepurnyi - mm14nl

31
Varnish Cache and its usage in the real world Ivan Chepurnyi Owner EcomDev BV

Upload: dutchento

Post on 10-May-2015

154 views

Category:

Software


0 download

DESCRIPTION

Varnish Cache and its usage in the real world! In the modern era of e-commerce, it is quite obvious that web-shop revenue is strictly bound to its code performance. If you can satisfy customer withing 300ms of total page load time, you’ll get this sale. MorЕ over your web-shop will be more likely to get ranked higher in Google. During my presentation you will find the best practices in integration of Varnish cache into Magento webshop. Varnish, de-facto is the best front-cache available on the market, but most of the people don’t use it at its maximums! Enjoy my useful speech and find a lot of interesting things in Magento’s life!

TRANSCRIPT

Page 1: Ivan Chepurnyi - MM14NL

Varnish Cache and its usage in the real world

Ivan ChepurnyiOwner

EcomDev BV

Page 2: Ivan Chepurnyi - MM14NL

Ivan Chepurnyi Meet Magento

About me

• Technical Consultant, Owner at EcomDev B.V.

• Was one of the first five developers in original Magento core team

• Providing trainings and coaching of Magento Developers in Europe

• Main areas of my expertise:– System Architecture – Performance Optimization– Test Driven Development– Complex Customizations

Page 3: Ivan Chepurnyi - MM14NL

Ivan Chepurnyi Meet Magento

Varnish

is not a cache backend

Page 4: Ivan Chepurnyi - MM14NL

Ivan Chepurnyi Meet Magento

Varnish

is a frontend caching proxy

Page 5: Ivan Chepurnyi - MM14NL

Ivan Chepurnyi Meet Magento

Simple Workflow

First call to a page

Page 6: Ivan Chepurnyi - MM14NL

Ivan Chepurnyi Meet Magento

Simple Workflow

Subsequent requests

Page 7: Ivan Chepurnyi - MM14NL

Ivan Chepurnyi Meet Magento

How Varnish Works

recv

hit pass miss

hash pipe

deliver

fetch

• recv – request is received from client

• pipe – direct output of backend data (streaming)

• hash – request is cacheable, lookup cache entry

• pass – request is not cacheable

• hit – cache entry is found

• miss – cache entry not found

• fetch – retrieval of data from backend

• deliver – return data to client

Page 8: Ivan Chepurnyi - MM14NL

Ivan Chepurnyi Meet Magento

What can we do with it?

• Cache static pages (Homepage, CMS, Contacts, etc)

• Cache catalog pages:– Category listings– Product search results– Product view pages

• Cache page parts:– CMS Blocks– Header– Footer

Page 9: Ivan Chepurnyi - MM14NL

Ivan Chepurnyi Meet Magento

Is it possible to clear Varnish cache based on product, category,

store, etc?

YES!!!

Page 10: Ivan Chepurnyi - MM14NL

Ivan Chepurnyi Meet Magento

The Secret is in

Cache Object structure

Page 11: Ivan Chepurnyi - MM14NL

Ivan Chepurnyi Meet Magento

Cached Object in Varnish

Cached Object

Response Headers

Response Body

Cache Metadata

Cache Content

Page 12: Ivan Chepurnyi - MM14NL

Ivan Chepurnyi Meet Magento

We just going to supply object ID with its type in response headers, so it later

on can be used to flush pages containing our object.

Page 13: Ivan Chepurnyi - MM14NL

Ivan Chepurnyi Meet Magento

But is it possible to make cache lifetime dynamic for per product, category, etc?

YES!!!

Page 14: Ivan Chepurnyi - MM14NL

Ivan Chepurnyi Meet Magento

You can supply a response header, that contains a TTL of the page.

Page 15: Ivan Chepurnyi - MM14NL

Ivan Chepurnyi Meet Magento

So what should be done to implement Varnish in Magento with all the

benefits?

Page 16: Ivan Chepurnyi - MM14NL

Ivan Chepurnyi Meet Magento

Varnish in Magento

• Collect current page objects, that are shown on the page. Also add them into response headers.

• Create a connector to a Varnish admin protocol, that will be used for flushing of the page by object ids.

• Implement auto-updated AJAX blocks for:– Shopping cart– Wishlist– Customer Account links

Page 17: Ivan Chepurnyi - MM14NL

Ivan Chepurnyi Meet Magento

But I have a good news:

I alredy developed a module that gives you a solid foundation for using Varnish in your

project!

Page 18: Ivan Chepurnyi - MM14NL

Ivan Chepurnyi Meet Magento

EcomDev_Varnish

Download URL: http://bit.ly/ecomdev_varnish

Requires:• Varnish 3.0• Minimal changes to your theme

Supports:• Flush of cache on update of product, category, cms page, csm

block, price rules• Client side cacheable AJAX placeholders (Cart, Wishlist, etc)• Possibility to make cache based on customer segment • Cache for logged in users

Page 19: Ivan Chepurnyi - MM14NL

Ivan Chepurnyi Meet Magento

Making an element dynamic on varnish cached page

Page 20: Ivan Chepurnyi - MM14NL

Ivan Chepurnyi Meet Magento

Code Sample Dynamic Block

Page 21: Ivan Chepurnyi - MM14NL

Ivan Chepurnyi Meet Magento

Adding custom TTL for a page

Page 22: Ivan Chepurnyi - MM14NL

Ivan Chepurnyi Meet Magento

Code Sample Custom TTL

Page 23: Ivan Chepurnyi - MM14NL

Ivan Chepurnyi Meet Magento

Making custom page cacheable

Page 24: Ivan Chepurnyi - MM14NL

Ivan Chepurnyi Meet Magento

Code Sample Custom Page

Page 25: Ivan Chepurnyi - MM14NL

Ivan Chepurnyi Meet Magento

Move blocks as a standalone cached page

(ESI).

Page 26: Ivan Chepurnyi - MM14NL

Ivan Chepurnyi Meet Magento

Code Sample ESI

Page 27: Ivan Chepurnyi - MM14NL

Ivan Chepurnyi Meet Magento

Varnish vs Full Page Cache

Varnish

• Avg. time to first byte 30ms

• Dedicated software

• Tools to monitor cache usage

• Scalable

• Requires adaptation of themes for dynamic parts

• Possibility to flush group of pages

Magento FPC implementation

• Avg. time to first byte 300ms

• Magento code level

• N/A

• Only as another backend

• Most of the time it is not required

• N/A

Page 28: Ivan Chepurnyi - MM14NL

Ivan Chepurnyi Meet Magento

Conclusion

Be smart and use Varnish correctly!

Page 29: Ivan Chepurnyi - MM14NL

Ivan Chepurnyi Meet Magento

OpenSource Roadmap 2014

1. Finalize EcomDev_Varnish module and make it open source;

2. EcomDev_PHPUnit refactoring for API based fixtures;

3. Working on EcomDev_Index module, to provide alternative of standard indexation mechanism in Magento:– Flat Indexers (failover indexation)– UrlRewrites (full refactor of existing module)– Layered Navigation (Sphinx)– Better Search (Sphinx)

Page 30: Ivan Chepurnyi - MM14NL

Ivan Chepurnyi Meet Magento

Thank You!

Page 31: Ivan Chepurnyi - MM14NL

Questions?