SlideShare a Scribd company logo
1 of 21
CHI: Universal caching
      for Perl
       Jonathan Swartz
       YAPC::NA 2012
         Madison, WI
What is CHI?

•   Cache Handling Interface

•   Standard interface and implementation for Perl
    caching ... like 'DBI for caching'

•   Caching = “Get and set key/values with expiration”
We already have...
What’s it good for?
•   Implement standard caching features in a single place
    •   Namespaces                •   Logging

    •   Serialization             •   Statistics collection

    •   Multilevel caches         •   Error handling

    •   Probablistic expiration   •   Compression

    •   Max size and discard      •   Configuration

•   Make new cache backends trivial to create
Who needs caches?

•   Web frameworks (Catalyst, Dancer, ...)

•   Sessions (Plack::Session, CGI::Session, ...)

•   ORMs (DBIx::Class, RDBO, ...)

•   Templating (TT, Mason, ...)

•   Code processing (Perl::Tidy, Perl::Critic, ...)

•   Slow to startup (Class::MOP/Moose, ...)
Using CHI
Namespaces
•   Separate cache keys into silos

•   Can be inspected, configured, and cleared
    independently

•   Typically package or template name
Drivers
•   Memory/RawMemory - In-process memory

•   File - Hierarchical, one file per entry

•   FastMmap - Mmap'ed files

•   BerkeleyDB

•   DBI

•   Memcached, Redis, TokyoTyrant - Distributed

•   ...
Probabilistic expiration
• Good for avoiding “miss stampedes”
L1/L2 cache
•   Store sessions in mysql, fronted by memcached
Mirror cache
•   Migrate cache from /old/root to /new/root
CHI::Memoize
•   Like Memoize, only CHI-ier
Why is compute() better?


•   Less typing

•   Background recomputation *
    (return old value immediately, recompute in background)

•   Can measure compute time and thus cache utility
    * - theoretical, not yet implemented
Cache utility
HR         =   hit rate
Cget       =   cost of get
Cset       =   cost of set
Ccompute   =   cost of compute

          Cget + (Ccompute + Cset) / HR
Utility = -------------------------------
                     Ccompute
Stats
Stats collected per namespace



•   # hits, misses, and sets   hit rate

•   avg cost of get, set, and compute (ms)

•   avg key and value size
Resources

• Get CHI from CPAN -
  http://search.cpan.org/perldoc?CHI

• Search for drivers -
  http://cpan.uwinnipeg.ca/search?query=CHI::Driver

• Subscribe to perl-cache mailing list -
  http://groups.google.com/group/perl-cache-discuss
Benchmarks
Description                    Get time   Set time
CHI::Driver::MemoryRaw         0.019ms    0.036ms
CHI::Driver::Memory            0.042ms    0.066ms
CHI::Driver::BerkeleyDB        0.052ms    0.073ms
CHI::Driver::FastMmap          0.057ms    0.087ms
CHI::Driver::DBI (sqlite)      0.112ms    1.659ms
CHI::Driver::File              0.118ms    1.138ms
CHI::Driver::Memcached::Fast   0.138ms    0.178ms
CHI::Driver::Memcached::libm   0.151ms    0.202ms
CHI::Driver::DBI (mysql)       0.236ms    0.273ms
CHI::Driver::Memcached         0.279ms    0.235ms
Creating a driver
Creating a cache
my $cache = CHI->new(
    driver     => 'File',
    namespace => ‘Foo::Bar’,
    cache_root => '/path/to/root'
);
my $cache = CHI->new(
    driver     => 'FastMmap',
    root_dir   => '/path/to/root',
    cache_size => '1k'
);
my $cache = CHI->new(
    driver => 'Memcached',
    servers => ["10.0.0.15:11211”, ...]
);

More Related Content

What's hot

Highload осень 2012 лекция 3
Highload осень 2012 лекция 3Highload осень 2012 лекция 3
Highload осень 2012 лекция 3
Technopark
 
Backup, Restore, and Disaster Recovery
Backup, Restore, and Disaster RecoveryBackup, Restore, and Disaster Recovery
Backup, Restore, and Disaster Recovery
MongoDB
 

What's hot (20)

Node.js - As a networking tool
Node.js - As a networking toolNode.js - As a networking tool
Node.js - As a networking tool
 
Nodejs - Should Ruby Developers Care?
Nodejs - Should Ruby Developers Care?Nodejs - Should Ruby Developers Care?
Nodejs - Should Ruby Developers Care?
 
Nodejs - A quick tour (v4)
Nodejs - A quick tour (v4)Nodejs - A quick tour (v4)
Nodejs - A quick tour (v4)
 
Elasticsearch 1.x Cluster Installation (VirtualBox)
Elasticsearch 1.x Cluster Installation (VirtualBox)Elasticsearch 1.x Cluster Installation (VirtualBox)
Elasticsearch 1.x Cluster Installation (VirtualBox)
 
Scaling WordPress On A Small Budget
Scaling WordPress On A Small BudgetScaling WordPress On A Small Budget
Scaling WordPress On A Small Budget
 
Highload осень 2012 лекция 3
Highload осень 2012 лекция 3Highload осень 2012 лекция 3
Highload осень 2012 лекция 3
 
Memcached
MemcachedMemcached
Memcached
 
Building low latency java applications with ehcache
Building low latency java applications with ehcacheBuilding low latency java applications with ehcache
Building low latency java applications with ehcache
 
Nodejs - A quick tour (v5)
Nodejs - A quick tour (v5)Nodejs - A quick tour (v5)
Nodejs - A quick tour (v5)
 
Sofia WP User Group Presentation
Sofia WP User Group PresentationSofia WP User Group Presentation
Sofia WP User Group Presentation
 
Caching
CachingCaching
Caching
 
Node.js - A practical introduction (v2)
Node.js  - A practical introduction (v2)Node.js  - A practical introduction (v2)
Node.js - A practical introduction (v2)
 
Node.js - A Quick Tour II
Node.js - A Quick Tour IINode.js - A Quick Tour II
Node.js - A Quick Tour II
 
cache concepts and varnish-cache
cache concepts and varnish-cachecache concepts and varnish-cache
cache concepts and varnish-cache
 
Banquet 36
Banquet 36Banquet 36
Banquet 36
 
Azure Recovery Services
Azure Recovery ServicesAzure Recovery Services
Azure Recovery Services
 
Scalability at GROU.PS
Scalability at GROU.PSScalability at GROU.PS
Scalability at GROU.PS
 
To Hire, or to train, that is the question (Percona Live 2014)
To Hire, or to train, that is the question (Percona Live 2014)To Hire, or to train, that is the question (Percona Live 2014)
To Hire, or to train, that is the question (Percona Live 2014)
 
Automating with Ansible
Automating with AnsibleAutomating with Ansible
Automating with Ansible
 
Backup, Restore, and Disaster Recovery
Backup, Restore, and Disaster RecoveryBackup, Restore, and Disaster Recovery
Backup, Restore, and Disaster Recovery
 

Viewers also liked (7)

Zadar digit presentation
Zadar digit presentationZadar digit presentation
Zadar digit presentation
 
Canal yoga-kit-iniciante
Canal yoga-kit-inicianteCanal yoga-kit-iniciante
Canal yoga-kit-iniciante
 
Portfolio For Library Course By Teng Miao(Eric)
Portfolio For Library Course By Teng Miao(Eric)Portfolio For Library Course By Teng Miao(Eric)
Portfolio For Library Course By Teng Miao(Eric)
 
Chiaccherata sulla democrazia partecipata
Chiaccherata sulla democrazia partecipataChiaccherata sulla democrazia partecipata
Chiaccherata sulla democrazia partecipata
 
Uspto reexamination request - update - august 8th to august 14th, 2012 - in...
Uspto   reexamination request - update - august 8th to august 14th, 2012 - in...Uspto   reexamination request - update - august 8th to august 14th, 2012 - in...
Uspto reexamination request - update - august 8th to august 14th, 2012 - in...
 
Routing 7
Routing 7Routing 7
Routing 7
 
Contract
ContractContract
Contract
 

Similar to CHI - YAPC NA 2012

Yapc10 Cdt World Domination
Yapc10   Cdt World DominationYapc10   Cdt World Domination
Yapc10 Cdt World Domination
cPanel
 

Similar to CHI - YAPC NA 2012 (20)

Introduction to memcached
Introduction to memcachedIntroduction to memcached
Introduction to memcached
 
Caching with Memcached and APC
Caching with Memcached and APCCaching with Memcached and APC
Caching with Memcached and APC
 
Where Django Caching Bust at the Seams
Where Django Caching Bust at the SeamsWhere Django Caching Bust at the Seams
Where Django Caching Bust at the Seams
 
Caching Methodology & Strategies
Caching Methodology & StrategiesCaching Methodology & Strategies
Caching Methodology & Strategies
 
Caching methodology and strategies
Caching methodology and strategiesCaching methodology and strategies
Caching methodology and strategies
 
Top ten-list
Top ten-listTop ten-list
Top ten-list
 
phptek13 - Caching and tuning fun tutorial
phptek13 - Caching and tuning fun tutorialphptek13 - Caching and tuning fun tutorial
phptek13 - Caching and tuning fun tutorial
 
Caching your rails application
Caching your rails applicationCaching your rails application
Caching your rails application
 
Caching and tuning fun for high scalability
Caching and tuning fun for high scalabilityCaching and tuning fun for high scalability
Caching and tuning fun for high scalability
 
Using cassandra as a distributed logging to store pb data
Using cassandra as a distributed logging to store pb dataUsing cassandra as a distributed logging to store pb data
Using cassandra as a distributed logging to store pb data
 
Ruby and Distributed Storage Systems
Ruby and Distributed Storage SystemsRuby and Distributed Storage Systems
Ruby and Distributed Storage Systems
 
High Performance With Java
High Performance With JavaHigh Performance With Java
High Performance With Java
 
Caching and tuning fun for high scalability
Caching and tuning fun for high scalabilityCaching and tuning fun for high scalability
Caching and tuning fun for high scalability
 
AppFabric Velocity
AppFabric VelocityAppFabric Velocity
AppFabric Velocity
 
Memcached: What is it and what does it do?
Memcached: What is it and what does it do?Memcached: What is it and what does it do?
Memcached: What is it and what does it do?
 
CREAM - That Conference Austin - January 2024.pptx
CREAM - That Conference Austin - January 2024.pptxCREAM - That Conference Austin - January 2024.pptx
CREAM - That Conference Austin - January 2024.pptx
 
Configuration Management in the Cloud - Cloud Phoenix Meetup Feb 2014
Configuration Management in the Cloud - Cloud Phoenix Meetup Feb 2014Configuration Management in the Cloud - Cloud Phoenix Meetup Feb 2014
Configuration Management in the Cloud - Cloud Phoenix Meetup Feb 2014
 
Speeding Up The Snail
Speeding Up The SnailSpeeding Up The Snail
Speeding Up The Snail
 
Yapc10 Cdt World Domination
Yapc10   Cdt World DominationYapc10   Cdt World Domination
Yapc10 Cdt World Domination
 
php & performance
 php & performance php & performance
php & performance
 

Recently uploaded

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Recently uploaded (20)

Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 

CHI - YAPC NA 2012

  • 1. CHI: Universal caching for Perl Jonathan Swartz YAPC::NA 2012 Madison, WI
  • 2. What is CHI? • Cache Handling Interface • Standard interface and implementation for Perl caching ... like 'DBI for caching' • Caching = “Get and set key/values with expiration”
  • 4. What’s it good for? • Implement standard caching features in a single place • Namespaces • Logging • Serialization • Statistics collection • Multilevel caches • Error handling • Probablistic expiration • Compression • Max size and discard • Configuration • Make new cache backends trivial to create
  • 5. Who needs caches? • Web frameworks (Catalyst, Dancer, ...) • Sessions (Plack::Session, CGI::Session, ...) • ORMs (DBIx::Class, RDBO, ...) • Templating (TT, Mason, ...) • Code processing (Perl::Tidy, Perl::Critic, ...) • Slow to startup (Class::MOP/Moose, ...)
  • 7. Namespaces • Separate cache keys into silos • Can be inspected, configured, and cleared independently • Typically package or template name
  • 8. Drivers • Memory/RawMemory - In-process memory • File - Hierarchical, one file per entry • FastMmap - Mmap'ed files • BerkeleyDB • DBI • Memcached, Redis, TokyoTyrant - Distributed • ...
  • 9. Probabilistic expiration • Good for avoiding “miss stampedes”
  • 10. L1/L2 cache • Store sessions in mysql, fronted by memcached
  • 11. Mirror cache • Migrate cache from /old/root to /new/root
  • 12. CHI::Memoize • Like Memoize, only CHI-ier
  • 13. Why is compute() better? • Less typing • Background recomputation * (return old value immediately, recompute in background) • Can measure compute time and thus cache utility * - theoretical, not yet implemented
  • 14. Cache utility HR = hit rate Cget = cost of get Cset = cost of set Ccompute = cost of compute Cget + (Ccompute + Cset) / HR Utility = ------------------------------- Ccompute
  • 15. Stats
  • 16. Stats collected per namespace • # hits, misses, and sets hit rate • avg cost of get, set, and compute (ms) • avg key and value size
  • 17. Resources • Get CHI from CPAN - http://search.cpan.org/perldoc?CHI • Search for drivers - http://cpan.uwinnipeg.ca/search?query=CHI::Driver • Subscribe to perl-cache mailing list - http://groups.google.com/group/perl-cache-discuss
  • 18.
  • 19. Benchmarks Description Get time Set time CHI::Driver::MemoryRaw 0.019ms 0.036ms CHI::Driver::Memory 0.042ms 0.066ms CHI::Driver::BerkeleyDB 0.052ms 0.073ms CHI::Driver::FastMmap 0.057ms 0.087ms CHI::Driver::DBI (sqlite) 0.112ms 1.659ms CHI::Driver::File 0.118ms 1.138ms CHI::Driver::Memcached::Fast 0.138ms 0.178ms CHI::Driver::Memcached::libm 0.151ms 0.202ms CHI::Driver::DBI (mysql) 0.236ms 0.273ms CHI::Driver::Memcached 0.279ms 0.235ms
  • 21. Creating a cache my $cache = CHI->new( driver => 'File', namespace => ‘Foo::Bar’, cache_root => '/path/to/root' ); my $cache = CHI->new( driver => 'FastMmap', root_dir => '/path/to/root', cache_size => '1k' ); my $cache = CHI->new( driver => 'Memcached', servers => ["10.0.0.15:11211”, ...] );

Editor's Notes

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n