$30 off During Our Annual Pro Sale. View Details »

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. #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
  2. #PHPTour joind.in/17700 @nicolasgrekas • Architectural compatibility with all existing cache

    implementations. • Advanced caching features such as namespacing or tagging. PSR-6 Non-Goals
  3. #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
  4. #PHPTour joind.in/17700 @nicolasgrekas • Crippled with “Bylaws” • Not always

    representative • Strategic hijacking • Way too much noise/overhead • Mission is unclear PHP-FIG Weaknesses
  5. #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
  6. #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
  7. #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
  8. #PHPTour joind.in/17700 @nicolasgrekas • ApcuAdapter • ArrayAdapter • FilesystemAdapter •

    RedisAdapter • It’s up to you to add more Base Symfony Cache Adapters
  9. #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
  10. #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
  11. #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
  12. #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
  13. #PHPTour joind.in/17700 @nicolasgrekas • Cache warming-up o Regeneration Before Expiration

    o Desynchronized Cache Misses o Stampede Protection Beyond PSR-6
  14. #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?
  15. “There are only two hard things in Computer Science: cache

    invalidation and naming things.” -- Phil Karlton