ivan chepurnyi - mm14nl

Post on 10-May-2015

154 Views

Category:

Software

0 Downloads

Preview:

Click to see full reader

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

Varnish Cache and its usage in the real world

Ivan ChepurnyiOwner

EcomDev BV

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

Ivan Chepurnyi Meet Magento

Varnish

is not a cache backend

Ivan Chepurnyi Meet Magento

Varnish

is a frontend caching proxy

Ivan Chepurnyi Meet Magento

Simple Workflow

First call to a page

Ivan Chepurnyi Meet Magento

Simple Workflow

Subsequent requests

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

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

Ivan Chepurnyi Meet Magento

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

store, etc?

YES!!!

Ivan Chepurnyi Meet Magento

The Secret is in

Cache Object structure

Ivan Chepurnyi Meet Magento

Cached Object in Varnish

Cached Object

Response Headers

Response Body

Cache Metadata

Cache Content

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.

Ivan Chepurnyi Meet Magento

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

YES!!!

Ivan Chepurnyi Meet Magento

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

Ivan Chepurnyi Meet Magento

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

benefits?

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

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!

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

Ivan Chepurnyi Meet Magento

Making an element dynamic on varnish cached page

Ivan Chepurnyi Meet Magento

Code Sample Dynamic Block

Ivan Chepurnyi Meet Magento

Adding custom TTL for a page

Ivan Chepurnyi Meet Magento

Code Sample Custom TTL

Ivan Chepurnyi Meet Magento

Making custom page cacheable

Ivan Chepurnyi Meet Magento

Code Sample Custom Page

Ivan Chepurnyi Meet Magento

Move blocks as a standalone cached page

(ESI).

Ivan Chepurnyi Meet Magento

Code Sample ESI

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

Ivan Chepurnyi Meet Magento

Conclusion

Be smart and use Varnish correctly!

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)

Ivan Chepurnyi Meet Magento

Thank You!

Questions?

top related