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.

6baa34bc1e5c347b1003f6abe8691de1?s=128

Nicolas Grekas

May 24, 2016
Tweet

Transcript

  1. PSR-6 & Symfony Cache de la perf en standard #PHPTour

    @nicolasgrekas joind.in/17700
  2. @nicolasgrekas #PHPTour

  3. #PHPTour joind.in/17700 @nicolasgrekas

  4. #PHPTour joind.in/17700 @nicolasgrekas

  5. #PHPTour joind.in/17700 @nicolasgrekas

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

  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
  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
  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
  10. #PHPTour joind.in/17700 @nicolasgrekas PSR-6 Concerns

  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
  12. PHP-FIG Strength Standards! Let’s do with!

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

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

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

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

  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
  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
  19. Welcome Symfony Cache

  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
  21. #PHPTour joind.in/17700 @nicolasgrekas • ApcuAdapter • ArrayAdapter • FilesystemAdapter •

    RedisAdapter • It’s up to you to add more Base Symfony Cache Adapters
  22. #PHPTour joind.in/17700 @nicolasgrekas • AbstractAdapter • ChainAdapter • DoctrineAdapter •

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

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

  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
  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
  27. Symfony Framework Wiring

  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
  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
  30. #PHPTour joind.in/17700 @nicolasgrekas Symfony Framework Services

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

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

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

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

  35. What’s next?

  36. #PHPTour joind.in/17700 @nicolasgrekas • Cache warming-up o Regeneration Before Expiration

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

    Beyond PSR-6
  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?
  39. “There are only two hard things in Computer Science: cache

    invalidation and naming things.” -- Phil Karlton
  40. Merci ! #PHPTour @nicolasgrekas joind.in/17700