SlideShare ist ein Scribd-Unternehmen logo
1 von 27
Cache That!
Gopal Vijayaraghavan
Yahoo Inc.
gopalv@php.net

                       July 26th, 2007
Cache ? Why ?
- Easiest optimisation you could do
  - Maximum return on work invested
- Hopefully transparent
- Probably doesn't need a complete redesign
  - especially of business logic
- Tradeoff between speed and accuracy
- 80+% of Web content is not mission critical
  - scale is more important
Sandwich Theory




http://flickr.com/photos/ozute/87465787/
Sandwich Theory
- Pages are dynamic
- Like a sandwich made to order.
- The whole page is built to order, but bits of
  content require varying “freshness”
- A jar of pre-cut olives are the next best thing after
  Sliced Bread
“fast”: latency & throughput




http://flickr.com/photos/brtsergio/184026033/
Cache: strategies and levels
- Browser land
- Content proxying
- Pre-generating content
- Active data caching
- Backend caches
So, what's this talk about ?




http://flickr.com/photos/frogmuseum2/238601344
Common Sense: Repeated
- Browser caches ?
  - DNS, Expires:, Cache-Control:
- Squid reverse proxies ?
  - Ad-hoc semi-static content
- Content pre-gen ?
  - RSS feeds & other periodically updated content
- Backend caches ?
  - DB query caches, disk/OS caches
Active Data Caching
- We're actually in PHP land now
- Two main cache tools
  - APC
  - Memcache
- APC is php specific
- Memcached is more generic and distributed
Choices




http://flickr.com/photos/elsie/347928333/
Red or Blue ?
- APC                    - Memcached
 - Single server          - Distributed
 - Stores arrays as-is    - needs serialization
 - small data             - large data safe
 - data churn causes      - handles data churn
   issues                   better
 - Does opcodes too       - Only data
APC: Opcode Cache
- Drop-in & use
- Prevents disk access & syscalls
- Is really old Hat, now
- Tuning & tweaking
  - nostat mode
  - include_once_override
  - locking modes
Tuning APC – check list
- You need to tweak APC if you've got
  - a large number of files (> 1024)
  - a large cache footprint (> 64 M)
  - a mess of include_onces
  - a highly OOP design
  - very static php files
  - rsync and inode re-use
APC Tuneables
- apc.ini
  - apc.shm_size (64 M)
  - apc.num_files_hint (512)
  - apc.stat (On)
  - apc.stat_ctime (Off)
  - apc.include_once_override (Off)
  - apc.filters ()
  - apc.localcache (Off)
APC monitoring
- Monitor APC using the apc.php in the pkg
- Provides basic information about
  - memory usage
  - fragmentation
  - cache request/insert rates
    - user and file
  - expunge/cache-full count
Tune your Code - #I
- Reduce include/include_once calls
  - Template & stitch
  - R3 (http://rthree.sf.net/)
- Use full include paths
  - include(“./z.php); instead of include(“z.php”);
- Use constant includes
  - don't wrap include with your functions
- Avoid eval() at all costs
Inclued
Inclued: Smarty
APC: var_export gotchas
- PHP opcodes are cached in APC
- So, putting a constant array on a file seems OK
- But here's the “constant” array in PHP

  line     # op                       ext operands
  -------------------------------------------------------
     2     0 INIT_ARRAY                    ~0, 'z', 'x'
     3     1 ADD_ARRAY_ELEMENT             ~0, 'b', 'a'
     4     2 ADD_ARRAY_ELEMENT             ~0, 'c', 'b'
     5     3 ADD_ARRAY_ELEMENT             ~0, 'd', 'c'
           4 ASSIGN                            !0, ~0
     7     5 RETURN                            1
           6 ZEND_HANDLE_EXCEPTION
APC: Dynamic Style
- apc_fetch()/apc_store()
- The interface is simple enough
   if(!($data = apc_fetch('data'))) {
     $data = array( .... );
     apc_store('data', $data);
   }


- But with a Time To Live (TTL) setting, data expires
Lies, Damned Lies & Statistics




http://flickr.com/photos/matthijs/82616861/
APC vs Files
                                                           Writes     Reads
     file + includes                                        17809 1856348.5
     file + serialized arrays                               13804 517380.2
     apc                                                    98586 359790.3
                                 Read/Write performance      * Less time means better

      Includes




                                                                                 Read
                                                                                 Write
     Serialized




          APC




              0.00   500000.00          1000000.00   1500000.00     2000000.00




http://pooteeweet.org/blog/721
APC vs Files
- Serialized arrays are the fastest to write to
- APC is the slowest to write to, but the fastest to
  read from
- Disk files with arrays lose out on both fronts
- But then why would you ever use files ?
- Because they expire gracefully, that's why
- So, what happens when a cache entry expires ?
Tune your Code - II
- Use APC user cache
  - WPcache2, smarty_cache_apc
- Re-order your nested lookups
  - NO: $a = apc_fetch(“foo”); echo $a[“baz”];
  - YES: $a = apc_fetch(“foo.baz”); echo $a;
- Avoid data race conditions
  - shouldn't I fix the race conditions ?
Anatomy of a Cache Slam
What works (or has worked)
- Give it more (virtual) memory to burn
- Use APC user cache for infrequently updated
  data
- Update your APC cache out of band
  - Cron & Curl are APC's friends
- Always check your APC info for
  - cache full count
  - fragmentation
Thank you for listening
- Resources
  - http://pecl.php.net/package/APC
  - http://pecl.php.net/package/memcache
- Slides
  - http://t3.dotgnu.info/slides/oscon07.pdf
- My Blog
  - http://t3.dotgnu.info/blog/php/

Weitere ähnliche Inhalte

Was ist angesagt?

scale14x-bigtop-overview-roadmap
scale14x-bigtop-overview-roadmapscale14x-bigtop-overview-roadmap
scale14x-bigtop-overview-roadmapNate D'Amico
 
Caching for Cash: Benchmarking and Profiling
Caching for Cash: Benchmarking and ProfilingCaching for Cash: Benchmarking and Profiling
Caching for Cash: Benchmarking and ProfilingScott MacVicar
 
Migrating and living on rds aurora
Migrating and living on rds auroraMigrating and living on rds aurora
Migrating and living on rds auroraBalazs Pocze
 
Hadoop spark performance comparison
Hadoop spark performance comparisonHadoop spark performance comparison
Hadoop spark performance comparisonarunkumar sadhasivam
 
Optimizing Laravel for Production
Optimizing Laravel for ProductionOptimizing Laravel for Production
Optimizing Laravel for ProductionKrisna Fathurahman
 
Caching for Cash: Caching
Caching for Cash: CachingCaching for Cash: Caching
Caching for Cash: CachingScott MacVicar
 
Database High Availability Using SHADOW Systems
Database High Availability Using SHADOW SystemsDatabase High Availability Using SHADOW Systems
Database High Availability Using SHADOW SystemsJaemyung Kim
 
Hadoop single node setup
Hadoop single node setupHadoop single node setup
Hadoop single node setupMohammad_Tariq
 
The Magic of Hot Streaming Replication, Bruce Momjian
The Magic of Hot Streaming Replication, Bruce MomjianThe Magic of Hot Streaming Replication, Bruce Momjian
The Magic of Hot Streaming Replication, Bruce MomjianFuenteovejuna
 
Set up Hadoop Cluster on Amazon EC2
Set up Hadoop Cluster on Amazon EC2Set up Hadoop Cluster on Amazon EC2
Set up Hadoop Cluster on Amazon EC2IMC Institute
 
Automating everything with PowerShell, Terraform, and AWS
Automating everything with PowerShell, Terraform, and AWSAutomating everything with PowerShell, Terraform, and AWS
Automating everything with PowerShell, Terraform, and AWSChris Brown
 
Performance all teh things
Performance all teh thingsPerformance all teh things
Performance all teh thingsMarcus Deglos
 
Basic Knowledge on MySql Replication
Basic Knowledge on MySql ReplicationBasic Knowledge on MySql Replication
Basic Knowledge on MySql ReplicationTasawr Interactive
 
Upgrading mysql version 5.5.30 to 5.6.10
Upgrading mysql version 5.5.30 to 5.6.10Upgrading mysql version 5.5.30 to 5.6.10
Upgrading mysql version 5.5.30 to 5.6.10Vasudeva Rao
 

Was ist angesagt? (18)

scale14x-bigtop-overview-roadmap
scale14x-bigtop-overview-roadmapscale14x-bigtop-overview-roadmap
scale14x-bigtop-overview-roadmap
 
Caching for Cash: Benchmarking and Profiling
Caching for Cash: Benchmarking and ProfilingCaching for Cash: Benchmarking and Profiling
Caching for Cash: Benchmarking and Profiling
 
Migrating and living on rds aurora
Migrating and living on rds auroraMigrating and living on rds aurora
Migrating and living on rds aurora
 
Hadoop spark performance comparison
Hadoop spark performance comparisonHadoop spark performance comparison
Hadoop spark performance comparison
 
Mysql
MysqlMysql
Mysql
 
Hadoop on ec2
Hadoop on ec2Hadoop on ec2
Hadoop on ec2
 
Optimizing Laravel for Production
Optimizing Laravel for ProductionOptimizing Laravel for Production
Optimizing Laravel for Production
 
Caching for Cash: Caching
Caching for Cash: CachingCaching for Cash: Caching
Caching for Cash: Caching
 
Database High Availability Using SHADOW Systems
Database High Availability Using SHADOW SystemsDatabase High Availability Using SHADOW Systems
Database High Availability Using SHADOW Systems
 
Hadoop single node setup
Hadoop single node setupHadoop single node setup
Hadoop single node setup
 
The Magic of Hot Streaming Replication, Bruce Momjian
The Magic of Hot Streaming Replication, Bruce MomjianThe Magic of Hot Streaming Replication, Bruce Momjian
The Magic of Hot Streaming Replication, Bruce Momjian
 
Scaling symfony apps
Scaling symfony appsScaling symfony apps
Scaling symfony apps
 
Set up Hadoop Cluster on Amazon EC2
Set up Hadoop Cluster on Amazon EC2Set up Hadoop Cluster on Amazon EC2
Set up Hadoop Cluster on Amazon EC2
 
Automating everything with PowerShell, Terraform, and AWS
Automating everything with PowerShell, Terraform, and AWSAutomating everything with PowerShell, Terraform, and AWS
Automating everything with PowerShell, Terraform, and AWS
 
Performance all teh things
Performance all teh thingsPerformance all teh things
Performance all teh things
 
Basic Knowledge on MySql Replication
Basic Knowledge on MySql ReplicationBasic Knowledge on MySql Replication
Basic Knowledge on MySql Replication
 
Upgrading mysql version 5.5.30 to 5.6.10
Upgrading mysql version 5.5.30 to 5.6.10Upgrading mysql version 5.5.30 to 5.6.10
Upgrading mysql version 5.5.30 to 5.6.10
 
Aegir presentation
Aegir presentation Aegir presentation
Aegir presentation
 

Ähnlich wie Os Gopal

php & performance
 php & performance php & performance
php & performancesimon8410
 
Caching and tuning fun for high scalability @ FOSDEM 2012
Caching and tuning fun for high scalability @ FOSDEM 2012Caching and tuning fun for high scalability @ FOSDEM 2012
Caching and tuning fun for high scalability @ FOSDEM 2012Wim Godden
 
PHP & Performance
PHP & PerformancePHP & Performance
PHP & Performance毅 吕
 
Caching and tuning fun for high scalability @ FrOSCon 2011
Caching and tuning fun for high scalability @ FrOSCon 2011Caching and tuning fun for high scalability @ FrOSCon 2011
Caching and tuning fun for high scalability @ FrOSCon 2011Wim Godden
 
Accelerating Spark SQL Workloads to 50X Performance with Apache Arrow-Based F...
Accelerating Spark SQL Workloads to 50X Performance with Apache Arrow-Based F...Accelerating Spark SQL Workloads to 50X Performance with Apache Arrow-Based F...
Accelerating Spark SQL Workloads to 50X Performance with Apache Arrow-Based F...Databricks
 
Caching and tuning fun for high scalability @ phpBenelux 2011
Caching and tuning fun for high scalability @ phpBenelux 2011Caching and tuning fun for high scalability @ phpBenelux 2011
Caching and tuning fun for high scalability @ phpBenelux 2011Wim Godden
 
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 scalabilityWim Godden
 
Caching and tuning fun for high scalability @ PHPTour
Caching and tuning fun for high scalability @ PHPTourCaching and tuning fun for high scalability @ PHPTour
Caching and tuning fun for high scalability @ PHPTourWim Godden
 
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 scalabilityWim Godden
 
Using apache spark for processing trillions of records each day at Datadog
Using apache spark for processing trillions of records each day at DatadogUsing apache spark for processing trillions of records each day at Datadog
Using apache spark for processing trillions of records each day at DatadogVadim Semenov
 
(DAT402) Amazon RDS PostgreSQL:Lessons Learned & New Features
(DAT402) Amazon RDS PostgreSQL:Lessons Learned & New Features(DAT402) Amazon RDS PostgreSQL:Lessons Learned & New Features
(DAT402) Amazon RDS PostgreSQL:Lessons Learned & New FeaturesAmazon Web Services
 
Bottom to Top Stack Optimization with LAMP
Bottom to Top Stack Optimization with LAMPBottom to Top Stack Optimization with LAMP
Bottom to Top Stack Optimization with LAMPkatzgrau
 
Bottom to Top Stack Optimization - CICON2011
Bottom to Top Stack Optimization - CICON2011Bottom to Top Stack Optimization - CICON2011
Bottom to Top Stack Optimization - CICON2011CodeIgniter Conference
 
High Performance Web Sites
High Performance Web SitesHigh Performance Web Sites
High Performance Web SitesRavi Raj
 
Tuning tips for Apache Spark Jobs
Tuning tips for Apache Spark JobsTuning tips for Apache Spark Jobs
Tuning tips for Apache Spark JobsSamir Bessalah
 
Hotsos 2011: Mining the AWR repository for Capacity Planning, Visualization, ...
Hotsos 2011: Mining the AWR repository for Capacity Planning, Visualization, ...Hotsos 2011: Mining the AWR repository for Capacity Planning, Visualization, ...
Hotsos 2011: Mining the AWR repository for Capacity Planning, Visualization, ...Kristofferson A
 
User-space Network Processing
User-space Network ProcessingUser-space Network Processing
User-space Network ProcessingRyousei Takano
 
Site Performance - From Pinto to Ferrari
Site Performance - From Pinto to FerrariSite Performance - From Pinto to Ferrari
Site Performance - From Pinto to FerrariJoseph Scott
 
0628阙宏宇
0628阙宏宇0628阙宏宇
0628阙宏宇zhu02
 
Spark 2.x Troubleshooting Guide
Spark 2.x Troubleshooting GuideSpark 2.x Troubleshooting Guide
Spark 2.x Troubleshooting GuideIBM
 

Ähnlich wie Os Gopal (20)

php & performance
 php & performance php & performance
php & performance
 
Caching and tuning fun for high scalability @ FOSDEM 2012
Caching and tuning fun for high scalability @ FOSDEM 2012Caching and tuning fun for high scalability @ FOSDEM 2012
Caching and tuning fun for high scalability @ FOSDEM 2012
 
PHP & Performance
PHP & PerformancePHP & Performance
PHP & Performance
 
Caching and tuning fun for high scalability @ FrOSCon 2011
Caching and tuning fun for high scalability @ FrOSCon 2011Caching and tuning fun for high scalability @ FrOSCon 2011
Caching and tuning fun for high scalability @ FrOSCon 2011
 
Accelerating Spark SQL Workloads to 50X Performance with Apache Arrow-Based F...
Accelerating Spark SQL Workloads to 50X Performance with Apache Arrow-Based F...Accelerating Spark SQL Workloads to 50X Performance with Apache Arrow-Based F...
Accelerating Spark SQL Workloads to 50X Performance with Apache Arrow-Based F...
 
Caching and tuning fun for high scalability @ phpBenelux 2011
Caching and tuning fun for high scalability @ phpBenelux 2011Caching and tuning fun for high scalability @ phpBenelux 2011
Caching and tuning fun for high scalability @ phpBenelux 2011
 
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
 
Caching and tuning fun for high scalability @ PHPTour
Caching and tuning fun for high scalability @ PHPTourCaching and tuning fun for high scalability @ PHPTour
Caching and tuning fun for high scalability @ PHPTour
 
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 apache spark for processing trillions of records each day at Datadog
Using apache spark for processing trillions of records each day at DatadogUsing apache spark for processing trillions of records each day at Datadog
Using apache spark for processing trillions of records each day at Datadog
 
(DAT402) Amazon RDS PostgreSQL:Lessons Learned & New Features
(DAT402) Amazon RDS PostgreSQL:Lessons Learned & New Features(DAT402) Amazon RDS PostgreSQL:Lessons Learned & New Features
(DAT402) Amazon RDS PostgreSQL:Lessons Learned & New Features
 
Bottom to Top Stack Optimization with LAMP
Bottom to Top Stack Optimization with LAMPBottom to Top Stack Optimization with LAMP
Bottom to Top Stack Optimization with LAMP
 
Bottom to Top Stack Optimization - CICON2011
Bottom to Top Stack Optimization - CICON2011Bottom to Top Stack Optimization - CICON2011
Bottom to Top Stack Optimization - CICON2011
 
High Performance Web Sites
High Performance Web SitesHigh Performance Web Sites
High Performance Web Sites
 
Tuning tips for Apache Spark Jobs
Tuning tips for Apache Spark JobsTuning tips for Apache Spark Jobs
Tuning tips for Apache Spark Jobs
 
Hotsos 2011: Mining the AWR repository for Capacity Planning, Visualization, ...
Hotsos 2011: Mining the AWR repository for Capacity Planning, Visualization, ...Hotsos 2011: Mining the AWR repository for Capacity Planning, Visualization, ...
Hotsos 2011: Mining the AWR repository for Capacity Planning, Visualization, ...
 
User-space Network Processing
User-space Network ProcessingUser-space Network Processing
User-space Network Processing
 
Site Performance - From Pinto to Ferrari
Site Performance - From Pinto to FerrariSite Performance - From Pinto to Ferrari
Site Performance - From Pinto to Ferrari
 
0628阙宏宇
0628阙宏宇0628阙宏宇
0628阙宏宇
 
Spark 2.x Troubleshooting Guide
Spark 2.x Troubleshooting GuideSpark 2.x Troubleshooting Guide
Spark 2.x Troubleshooting Guide
 

Mehr von oscon2007

J Ruby Whirlwind Tour
J Ruby Whirlwind TourJ Ruby Whirlwind Tour
J Ruby Whirlwind Touroscon2007
 
Solr Presentation5
Solr Presentation5Solr Presentation5
Solr Presentation5oscon2007
 
Os Fitzpatrick Sussman Wiifm
Os Fitzpatrick Sussman WiifmOs Fitzpatrick Sussman Wiifm
Os Fitzpatrick Sussman Wiifmoscon2007
 
Performance Whack A Mole
Performance Whack A MolePerformance Whack A Mole
Performance Whack A Moleoscon2007
 
Os Lanphier Brashears
Os Lanphier BrashearsOs Lanphier Brashears
Os Lanphier Brashearsoscon2007
 
Os Fitzpatrick Sussman Swp
Os Fitzpatrick Sussman SwpOs Fitzpatrick Sussman Swp
Os Fitzpatrick Sussman Swposcon2007
 
Os Berlin Dispelling Myths
Os Berlin Dispelling MythsOs Berlin Dispelling Myths
Os Berlin Dispelling Mythsoscon2007
 
Os Keysholistic
Os KeysholisticOs Keysholistic
Os Keysholisticoscon2007
 
Os Jonphillips
Os JonphillipsOs Jonphillips
Os Jonphillipsoscon2007
 
Os Urnerupdated
Os UrnerupdatedOs Urnerupdated
Os Urnerupdatedoscon2007
 

Mehr von oscon2007 (20)

J Ruby Whirlwind Tour
J Ruby Whirlwind TourJ Ruby Whirlwind Tour
J Ruby Whirlwind Tour
 
Solr Presentation5
Solr Presentation5Solr Presentation5
Solr Presentation5
 
Os Borger
Os BorgerOs Borger
Os Borger
 
Os Harkins
Os HarkinsOs Harkins
Os Harkins
 
Os Fitzpatrick Sussman Wiifm
Os Fitzpatrick Sussman WiifmOs Fitzpatrick Sussman Wiifm
Os Fitzpatrick Sussman Wiifm
 
Os Bunce
Os BunceOs Bunce
Os Bunce
 
Yuicss R7
Yuicss R7Yuicss R7
Yuicss R7
 
Performance Whack A Mole
Performance Whack A MolePerformance Whack A Mole
Performance Whack A Mole
 
Os Fogel
Os FogelOs Fogel
Os Fogel
 
Os Lanphier Brashears
Os Lanphier BrashearsOs Lanphier Brashears
Os Lanphier Brashears
 
Os Tucker
Os TuckerOs Tucker
Os Tucker
 
Os Fitzpatrick Sussman Swp
Os Fitzpatrick Sussman SwpOs Fitzpatrick Sussman Swp
Os Fitzpatrick Sussman Swp
 
Os Furlong
Os FurlongOs Furlong
Os Furlong
 
Os Berlin Dispelling Myths
Os Berlin Dispelling MythsOs Berlin Dispelling Myths
Os Berlin Dispelling Myths
 
Os Kimsal
Os KimsalOs Kimsal
Os Kimsal
 
Os Pruett
Os PruettOs Pruett
Os Pruett
 
Os Alrubaie
Os AlrubaieOs Alrubaie
Os Alrubaie
 
Os Keysholistic
Os KeysholisticOs Keysholistic
Os Keysholistic
 
Os Jonphillips
Os JonphillipsOs Jonphillips
Os Jonphillips
 
Os Urnerupdated
Os UrnerupdatedOs Urnerupdated
Os Urnerupdated
 

Kürzlich hochgeladen

Lundin Gold - Q1 2024 Conference Call Presentation (Revised)
Lundin Gold - Q1 2024 Conference Call Presentation (Revised)Lundin Gold - Q1 2024 Conference Call Presentation (Revised)
Lundin Gold - Q1 2024 Conference Call Presentation (Revised)Adnet Communications
 
Putting the SPARK into Virtual Training.pptx
Putting the SPARK into Virtual Training.pptxPutting the SPARK into Virtual Training.pptx
Putting the SPARK into Virtual Training.pptxCynthia Clay
 
Pre Engineered Building Manufacturers Hyderabad.pptx
Pre Engineered  Building Manufacturers Hyderabad.pptxPre Engineered  Building Manufacturers Hyderabad.pptx
Pre Engineered Building Manufacturers Hyderabad.pptxRoofing Contractor
 
Paradip CALL GIRL❤7091819311❤CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDING
Paradip CALL GIRL❤7091819311❤CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDINGParadip CALL GIRL❤7091819311❤CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDING
Paradip CALL GIRL❤7091819311❤CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDINGpr788182
 
Structuring and Writing DRL Mckinsey (1).pdf
Structuring and Writing DRL Mckinsey (1).pdfStructuring and Writing DRL Mckinsey (1).pdf
Structuring and Writing DRL Mckinsey (1).pdflaloo_007
 
Unveiling Falcon Invoice Discounting: Leading the Way as India's Premier Bill...
Unveiling Falcon Invoice Discounting: Leading the Way as India's Premier Bill...Unveiling Falcon Invoice Discounting: Leading the Way as India's Premier Bill...
Unveiling Falcon Invoice Discounting: Leading the Way as India's Premier Bill...Falcon Invoice Discounting
 
Falcon Invoice Discounting: The best investment platform in india for investors
Falcon Invoice Discounting: The best investment platform in india for investorsFalcon Invoice Discounting: The best investment platform in india for investors
Falcon Invoice Discounting: The best investment platform in india for investorsFalcon Invoice Discounting
 
joint cost.pptx COST ACCOUNTING Sixteenth Edition ...
joint cost.pptx  COST ACCOUNTING  Sixteenth Edition                          ...joint cost.pptx  COST ACCOUNTING  Sixteenth Edition                          ...
joint cost.pptx COST ACCOUNTING Sixteenth Edition ...NadhimTaha
 
Organizational Transformation Lead with Culture
Organizational Transformation Lead with CultureOrganizational Transformation Lead with Culture
Organizational Transformation Lead with CultureSeta Wicaksana
 
BeMetals Investor Presentation_May 3, 2024.pdf
BeMetals Investor Presentation_May 3, 2024.pdfBeMetals Investor Presentation_May 3, 2024.pdf
BeMetals Investor Presentation_May 3, 2024.pdfDerekIwanaka1
 
Falcon Invoice Discounting: Empowering Your Business Growth
Falcon Invoice Discounting: Empowering Your Business GrowthFalcon Invoice Discounting: Empowering Your Business Growth
Falcon Invoice Discounting: Empowering Your Business GrowthFalcon investment
 
PHX May 2024 Corporate Presentation Final
PHX May 2024 Corporate Presentation FinalPHX May 2024 Corporate Presentation Final
PHX May 2024 Corporate Presentation FinalPanhandleOilandGas
 
Falcon Invoice Discounting: Unlock Your Business Potential
Falcon Invoice Discounting: Unlock Your Business PotentialFalcon Invoice Discounting: Unlock Your Business Potential
Falcon Invoice Discounting: Unlock Your Business PotentialFalcon investment
 
Phases of Negotiation .pptx
 Phases of Negotiation .pptx Phases of Negotiation .pptx
Phases of Negotiation .pptxnandhinijagan9867
 
TVB_The Vietnam Believer Newsletter_May 6th, 2024_ENVol. 006.pdf
TVB_The Vietnam Believer Newsletter_May 6th, 2024_ENVol. 006.pdfTVB_The Vietnam Believer Newsletter_May 6th, 2024_ENVol. 006.pdf
TVB_The Vietnam Believer Newsletter_May 6th, 2024_ENVol. 006.pdfbelieveminhh
 
Arti Languages Pre Seed Teaser Deck 2024.pdf
Arti Languages Pre Seed Teaser Deck 2024.pdfArti Languages Pre Seed Teaser Deck 2024.pdf
Arti Languages Pre Seed Teaser Deck 2024.pdfwill854175
 
Lucknow Housewife Escorts by Sexy Bhabhi Service 8250092165
Lucknow Housewife Escorts  by Sexy Bhabhi Service 8250092165Lucknow Housewife Escorts  by Sexy Bhabhi Service 8250092165
Lucknow Housewife Escorts by Sexy Bhabhi Service 8250092165meghakumariji156
 
Dr. Admir Softic_ presentation_Green Club_ENG.pdf
Dr. Admir Softic_ presentation_Green Club_ENG.pdfDr. Admir Softic_ presentation_Green Club_ENG.pdf
Dr. Admir Softic_ presentation_Green Club_ENG.pdfAdmir Softic
 

Kürzlich hochgeladen (20)

Lundin Gold - Q1 2024 Conference Call Presentation (Revised)
Lundin Gold - Q1 2024 Conference Call Presentation (Revised)Lundin Gold - Q1 2024 Conference Call Presentation (Revised)
Lundin Gold - Q1 2024 Conference Call Presentation (Revised)
 
Putting the SPARK into Virtual Training.pptx
Putting the SPARK into Virtual Training.pptxPutting the SPARK into Virtual Training.pptx
Putting the SPARK into Virtual Training.pptx
 
Pre Engineered Building Manufacturers Hyderabad.pptx
Pre Engineered  Building Manufacturers Hyderabad.pptxPre Engineered  Building Manufacturers Hyderabad.pptx
Pre Engineered Building Manufacturers Hyderabad.pptx
 
Paradip CALL GIRL❤7091819311❤CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDING
Paradip CALL GIRL❤7091819311❤CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDINGParadip CALL GIRL❤7091819311❤CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDING
Paradip CALL GIRL❤7091819311❤CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDING
 
Structuring and Writing DRL Mckinsey (1).pdf
Structuring and Writing DRL Mckinsey (1).pdfStructuring and Writing DRL Mckinsey (1).pdf
Structuring and Writing DRL Mckinsey (1).pdf
 
Unveiling Falcon Invoice Discounting: Leading the Way as India's Premier Bill...
Unveiling Falcon Invoice Discounting: Leading the Way as India's Premier Bill...Unveiling Falcon Invoice Discounting: Leading the Way as India's Premier Bill...
Unveiling Falcon Invoice Discounting: Leading the Way as India's Premier Bill...
 
Falcon Invoice Discounting: The best investment platform in india for investors
Falcon Invoice Discounting: The best investment platform in india for investorsFalcon Invoice Discounting: The best investment platform in india for investors
Falcon Invoice Discounting: The best investment platform in india for investors
 
unwanted pregnancy Kit [+918133066128] Abortion Pills IN Dubai UAE Abudhabi
unwanted pregnancy Kit [+918133066128] Abortion Pills IN Dubai UAE Abudhabiunwanted pregnancy Kit [+918133066128] Abortion Pills IN Dubai UAE Abudhabi
unwanted pregnancy Kit [+918133066128] Abortion Pills IN Dubai UAE Abudhabi
 
joint cost.pptx COST ACCOUNTING Sixteenth Edition ...
joint cost.pptx  COST ACCOUNTING  Sixteenth Edition                          ...joint cost.pptx  COST ACCOUNTING  Sixteenth Edition                          ...
joint cost.pptx COST ACCOUNTING Sixteenth Edition ...
 
Organizational Transformation Lead with Culture
Organizational Transformation Lead with CultureOrganizational Transformation Lead with Culture
Organizational Transformation Lead with Culture
 
Mifty kit IN Salmiya (+918133066128) Abortion pills IN Salmiyah Cytotec pills
Mifty kit IN Salmiya (+918133066128) Abortion pills IN Salmiyah Cytotec pillsMifty kit IN Salmiya (+918133066128) Abortion pills IN Salmiyah Cytotec pills
Mifty kit IN Salmiya (+918133066128) Abortion pills IN Salmiyah Cytotec pills
 
BeMetals Investor Presentation_May 3, 2024.pdf
BeMetals Investor Presentation_May 3, 2024.pdfBeMetals Investor Presentation_May 3, 2024.pdf
BeMetals Investor Presentation_May 3, 2024.pdf
 
Falcon Invoice Discounting: Empowering Your Business Growth
Falcon Invoice Discounting: Empowering Your Business GrowthFalcon Invoice Discounting: Empowering Your Business Growth
Falcon Invoice Discounting: Empowering Your Business Growth
 
PHX May 2024 Corporate Presentation Final
PHX May 2024 Corporate Presentation FinalPHX May 2024 Corporate Presentation Final
PHX May 2024 Corporate Presentation Final
 
Falcon Invoice Discounting: Unlock Your Business Potential
Falcon Invoice Discounting: Unlock Your Business PotentialFalcon Invoice Discounting: Unlock Your Business Potential
Falcon Invoice Discounting: Unlock Your Business Potential
 
Phases of Negotiation .pptx
 Phases of Negotiation .pptx Phases of Negotiation .pptx
Phases of Negotiation .pptx
 
TVB_The Vietnam Believer Newsletter_May 6th, 2024_ENVol. 006.pdf
TVB_The Vietnam Believer Newsletter_May 6th, 2024_ENVol. 006.pdfTVB_The Vietnam Believer Newsletter_May 6th, 2024_ENVol. 006.pdf
TVB_The Vietnam Believer Newsletter_May 6th, 2024_ENVol. 006.pdf
 
Arti Languages Pre Seed Teaser Deck 2024.pdf
Arti Languages Pre Seed Teaser Deck 2024.pdfArti Languages Pre Seed Teaser Deck 2024.pdf
Arti Languages Pre Seed Teaser Deck 2024.pdf
 
Lucknow Housewife Escorts by Sexy Bhabhi Service 8250092165
Lucknow Housewife Escorts  by Sexy Bhabhi Service 8250092165Lucknow Housewife Escorts  by Sexy Bhabhi Service 8250092165
Lucknow Housewife Escorts by Sexy Bhabhi Service 8250092165
 
Dr. Admir Softic_ presentation_Green Club_ENG.pdf
Dr. Admir Softic_ presentation_Green Club_ENG.pdfDr. Admir Softic_ presentation_Green Club_ENG.pdf
Dr. Admir Softic_ presentation_Green Club_ENG.pdf
 

Os Gopal

  • 1. Cache That! Gopal Vijayaraghavan Yahoo Inc. gopalv@php.net July 26th, 2007
  • 2. Cache ? Why ? - Easiest optimisation you could do - Maximum return on work invested - Hopefully transparent - Probably doesn't need a complete redesign - especially of business logic - Tradeoff between speed and accuracy - 80+% of Web content is not mission critical - scale is more important
  • 4. Sandwich Theory - Pages are dynamic - Like a sandwich made to order. - The whole page is built to order, but bits of content require varying “freshness” - A jar of pre-cut olives are the next best thing after Sliced Bread
  • 5. “fast”: latency & throughput http://flickr.com/photos/brtsergio/184026033/
  • 6. Cache: strategies and levels - Browser land - Content proxying - Pre-generating content - Active data caching - Backend caches
  • 7. So, what's this talk about ? http://flickr.com/photos/frogmuseum2/238601344
  • 8. Common Sense: Repeated - Browser caches ? - DNS, Expires:, Cache-Control: - Squid reverse proxies ? - Ad-hoc semi-static content - Content pre-gen ? - RSS feeds & other periodically updated content - Backend caches ? - DB query caches, disk/OS caches
  • 9. Active Data Caching - We're actually in PHP land now - Two main cache tools - APC - Memcache - APC is php specific - Memcached is more generic and distributed
  • 11. Red or Blue ? - APC - Memcached - Single server - Distributed - Stores arrays as-is - needs serialization - small data - large data safe - data churn causes - handles data churn issues better - Does opcodes too - Only data
  • 12. APC: Opcode Cache - Drop-in & use - Prevents disk access & syscalls - Is really old Hat, now - Tuning & tweaking - nostat mode - include_once_override - locking modes
  • 13. Tuning APC – check list - You need to tweak APC if you've got - a large number of files (> 1024) - a large cache footprint (> 64 M) - a mess of include_onces - a highly OOP design - very static php files - rsync and inode re-use
  • 14. APC Tuneables - apc.ini - apc.shm_size (64 M) - apc.num_files_hint (512) - apc.stat (On) - apc.stat_ctime (Off) - apc.include_once_override (Off) - apc.filters () - apc.localcache (Off)
  • 15. APC monitoring - Monitor APC using the apc.php in the pkg - Provides basic information about - memory usage - fragmentation - cache request/insert rates - user and file - expunge/cache-full count
  • 16. Tune your Code - #I - Reduce include/include_once calls - Template & stitch - R3 (http://rthree.sf.net/) - Use full include paths - include(“./z.php); instead of include(“z.php”); - Use constant includes - don't wrap include with your functions - Avoid eval() at all costs
  • 19. APC: var_export gotchas - PHP opcodes are cached in APC - So, putting a constant array on a file seems OK - But here's the “constant” array in PHP line # op ext operands ------------------------------------------------------- 2 0 INIT_ARRAY ~0, 'z', 'x' 3 1 ADD_ARRAY_ELEMENT ~0, 'b', 'a' 4 2 ADD_ARRAY_ELEMENT ~0, 'c', 'b' 5 3 ADD_ARRAY_ELEMENT ~0, 'd', 'c' 4 ASSIGN !0, ~0 7 5 RETURN 1 6 ZEND_HANDLE_EXCEPTION
  • 20. APC: Dynamic Style - apc_fetch()/apc_store() - The interface is simple enough if(!($data = apc_fetch('data'))) { $data = array( .... ); apc_store('data', $data); } - But with a Time To Live (TTL) setting, data expires
  • 21. Lies, Damned Lies & Statistics http://flickr.com/photos/matthijs/82616861/
  • 22. APC vs Files Writes Reads file + includes 17809 1856348.5 file + serialized arrays 13804 517380.2 apc 98586 359790.3 Read/Write performance * Less time means better Includes Read Write Serialized APC 0.00 500000.00 1000000.00 1500000.00 2000000.00 http://pooteeweet.org/blog/721
  • 23. APC vs Files - Serialized arrays are the fastest to write to - APC is the slowest to write to, but the fastest to read from - Disk files with arrays lose out on both fronts - But then why would you ever use files ? - Because they expire gracefully, that's why - So, what happens when a cache entry expires ?
  • 24. Tune your Code - II - Use APC user cache - WPcache2, smarty_cache_apc - Re-order your nested lookups - NO: $a = apc_fetch(“foo”); echo $a[“baz”]; - YES: $a = apc_fetch(“foo.baz”); echo $a; - Avoid data race conditions - shouldn't I fix the race conditions ?
  • 25. Anatomy of a Cache Slam
  • 26. What works (or has worked) - Give it more (virtual) memory to burn - Use APC user cache for infrequently updated data - Update your APC cache out of band - Cron & Curl are APC's friends - Always check your APC info for - cache full count - fragmentation
  • 27. Thank you for listening - Resources - http://pecl.php.net/package/APC - http://pecl.php.net/package/memcache - Slides - http://t3.dotgnu.info/slides/oscon07.pdf - My Blog - http://t3.dotgnu.info/blog/php/