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

PSR-6 & Symfony Cache: fast by standards

6baa34bc1e5c347b1003f6abe8691de1?s=47 Nicolas Grekas
September 16, 2016

PSR-6 & Symfony Cache: fast by standards

After several months of discussion, the PHP-FIG (PHP Framework Interop Group) published the PSR-6. Its goal is to enable interoperability between caching systems implementations - a mandatory aspect to improve performance in your applications. At this conference, we will see the benefits and limitations of PSR-6, we will discuss the various existing cache solutions (Doctrine, Stash, php-cache), and I will present the new Symfony 3.1 Cache component and its upcoming improvements in version 3.2.

6baa34bc1e5c347b1003f6abe8691de1?s=128

Nicolas Grekas

September 16, 2016
Tweet

More Decks by Nicolas Grekas

Other Decks in Technology

Transcript

  1. PSR-6 & Symfony Cache fast by standards #Symfony_Live @nicolasgrekas

  2. @nicolasgrekas # Symfony_Live

  3. #Symfony_Live @nicolasgrekas

  4. #Symfony_Live @nicolasgrekas

  5. #Symfony_Live @nicolasgrekas

  6. “There are only two hard things in Computer Science: -

    cache invalidation - and naming things.” -- Phil Karlton
  7. PSR-6 Caching Interface Draft: Sept. 2013 Final: Dec. 2015

  8. #Symfony_Live @nicolasgrekas • A common interface for basic and intermediate-level

    caching needs. • Allow for multiple independent extensions without collision. PSR-6 Goals
  9. #Symfony_Live @nicolasgrekas • Architectural compatibility with all existing cache implementations.

    • Advanced caching features such as namespacing or tagging. PSR-6 Non-Goals
  10. #Symfony_Live @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
  11. #Symfony_Live @nicolasgrekas PSR-6 Concerns

  12. #Symfony_Live @nicolasgrekas • Crippled with “Bylaws” • Not always representative

    • Strategic hijacking • Way too much noise/overhead • Mission is unclear PHP-FIG Weaknesses
  13. PHP-FIG Strength Standards! Let’s do with!

  14. #Symfony_Live @nicolasgrekas PSR-6 CacheItemPoolInterface

  15. #Symfony_Live @nicolasgrekas PSR-6 CacheItemInterface

  16. #Symfony_Live @nicolasgrekas PSR-6 Example #1

  17. #Symfony_Live @nicolasgrekas PSR-6 Example #2

  18. #Symfony_Live @nicolasgrekas • CacheItemInterface instances are not interoperable • Restricted

    characters for keys • false as error reporting • No atomicity/transactionality • Lazyness is unspecified PSR-6 Edge-cases
  19. #Symfony_Live @nicolasgrekas • See on Packagist https://packagist.org/providers/psr/cache-implementation • Stash PHP

    – stashphp.com • PHP Cache – php-cache.com • and … PSR-6 Implementations
  20. Welcome Symfony Cache

  21. #Symfony_Live @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 in 3.1
  22. #Symfony_Live @nicolasgrekas • ApcuAdapter • ArrayAdapter • FilesystemAdapter • RedisAdapter

    • …it’s up to you to add more Base Symfony Cache Adapters
  23. #Symfony_Live @nicolasgrekas • AbstractAdapter • ChainAdapter • DoctrineAdapter • ProxyAdapter

    • + DoctrineProvider Special Symfony Cache Adapters
  24. #Symfony_Live @nicolasgrekas Symfony Cache CacheItem

  25. #Symfony_Live @nicolasgrekas Symfony Cache AbstractAdapter

  26. #Symfony_Live @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
  27. #Symfony_Live @nicolasgrekas Doctrine 705.001 items/ms PHP Cache 362.477 items/ms Stash

    PHP 153.803 items/ms Symfony 845.910 items/ms Bench Symfony Cache
  28. Symfony Framework Wiring

  29. #Symfony_Live @nicolasgrekas Symfony Framework Concepts Front 1 - APCu Front

    2 - APCu Redis Pool 1: Code Annotations Pool 2: Validation Pool 3: SQL results Pool 4: API responses
  30. #Symfony_Live @nicolasgrekas • « cache.app » for model sourced items

    o Defaults to filesystem, change it to Redis • « cache.system » for code sourced items o Defaults to APCu+filesystem chain Symfony Framework Services
  31. #Symfony_Live @nicolasgrekas Symfony Framework Semantic Config

  32. #Symfony_Live @nicolasgrekas Symfony Framework Semantic Config

  33. #Symfony_Live @nicolasgrekas Symfony Bundle Config

  34. #Symfony_Live @nicolasgrekas Wrap Symfony Cache as Doctrine Providers

  35. What’s next?

  36. #Symfony_Live @nicolasgrekas • Cache warming-up o Regeneration Before Expiration o

    Desynchronized Cache Misses o Stampede Protection Beyond PSR-6
  37. #Symfony_Live @nicolasgrekas • Cache invalidation o Hierarchy? o Tagging? Beyond

    PSR-6
  38. #Symfony_Live @nicolasgrekas • New adapter: PDO/DBAL, PHP array/file, Null •

    Tags based invalidation o $cache->invalidateTags($tags); • Hierarchical invalidation o $cache->withContext($contextChecksum); • cache:pool:clear command • Warm-up Validator, Serializer, etc. • Deprecate per components *CacheInterface Symfony 3.2
  39. #Symfony_Live @nicolasgrekas • Serve stale items while refreshing? • Desynchronized

    Cache Misses? • Add a profiler panel with hits/misses? • …add your ideas here Symfony 3.3?
  40. Merci ! #Symfony_Live @nicolasgrekas