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

Zend Cache - Evolution

Dd3f18c87b851137000c7427d7bd5d32?s=47 fwdays
November 24, 2012

Zend Cache - Evolution

В докладе я расскажу о своем опыте оптимизации “тяжелых” e-commerce проектов написанных на платформе Magento. В ходе доклада мы рассмотрим, практики и стратегии кэширования такие как:
— Точечное кэширование
— “Клонирование” приложения и генерация статического контента
— Кэширование вместо оптимизации
— Автоматическая генерация кэшей и др.
Немного остановимся на рассмотрении TwoLevels Cache в Zend 1 и математических моделях кэширования (LRU, LFU, LRU2, MRU).
Попробуем подобрать адекватное хранилище для кеша. Посмотрим чем нам может помочь cобытийно-ориентированная архитектура поддерживать валидность кэша.
И сравним Zend\Cache 2.0 с Zend_Cache 1.0.

Dd3f18c87b851137000c7427d7bd5d32?s=128

fwdays

November 24, 2012
Tweet

More Decks by fwdays

Other Decks in Programming

Transcript

  1. Zend Cache - Evolution Владимир Дубина

  2. За кадром 5 years PHP, 2 years Team Lead

  3. Optimization: general patterns Make it Work Make it Right Make

    it Fast Kent Beck
  4. Optimization: general patterns Make it Work Make it Right Small

    Make it Fast
  5. Optimization: general patterns Make it Work Make it Right Make

    it Fast Kent Beck
  6. Optimization: general patterns Make it Work Make it Right Make

    it Fast
  7. Optimization: general patterns Make it Work Make it Fast

  8. Optimization: general patterns Make it Work Make it Fast Fast

  9. Optimization: general patterns Make it Fast Fast

  10. Proxy, HTTP cache, Web cache

  11. Static site generator

  12. Practical cache: my experience • Home page (8) < 1

    sec • Product page (18) < 3 sec • Category page (15 - 45) < 4 sec
  13. Practical cache: my experience • Home page (8) < 1

    sec • Product page (18) < 3 sec • Category page (15 - 45) < 4 sec • No docs, support, time
  14. Optimization: framework

  15. Practical cache: Find • Zend_Log • Profiler Core_Debug • Magento

    Profiler • Xdebug Profiler • New Relic
  16. Practical cache: Find: Xdebug Profiler • Use xdebug.profiler_enable_trigger • Use

    xdebug.profiler_output_dir
  17. Practical cache: Find: New Relic

  18. Optimization: framework EPIC FAIL

  19. Practical cache: my experience • Magical numbers • Spaghetti code

    • Dead code • Duplicated code • Much more: http://www.codinghorror.com/
  20. Practical cache: Measure code • Phpcs • Phpcpd • Phpmd

    • Pdepend
  21. Practical cache: Measure with Sonar

  22. Practical cache: Cache strategies Bélády's Algorithm Most Recently Used Least

    Recently Used Least Frequently Used Adaptive Replacement Cache => LRU/LFU
  23. Practical cache: Research Home page (8) < 1 sec •

    Most viewed • Has dynamic content • Login area • Hot sells
  24. Practical cache: Research Home page (8) < 1 sec •

    Most viewed • Has dynamic content • Login area – not important • Hot sells – changes not often
  25. Practical cache: Zend Cache 1.0 Frontends Page cache Quick FPC

    Uses PHP Output (Capture) Blocks/Pages just cool
  26. Practical cache: Zend Cache 1.0: Output if (!($cache->start('UniqID'))) { Mage::run($mageRunCode,

    $mageRunType); $cache->end(); } else { $cache->end(); } 110 ms -> 20 ms
  27. Practical cache: Zend Cache 1.0 Backends File easy/cheap slow Memcache

    quick/independent flat data Database slow/independent expensive
  28. Practical cache: Research Product page (18) < 3 sec •

    Frequently viewed • Has dynamic content • Should be quick even for the first visitor
  29. Practical cache: Research Product page (18) < 3 sec •

    Frequently viewed • Cache blocks and parts of code • Has dynamic content • Validate on each change (EOA) • Should be quick even for the first visitor • Generate cache on our side
  30. Practical cache: Event Oriented Architecture

  31. Practical cache: Research Category page (15 - 45) < 4

    sec • Frequently viewed • Has dynamic content • Should be quick • Has high variety
  32. Practical cache: Research

  33. Practical cache: Research Category page (15 - 45) < 4

    sec • Frequently viewed • Cache blocks and parts of code • Has dynamic content • Validate on each change (EOA) • Has high variety • Cache collections
  34. Practical cache: Advices • Always Measure

  35. Practical cache: Advices • Always Measure • Do not cache

    only because You can
  36. Practical cache: Advices • Always Measure • Do not cache

    only because You can • Use Tags + Events for CRUD operations
  37. Practical cache: Advices • Always Measure • Do not cache

    only because You can • Use Tags + Events for CRUD operations • Generate cache by yourself if possible
  38. Practical cache: Advices • Always Measure • Do not cache

    only because You can • Use Tags + Events for CRUD operations • Generate cache by yourself if possible • Helpers sometimes don’t help
  39. Practical cache: Advices • Always Measure • Do not cache

    only because You can • Use Tags + Events for CRUD operations • Generate cache by yourself if possible • Helpers sometimes don’t help • File storage is slow on many files
  40. Practical cache: Advices • Always Research Background

  41. Zend Cache 1.0: TwoLevels Cache Response Request Slow Storage Fast

    Storage isCacheExists
  42. Zend Cache 1.0: TwoLevels Cache Response Request Slow Storage Fast

    Storage isCacheExists checkPriority Priority: 1-10 Depends on % of free space in the Fast Storage
  43. Zend Cache 1.0: TwoLevels Cache Priority: 1-10 Depends on %

    of free space in the Fast Storage Calculate priorities LRU/LFU
  44. Zend_Cache 2.0: Composer package

  45. Zend_Cache 2.0: in progress… Спасибо Вопросы