Upgrade to Pro — share decks privately, control downloads, hide ads and more …

PSR-6 & Symfony Cache : de la perf en standard

PSR-6 & Symfony Cache : de la perf en standard

Après plusieurs mois de discussion, le PHP-FIG (PHP Framework Interop Group) a publié la PSR-6. Son objectif est de permettre l'interopérabilité entre implémentations de systèmes de mise en cache - un aspect indispensable pour gagner en performance dans votre application. Lors de cette conférence, nous verrons les avantages et les limites de PSR-6, nous discuterons des différentes solutions de cache existantes (Doctrine, Stash, php-cache), et je vous présenterai le nouveau composant Symfony Cache.

Nicolas Grekas

May 24, 2016
Tweet

More Decks by Nicolas Grekas

Other Decks in Programming

Transcript

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

    View Slide

  2. @nicolasgrekas
    #PHPTour

    View Slide

  3. #PHPTour joind.in/17700 @nicolasgrekas

    View Slide

  4. #PHPTour joind.in/17700 @nicolasgrekas

    View Slide

  5. #PHPTour joind.in/17700 @nicolasgrekas

    View Slide

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

    View Slide

  7. #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

    View Slide

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

    View Slide

  9. #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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  17. #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

    View Slide

  18. #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

    View Slide

  19. Welcome
    Symfony Cache

    View Slide

  20. #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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  25. #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

    View Slide

  26. #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

    View Slide

  27. Symfony
    Framework
    Wiring

    View Slide

  28. #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

    View Slide

  29. #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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  35. What’s next?

    View Slide

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

    View Slide

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

    View Slide

  38. #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?

    View Slide

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

    View Slide

  40. Merci ! #PHPTour
    @nicolasgrekas
    joind.in/17700

    View Slide