Slide 1

Slide 1 text

PSR-6 & Symfony Cache de la perf en standard #PHPTour @nicolasgrekas joind.in/17700

Slide 2

Slide 2 text

@nicolasgrekas #PHPTour

Slide 3

Slide 3 text

#PHPTour joind.in/17700 @nicolasgrekas

Slide 4

Slide 4 text

#PHPTour joind.in/17700 @nicolasgrekas

Slide 5

Slide 5 text

#PHPTour joind.in/17700 @nicolasgrekas

Slide 6

Slide 6 text

PSR-6 Caching Interface Draft: Sept. 2013 Final: Dec. 2015

Slide 7

Slide 7 text

#PHPTour joind.in/17700 @nicolasgrekas • A common interface for basic and intermediate-level caching needs. • Allow for multiple independent extensions without collision. PSR-6 Goals

Slide 8

Slide 8 text

#PHPTour joind.in/17700 @nicolasgrekas • Architectural compatibility with all existing cache implementations. • Advanced caching features such as namespacing or tagging. PSR-6 Non-Goals

Slide 9

Slide 9 text

#PHPTour joind.in/17700 @nicolasgrekas • doctrine/cache 16.8M • sonata-project/cache 1.3M • zendframework/zend-cache 1.1M • illuminate/cache 0.5M • tedivm/stash 0.4M PSR-6 Prior-art on Packagist

Slide 10

Slide 10 text

#PHPTour joind.in/17700 @nicolasgrekas PSR-6 Concerns

Slide 11

Slide 11 text

#PHPTour joind.in/17700 @nicolasgrekas • Crippled with “Bylaws” • Not always representative • Strategic hijacking • Way too much noise/overhead • Mission is unclear PHP-FIG Weaknesses

Slide 12

Slide 12 text

PHP-FIG Strength Standards! Let’s do with!

Slide 13

Slide 13 text

#PHPTour joind.in/17700 @nicolasgrekas PSR-6 Example #1

Slide 14

Slide 14 text

#PHPTour joind.in/17700 @nicolasgrekas PSR-6 Example #2

Slide 15

Slide 15 text

#PHPTour joind.in/17700 @nicolasgrekas PSR-6 CacheItemPoolInterface

Slide 16

Slide 16 text

#PHPTour joind.in/17700 @nicolasgrekas PSR-6 CacheItemInterface

Slide 17

Slide 17 text

#PHPTour joind.in/17700 @nicolasgrekas • CacheItemInterface instances are not interoperable • Restricted characters for keys • false as error reporting • No atomicity/transactionality PSR-6 Edge-cases

Slide 18

Slide 18 text

#PHPTour joind.in/17700 @nicolasgrekas • See on Packagist https://packagist.org/providers/psr/cache-implementation • Stash PHP – stashphp.com • PHP Cache – php-cache.com • and … PSR-6 Implementations

Slide 19

Slide 19 text

Welcome Symfony Cache

Slide 20

Slide 20 text

#PHPTour joind.in/17700 @nicolasgrekas • Be the most powerful PHP caching library • A strict PSR-6 implementation • Following Symfony’s quality processes* • Just the bare minimum to be fast by default * Thanks "cache/integration-tests"! Symfony Cache Goals

Slide 21

Slide 21 text

#PHPTour joind.in/17700 @nicolasgrekas • ApcuAdapter • ArrayAdapter • FilesystemAdapter • RedisAdapter • It’s up to you to add more Base Symfony Cache Adapters

Slide 22

Slide 22 text

#PHPTour joind.in/17700 @nicolasgrekas • AbstractAdapter • ChainAdapter • DoctrineAdapter • ProxyAdapter Special Symfony Cache Adapters

Slide 23

Slide 23 text

#PHPTour joind.in/17700 @nicolasgrekas Symfony Cache CacheItem

Slide 24

Slide 24 text

#PHPTour joind.in/17700 @nicolasgrekas Symfony Cache AbstractAdapter

Slide 25

Slide 25 text

#PHPTour joind.in/17700 @nicolasgrekas Doctrine 834.863 items/ms PHP Cache 313.334 items/ms Stash PHP 55.346 items/ms Symfony 533.366 items/ms Bench Symfony Cache

Slide 26

Slide 26 text

#PHPTour joind.in/17700 @nicolasgrekas Doctrine 705.999 items/ms PHP Cache 362.477 items/ms Stash PHP 153.803 items/ms Symfony 845.910 items/ms Bench Symfony Cache

Slide 27

Slide 27 text

Symfony Framework Wiring

Slide 28

Slide 28 text

#PHPTour joind.in/17700 @nicolasgrekas Symfony Framework Concepts Front 1 - APCu Front 2 - APCu Redis Pool 1: Annotations Pool 2: Validation Pool 3: SQL results Pool 4: API responses

Slide 29

Slide 29 text

#PHPTour joind.in/17700 @nicolasgrekas • Two core cache pool services: o cache.app for you • Defaults to filesystem, change it to Redis o cache.system derived for Symfony • Defaults to APCu+filesystem chain Symfony Framework

Slide 30

Slide 30 text

#PHPTour joind.in/17700 @nicolasgrekas Symfony Framework Services

Slide 31

Slide 31 text

#PHPTour joind.in/17700 @nicolasgrekas Symfony Framework Config

Slide 32

Slide 32 text

#PHPTour joind.in/17700 @nicolasgrekas Symfony Framework Services

Slide 33

Slide 33 text

#PHPTour joind.in/17700 @nicolasgrekas Symfony Framework Services

Slide 34

Slide 34 text

#PHPTour joind.in/17700 @nicolasgrekas Symfony Framework Services

Slide 35

Slide 35 text

What’s next?

Slide 36

Slide 36 text

#PHPTour joind.in/17700 @nicolasgrekas • Cache warming-up o Regeneration Before Expiration o Desynchronized Cache Misses o Stampede Protection Beyond PSR-6

Slide 37

Slide 37 text

#PHPTour joind.in/17700 @nicolasgrekas • Cache invalidation o Hierarchy o Tagging Beyond PSR-6

Slide 38

Slide 38 text

#PHPTour joind.in/17700 @nicolasgrekas • Warm-up Validator, Serializer, etc. • $cache->invalidate($tags); • Serve stale items while refreshing? • Add a profiler panel with hits/misses? • Deprecate current way of caching • Borrow more ideas from Drupal? Symfony 3.2?

Slide 39

Slide 39 text

“There are only two hard things in Computer Science: cache invalidation and naming things.” -- Phil Karlton

Slide 40

Slide 40 text

Merci ! #PHPTour @nicolasgrekas joind.in/17700