SlideShare une entreprise Scribd logo
1  sur  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/

Contenu connexe

Tendances

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
 

Tendances (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
 

Similaire à 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
 

Similaire à 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
 

Plus de 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
 

Plus de 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
 

Dernier

Eluru Call Girls Service ☎ ️93326-06886 ❤️‍🔥 Enjoy 24/7 Escort Service
Eluru Call Girls Service ☎ ️93326-06886 ❤️‍🔥 Enjoy 24/7 Escort ServiceEluru Call Girls Service ☎ ️93326-06886 ❤️‍🔥 Enjoy 24/7 Escort Service
Eluru Call Girls Service ☎ ️93326-06886 ❤️‍🔥 Enjoy 24/7 Escort ServiceDamini Dixit
 
Call Girls In Majnu Ka Tilla 959961~3876 Shot 2000 Night 8000
Call Girls In Majnu Ka Tilla 959961~3876 Shot 2000 Night 8000Call Girls In Majnu Ka Tilla 959961~3876 Shot 2000 Night 8000
Call Girls In Majnu Ka Tilla 959961~3876 Shot 2000 Night 8000dlhescort
 
BAGALUR CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRL
BAGALUR CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRLBAGALUR CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRL
BAGALUR CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRLkapoorjyoti4444
 
Chandigarh Escorts Service 📞8868886958📞 Just📲 Call Nihal Chandigarh Call Girl...
Chandigarh Escorts Service 📞8868886958📞 Just📲 Call Nihal Chandigarh Call Girl...Chandigarh Escorts Service 📞8868886958📞 Just📲 Call Nihal Chandigarh Call Girl...
Chandigarh Escorts Service 📞8868886958📞 Just📲 Call Nihal Chandigarh Call Girl...Sheetaleventcompany
 
Malegaon Call Girls Service ☎ ️82500–77686 ☎️ Enjoy 24/7 Escort Service
Malegaon Call Girls Service ☎ ️82500–77686 ☎️ Enjoy 24/7 Escort ServiceMalegaon Call Girls Service ☎ ️82500–77686 ☎️ Enjoy 24/7 Escort Service
Malegaon Call Girls Service ☎ ️82500–77686 ☎️ Enjoy 24/7 Escort ServiceDamini Dixit
 
Call Girls Kengeri Satellite Town Just Call 👗 7737669865 👗 Top Class Call Gir...
Call Girls Kengeri Satellite Town Just Call 👗 7737669865 👗 Top Class Call Gir...Call Girls Kengeri Satellite Town Just Call 👗 7737669865 👗 Top Class Call Gir...
Call Girls Kengeri Satellite Town Just Call 👗 7737669865 👗 Top Class Call Gir...amitlee9823
 
SEO Case Study: How I Increased SEO Traffic & Ranking by 50-60% in 6 Months
SEO Case Study: How I Increased SEO Traffic & Ranking by 50-60%  in 6 MonthsSEO Case Study: How I Increased SEO Traffic & Ranking by 50-60%  in 6 Months
SEO Case Study: How I Increased SEO Traffic & Ranking by 50-60% in 6 MonthsIndeedSEO
 
Call Girls In Noida 959961⊹3876 Independent Escort Service Noida
Call Girls In Noida 959961⊹3876 Independent Escort Service NoidaCall Girls In Noida 959961⊹3876 Independent Escort Service Noida
Call Girls In Noida 959961⊹3876 Independent Escort Service Noidadlhescort
 
FULL ENJOY Call Girls In Majnu Ka Tilla, Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Majnu Ka Tilla, Delhi Contact Us 8377877756FULL ENJOY Call Girls In Majnu Ka Tilla, Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Majnu Ka Tilla, Delhi Contact Us 8377877756dollysharma2066
 
Falcon's Invoice Discounting: Your Path to Prosperity
Falcon's Invoice Discounting: Your Path to ProsperityFalcon's Invoice Discounting: Your Path to Prosperity
Falcon's Invoice Discounting: Your Path to Prosperityhemanthkumar470700
 
How to Get Started in Social Media for Art League City
How to Get Started in Social Media for Art League CityHow to Get Started in Social Media for Art League City
How to Get Started in Social Media for Art League CityEric T. Tung
 
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...amitlee9823
 
It will be International Nurses' Day on 12 May
It will be International Nurses' Day on 12 MayIt will be International Nurses' Day on 12 May
It will be International Nurses' Day on 12 MayNZSG
 
Mysore Call Girls 8617370543 WhatsApp Number 24x7 Best Services
Mysore Call Girls 8617370543 WhatsApp Number 24x7 Best ServicesMysore Call Girls 8617370543 WhatsApp Number 24x7 Best Services
Mysore Call Girls 8617370543 WhatsApp Number 24x7 Best ServicesDipal Arora
 
Famous Olympic Siblings from the 21st Century
Famous Olympic Siblings from the 21st CenturyFamous Olympic Siblings from the 21st Century
Famous Olympic Siblings from the 21st Centuryrwgiffor
 
Katrina Personal Brand Project and portfolio 1
Katrina Personal Brand Project and portfolio 1Katrina Personal Brand Project and portfolio 1
Katrina Personal Brand Project and portfolio 1kcpayne
 
Call Now ☎️🔝 9332606886🔝 Call Girls ❤ Service In Bhilwara Female Escorts Serv...
Call Now ☎️🔝 9332606886🔝 Call Girls ❤ Service In Bhilwara Female Escorts Serv...Call Now ☎️🔝 9332606886🔝 Call Girls ❤ Service In Bhilwara Female Escorts Serv...
Call Now ☎️🔝 9332606886🔝 Call Girls ❤ Service In Bhilwara Female Escorts Serv...Anamikakaur10
 
Cracking the Cultural Competence Code.pptx
Cracking the Cultural Competence Code.pptxCracking the Cultural Competence Code.pptx
Cracking the Cultural Competence Code.pptxWorkforce Group
 
Call Girls From Pari Chowk Greater Noida ❤️8448577510 ⊹Best Escorts Service I...
Call Girls From Pari Chowk Greater Noida ❤️8448577510 ⊹Best Escorts Service I...Call Girls From Pari Chowk Greater Noida ❤️8448577510 ⊹Best Escorts Service I...
Call Girls From Pari Chowk Greater Noida ❤️8448577510 ⊹Best Escorts Service I...lizamodels9
 

Dernier (20)

Eluru Call Girls Service ☎ ️93326-06886 ❤️‍🔥 Enjoy 24/7 Escort Service
Eluru Call Girls Service ☎ ️93326-06886 ❤️‍🔥 Enjoy 24/7 Escort ServiceEluru Call Girls Service ☎ ️93326-06886 ❤️‍🔥 Enjoy 24/7 Escort Service
Eluru Call Girls Service ☎ ️93326-06886 ❤️‍🔥 Enjoy 24/7 Escort Service
 
Call Girls In Majnu Ka Tilla 959961~3876 Shot 2000 Night 8000
Call Girls In Majnu Ka Tilla 959961~3876 Shot 2000 Night 8000Call Girls In Majnu Ka Tilla 959961~3876 Shot 2000 Night 8000
Call Girls In Majnu Ka Tilla 959961~3876 Shot 2000 Night 8000
 
BAGALUR CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRL
BAGALUR CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRLBAGALUR CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRL
BAGALUR CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRL
 
Chandigarh Escorts Service 📞8868886958📞 Just📲 Call Nihal Chandigarh Call Girl...
Chandigarh Escorts Service 📞8868886958📞 Just📲 Call Nihal Chandigarh Call Girl...Chandigarh Escorts Service 📞8868886958📞 Just📲 Call Nihal Chandigarh Call Girl...
Chandigarh Escorts Service 📞8868886958📞 Just📲 Call Nihal Chandigarh Call Girl...
 
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
 
Malegaon Call Girls Service ☎ ️82500–77686 ☎️ Enjoy 24/7 Escort Service
Malegaon Call Girls Service ☎ ️82500–77686 ☎️ Enjoy 24/7 Escort ServiceMalegaon Call Girls Service ☎ ️82500–77686 ☎️ Enjoy 24/7 Escort Service
Malegaon Call Girls Service ☎ ️82500–77686 ☎️ Enjoy 24/7 Escort Service
 
Call Girls Kengeri Satellite Town Just Call 👗 7737669865 👗 Top Class Call Gir...
Call Girls Kengeri Satellite Town Just Call 👗 7737669865 👗 Top Class Call Gir...Call Girls Kengeri Satellite Town Just Call 👗 7737669865 👗 Top Class Call Gir...
Call Girls Kengeri Satellite Town Just Call 👗 7737669865 👗 Top Class Call Gir...
 
SEO Case Study: How I Increased SEO Traffic & Ranking by 50-60% in 6 Months
SEO Case Study: How I Increased SEO Traffic & Ranking by 50-60%  in 6 MonthsSEO Case Study: How I Increased SEO Traffic & Ranking by 50-60%  in 6 Months
SEO Case Study: How I Increased SEO Traffic & Ranking by 50-60% in 6 Months
 
Call Girls In Noida 959961⊹3876 Independent Escort Service Noida
Call Girls In Noida 959961⊹3876 Independent Escort Service NoidaCall Girls In Noida 959961⊹3876 Independent Escort Service Noida
Call Girls In Noida 959961⊹3876 Independent Escort Service Noida
 
FULL ENJOY Call Girls In Majnu Ka Tilla, Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Majnu Ka Tilla, Delhi Contact Us 8377877756FULL ENJOY Call Girls In Majnu Ka Tilla, Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Majnu Ka Tilla, Delhi Contact Us 8377877756
 
Falcon's Invoice Discounting: Your Path to Prosperity
Falcon's Invoice Discounting: Your Path to ProsperityFalcon's Invoice Discounting: Your Path to Prosperity
Falcon's Invoice Discounting: Your Path to Prosperity
 
How to Get Started in Social Media for Art League City
How to Get Started in Social Media for Art League CityHow to Get Started in Social Media for Art League City
How to Get Started in Social Media for Art League City
 
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...
 
It will be International Nurses' Day on 12 May
It will be International Nurses' Day on 12 MayIt will be International Nurses' Day on 12 May
It will be International Nurses' Day on 12 May
 
Mysore Call Girls 8617370543 WhatsApp Number 24x7 Best Services
Mysore Call Girls 8617370543 WhatsApp Number 24x7 Best ServicesMysore Call Girls 8617370543 WhatsApp Number 24x7 Best Services
Mysore Call Girls 8617370543 WhatsApp Number 24x7 Best Services
 
Famous Olympic Siblings from the 21st Century
Famous Olympic Siblings from the 21st CenturyFamous Olympic Siblings from the 21st Century
Famous Olympic Siblings from the 21st Century
 
Katrina Personal Brand Project and portfolio 1
Katrina Personal Brand Project and portfolio 1Katrina Personal Brand Project and portfolio 1
Katrina Personal Brand Project and portfolio 1
 
Call Now ☎️🔝 9332606886🔝 Call Girls ❤ Service In Bhilwara Female Escorts Serv...
Call Now ☎️🔝 9332606886🔝 Call Girls ❤ Service In Bhilwara Female Escorts Serv...Call Now ☎️🔝 9332606886🔝 Call Girls ❤ Service In Bhilwara Female Escorts Serv...
Call Now ☎️🔝 9332606886🔝 Call Girls ❤ Service In Bhilwara Female Escorts Serv...
 
Cracking the Cultural Competence Code.pptx
Cracking the Cultural Competence Code.pptxCracking the Cultural Competence Code.pptx
Cracking the Cultural Competence Code.pptx
 
Call Girls From Pari Chowk Greater Noida ❤️8448577510 ⊹Best Escorts Service I...
Call Girls From Pari Chowk Greater Noida ❤️8448577510 ⊹Best Escorts Service I...Call Girls From Pari Chowk Greater Noida ❤️8448577510 ⊹Best Escorts Service I...
Call Girls From Pari Chowk Greater Noida ❤️8448577510 ⊹Best Escorts Service I...
 

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/