SlideShare a Scribd company logo
<?PHP Performance ?>
                       w/APC + Memcached
                              for Windows

@FordAntiTrust
thaicyberpoint.com
thaithinkpad.com
thaihi5.com
Cache Theory ?
Cache Theory ?

             Req
                               1 Check

                      2 Miss
        Compute

                   Store 3        Cache
     4 Hit
         Output

                     Miss - [Store] - Hit
Type ?
                    Fast                                Slow




http://ralphlosey.files.wordpress.com/2007/06/ram.jpg
http://www.pctechguide.com/images/31HardDrive.jpg
APC ?

Alternative PHP Cache
Opcode Cache and Variables Cache




            Automatic update w/code changes




Code not changes request and Simply Installation
Free & Open Source
PHP Flow
                                             Req
• Scanning and Lexing
  (Plain Text to Tokens)

• Parsing                              • Scanning
                                       • Lexing
  (Tokens to Expressions)              • Parsing
                                       • Compilation
• Compilation
  (Translated Expressions to Opcode)

• Execution                             Execution
  (Opcode stacks are processed)

                                          Output
Normal PHP vs APC
Normal PHP vs APC
                  Req


            • Scanning
            • Lexing
            • Parsing
            • Compilation




             Execution


               Output
Normal PHP vs APC
             Req

           APC hook

       • Scanning
       • Lexing
       • Parsing           Miss
       • Compilation
           APC hook    Store      Opcode
                                   cache
        Execution
                           Hit

          Output
Why ?
Why ?




        http://ralphschindler.com/
Why ?




        http://ralphschindler.com/
Installation
• Windows (http://downloads.php.net/pierre/)
  – extension=php_apc.dll
Installation
• Windows (http://downloads.php.net/pierre/)
  – extension=php_apc.dll
• Basic PECL
  (http://pecl.php.net)
  – pecl install apc
Installation
• Windows (http://downloads.php.net/pierre/)
  – extension=php_apc.dll
                            Conf
• Basic PECL
  (http://pecl.php.net)
  – pecl install apc
Benchmark
                                         PHP Native               PHP w/APC
Concurrency Level                                                10
Time taken for tests                                       60 seconds
Complete requests                        298                      914

Total transferred                        643,149 bytes            1,962,675 bytes

HTML transferred                         516,971 bytes            1,582,035 bytes

Requests per second                      4.91 [#/sec] (mean)      15.21 [#/sec] (mean)

Time per request                         2035.405 [ms] (mean)     657.623 [ms] (mean)

Time per request                         203.541 [ms]             65.762 [ms]
(mean, across all concurrent requests)
Transfer rate                            10.35 [KB/s] received    31.88 [KB/s] received
Memcached
History



    “Developed by Danga Interactive for
             LiveJournal.com”
Memcached ?
• a distributed memory object caching system
  with hash table
Memcached ?
• a distributed memory object caching system
  with hash table
Memcached ?
• a distributed memory object caching system
  with hash table
• a generic two stage hashing system (clients
  and servers). Clients are written for specific
  application languages. Server is written in C
Memcached ?
• a distributed memory object caching system
  with hash table
• a generic two stage hashing system (clients
  and servers). Clients are written for specific
  application languages. Server is written in C
Memcached ?
• a distributed memory object caching system
  with hash table
• a generic two stage hashing system (clients
  and servers). Clients are written for specific
  application languages. Server is written in C
• 85% of top 20 sites use memcached; 50%+ of
  top 5k sites uses Memcached
Memcached ?
• a distributed memory object caching system
  with hash table
• a generic two stage hashing system (clients
  and servers). Clients are written for specific
  application languages. Server is written in C
• 85% of top 20 sites use memcached; 50%+ of
  top 5k sites uses Memcached
Limits (c/Hash Table)
• Key : max 250 chars.
• Values: max 1MB
Why Memcached ?
• Scale-out
  – Machine
  – Process (Use different ports)
• Memory faster than Disk
• Allows for efficient use of your database
• Can utilize existing network
  – Uses non-blocking network I/O (TCP/IP)
• Very flexible
• Client libraries in all major languages
“We use more than 800 servers supplying over
     28 terabytes of memory to our users.”

     “total throughput achieved is 300,000 UDP req/s”
                                       by Paul Saab Saturday, December 13, 2008 at 2:43am
 •   8-core machines
 •   20-30% CPU usage.
 •   scale memcached to 8 threads on an 8-core system
 •   moved to UDP for get operations to reduce network traffic


http://www.facebook.com/note.php?note_id=39391378919
Architecture practical ?




http://barry.files.wordpress.com/2007/04/new-servers-back-04-2007.jpg
Cache
                   Memcached
     APC            Memcached
                    Instance                 Reverse
                      Memcached
                      Instance
                         Memcached
                        Instance              Proxy
                          Instance
                                                                            I
                                                                            n
                                                                            t
                                                                            e
     PHP Web App
                                             Web Server                     r
                                                                            n
                                                                            e
                                       Session                      Files
                                                                            t
                           Memcached               Memcached
                            Memcached
                            Instance                Memcached
                                                    Instance
 Master    Slave              Memcached
                              Instance                Memcached
                                                      Instance
                                 Memcached
                                Instance                Instance
                                                          CDN/DFS
                                  Instance
DB
Installation & Used
memcached binary packages
• http://labs.northscale.com/memcached-packages/

1.   Unzip into a directory of choice
2.   Open the shell of your choice (i.e. cmd.exe); cd into the directory
3.   Run memcached.exe passing standard arguments.


Sample
C:memcachedmemcached.exe -m 128 -p 11211 -l 127.0.0.1 -d
PHP Session w/Memcached
session.save_handler = files
session.save_path = “C:/Windows/temp”

TO

session.save_handler = memcache
session.save_path = “tcp://server:port “

OR

ini_set('session.save_handler', 'memcache');
ini_set('session.save_path', 'tcp://server:port,tcp://server:port');
Coding ? (in PHP)
/* OO API */
$memcacheObj = new Memcache;
$memcacheObj->connect('memcache_host', 11211);

/* set */
$memcacheObj->set('key', 'data', MEMCACHE_COMPRESSED, 50);
/ * get w/single key */
$var = $memcacheObj->get('key');
/ * get w/multiple key */
$var = $memcacheObj->get(array('key1', 'key2'));

$memcacheObj->close();
CMS ?
• Drupal has Memcache API and Integration
  http://drupal.org/project/memcache
• Wordpress has object cache
  http://mohanjith.net/blog/2008/10/using-memcached-with-
  wordpress-object-cache.html
Tips
Two Level Caching with Zend_Cache

• Tagging System in Files Cache
• Memcached Key used Tagging System
Two Level Caching - Workflow

                 Req



 Compute       Files Cache

                                       Memcached




     Output

                        1. Check   3. Store
                        2. Miss    4. Hit
Implement with Zend_Cache
Used Two Level with Zend_Cache
Ref.
• Improving PHP Application Performance with APC
     http://www.slideshare.net/vortexau/improving-php-application-
     performance-with-apc-presentation
• PHP Accelerators : APC vs Zend vs XCache with Zend
  Framework
     http://blog.digitalstruct.com/2007/12/23/php-accelerators-apc-vs-zend-vs-
     xcache-with-zend-framework/
• Scaling with memcached
     http://www.slideshare.net/acme/scaling-with-memcached
• Gear6 and Scaling Website Performance: Caching Session and
  Profile Data with Memcached
     http://www.slideshare.net/gear6memcached/gear6-and-scaling-website-
     performance-caching-session-and-profile-data-with-memcached
Ref. (2)
• PHP: Memcache - Manual
  http://th.php.net/manual/en/book.memcache.php
• http://danga.com/memcached/
• http://pecl.php.net/package/memcache
• http://www.socialtext.net/memcached/
Discussion
   Q&A
Thank you
           @FordAntiTrust
http://www.slideshare.net/FordAntiTrust

More Related Content

What's hot

WE18_Performance_Up.ppt
WE18_Performance_Up.pptWE18_Performance_Up.ppt
WE18_Performance_Up.ppt
webhostingguy
 
[MathWorks] Versioning Infrastructure
[MathWorks] Versioning Infrastructure[MathWorks] Versioning Infrastructure
[MathWorks] Versioning Infrastructure
Perforce
 
WordPress Performance & Scalability
WordPress Performance & ScalabilityWordPress Performance & Scalability
WordPress Performance & Scalability
Joseph Scott
 
Php psr standard 2014 01-22
Php psr standard 2014 01-22Php psr standard 2014 01-22
Php psr standard 2014 01-22
Võ Duy Tuấn
 
J Ruby Whirlwind Tour
J Ruby Whirlwind TourJ Ruby Whirlwind Tour
J Ruby Whirlwind Tour
oscon2007
 

What's hot (20)

WE18_Performance_Up.ppt
WE18_Performance_Up.pptWE18_Performance_Up.ppt
WE18_Performance_Up.ppt
 
are available here
are available hereare available here
are available here
 
[MathWorks] Versioning Infrastructure
[MathWorks] Versioning Infrastructure[MathWorks] Versioning Infrastructure
[MathWorks] Versioning Infrastructure
 
Performance_Up.ppt
Performance_Up.pptPerformance_Up.ppt
Performance_Up.ppt
 
WordPress Performance & Scalability
WordPress Performance & ScalabilityWordPress Performance & Scalability
WordPress Performance & Scalability
 
Apache Performance Tuning: Scaling Up
Apache Performance Tuning: Scaling UpApache Performance Tuning: Scaling Up
Apache Performance Tuning: Scaling Up
 
Nginx Internals
Nginx InternalsNginx Internals
Nginx Internals
 
Web Server Load Balancer
Web Server Load BalancerWeb Server Load Balancer
Web Server Load Balancer
 
Supercharging your PHP pages with mod_lsapi in CloudLinux OS
Supercharging your PHP pages with mod_lsapi in CloudLinux OSSupercharging your PHP pages with mod_lsapi in CloudLinux OS
Supercharging your PHP pages with mod_lsapi in CloudLinux OS
 
ReplacingSquidWithATS
ReplacingSquidWithATSReplacingSquidWithATS
ReplacingSquidWithATS
 
Apache Traffic Server & Lua
Apache Traffic Server & LuaApache Traffic Server & Lua
Apache Traffic Server & Lua
 
NginX - good practices, tips and advanced techniques
NginX - good practices, tips and advanced techniquesNginX - good practices, tips and advanced techniques
NginX - good practices, tips and advanced techniques
 
Memcached B box presentation
Memcached B box presentationMemcached B box presentation
Memcached B box presentation
 
Fastest Servlets in the West
Fastest Servlets in the WestFastest Servlets in the West
Fastest Servlets in the West
 
Os Harkins
Os HarkinsOs Harkins
Os Harkins
 
Apache httpd 2.4: The Cloud Killer App
Apache httpd 2.4: The Cloud Killer AppApache httpd 2.4: The Cloud Killer App
Apache httpd 2.4: The Cloud Killer App
 
Php psr standard 2014 01-22
Php psr standard 2014 01-22Php psr standard 2014 01-22
Php psr standard 2014 01-22
 
J Ruby Whirlwind Tour
J Ruby Whirlwind TourJ Ruby Whirlwind Tour
J Ruby Whirlwind Tour
 
Zendcon scaling magento
Zendcon scaling magentoZendcon scaling magento
Zendcon scaling magento
 
MNPHP Scalable Architecture 101 - Feb 3 2011
MNPHP Scalable Architecture 101 - Feb 3 2011MNPHP Scalable Architecture 101 - Feb 3 2011
MNPHP Scalable Architecture 101 - Feb 3 2011
 

Similar to /* pOrt80BKK */ - PHP Day - PHP Performance with APC + Memcached for Windows

Host and Boast: Best Practices for Magento Hosting | Imagine 2013 Technolog…
Host and Boast: Best Practices for Magento Hosting | Imagine 2013 Technolog…Host and Boast: Best Practices for Magento Hosting | Imagine 2013 Technolog…
Host and Boast: Best Practices for Magento Hosting | Imagine 2013 Technolog…
Atwix
 
Site Performance - From Pinto to Ferrari
Site Performance - From Pinto to FerrariSite Performance - From Pinto to Ferrari
Site Performance - From Pinto to Ferrari
Joseph Scott
 
Memcached, presented to LCA2010
Memcached, presented to LCA2010Memcached, presented to LCA2010
Memcached, presented to LCA2010
Mark Atwood
 
Dutch php conference_2010_opm
Dutch php conference_2010_opmDutch php conference_2010_opm
Dutch php conference_2010_opm
isnull
 

Similar to /* pOrt80BKK */ - PHP Day - PHP Performance with APC + Memcached for Windows (20)

Host and Boast: Best Practices for Magento Hosting | Imagine 2013 Technolog…
Host and Boast: Best Practices for Magento Hosting | Imagine 2013 Technolog…Host and Boast: Best Practices for Magento Hosting | Imagine 2013 Technolog…
Host and Boast: Best Practices for Magento Hosting | Imagine 2013 Technolog…
 
php & performance
 php & performance php & performance
php & performance
 
PHP & Performance
PHP & PerformancePHP & Performance
PHP & Performance
 
Site Performance - From Pinto to Ferrari
Site Performance - From Pinto to FerrariSite Performance - From Pinto to Ferrari
Site Performance - From Pinto to Ferrari
 
Introduction to memcached
Introduction to memcachedIntroduction to memcached
Introduction to memcached
 
Northeast PHP - High Performance PHP
Northeast PHP - High Performance PHPNortheast PHP - High Performance PHP
Northeast PHP - High Performance PHP
 
EVCache & Moneta (GoSF)
EVCache & Moneta (GoSF)EVCache & Moneta (GoSF)
EVCache & Moneta (GoSF)
 
Memcached, presented to LCA2010
Memcached, presented to LCA2010Memcached, presented to LCA2010
Memcached, presented to LCA2010
 
Nginx pres
Nginx presNginx pres
Nginx pres
 
WebCamp 2016: PHP.Алексей Петров.PHP at Scale: System Architect Toolbox
WebCamp 2016: PHP.Алексей Петров.PHP at Scale: System Architect ToolboxWebCamp 2016: PHP.Алексей Петров.PHP at Scale: System Architect Toolbox
WebCamp 2016: PHP.Алексей Петров.PHP at Scale: System Architect Toolbox
 
Qcon
QconQcon
Qcon
 
Full Stack Load Testing
Full Stack Load Testing Full Stack Load Testing
Full Stack Load Testing
 
Dutch php conference_2010_opm
Dutch php conference_2010_opmDutch php conference_2010_opm
Dutch php conference_2010_opm
 
EVCache Builderscon
EVCache BuildersconEVCache Builderscon
EVCache Builderscon
 
PostgreSQL Query Cache - "pqc"
PostgreSQL Query Cache - "pqc"PostgreSQL Query Cache - "pqc"
PostgreSQL Query Cache - "pqc"
 
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
 
EECI 2013 - ExpressionEngine Performance & Optimization - Laying a Solid Foun...
EECI 2013 - ExpressionEngine Performance & Optimization - Laying a Solid Foun...EECI 2013 - ExpressionEngine Performance & Optimization - Laying a Solid Foun...
EECI 2013 - ExpressionEngine Performance & Optimization - Laying a Solid Foun...
 
A Tale of 2 Systems
A Tale of 2 SystemsA Tale of 2 Systems
A Tale of 2 Systems
 
Application Caching: The Hidden Microservice (SAConf)
Application Caching: The Hidden Microservice (SAConf)Application Caching: The Hidden Microservice (SAConf)
Application Caching: The Hidden Microservice (SAConf)
 
High Performance Drupal Sites
High Performance Drupal SitesHigh Performance Drupal Sites
High Performance Drupal Sites
 

More from Ford AntiTrust (9)

Google calendar
Google calendarGoogle calendar
Google calendar
 
Qbasic
QbasicQbasic
Qbasic
 
Drupal in the Cloud with Windows Azure
Drupal in the Cloud with Windows AzureDrupal in the Cloud with Windows Azure
Drupal in the Cloud with Windows Azure
 
Web Design, Running A Website And Hosting
Web Design, Running A Website And HostingWeb Design, Running A Website And Hosting
Web Design, Running A Website And Hosting
 
PHP Hoffman Framework (HMF) at Barcamp Bangkok 2
PHP Hoffman Framework(HMF) at Barcamp Bangkok 2PHP Hoffman Framework(HMF) at Barcamp Bangkok 2
PHP Hoffman Framework (HMF) at Barcamp Bangkok 2
 
GoOO->PHP [5] at Barcamp Bangkok 2
GoOO->PHP [5]  at Barcamp Bangkok 2GoOO->PHP [5]  at Barcamp Bangkok 2
GoOO->PHP [5] at Barcamp Bangkok 2
 
MySQL Tuning
MySQL TuningMySQL Tuning
MySQL Tuning
 
PHP on AJAX
PHP on AJAXPHP on AJAX
PHP on AJAX
 
PHP Hoffman Framework
PHP Hoffman FrameworkPHP Hoffman Framework
PHP Hoffman Framework
 

Recently uploaded

Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Peter Udo Diehl
 

Recently uploaded (20)

AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
The architecture of Generative AI for enterprises.pdf
The architecture of Generative AI for enterprises.pdfThe architecture of Generative AI for enterprises.pdf
The architecture of Generative AI for enterprises.pdf
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
IESVE for Early Stage Design and Planning
IESVE for Early Stage Design and PlanningIESVE for Early Stage Design and Planning
IESVE for Early Stage Design and Planning
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi IbrahimzadeFree and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1
 
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptxWSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
 
IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
 
PLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. StartupsPLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. Startups
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 

/* pOrt80BKK */ - PHP Day - PHP Performance with APC + Memcached for Windows

  • 1. <?PHP Performance ?> w/APC + Memcached for Windows @FordAntiTrust thaicyberpoint.com thaithinkpad.com thaihi5.com
  • 3. Cache Theory ? Req 1 Check 2 Miss Compute Store 3 Cache 4 Hit Output Miss - [Store] - Hit
  • 4. Type ? Fast Slow http://ralphlosey.files.wordpress.com/2007/06/ram.jpg http://www.pctechguide.com/images/31HardDrive.jpg
  • 6. Opcode Cache and Variables Cache Automatic update w/code changes Code not changes request and Simply Installation
  • 7. Free & Open Source
  • 8. PHP Flow Req • Scanning and Lexing (Plain Text to Tokens) • Parsing • Scanning • Lexing (Tokens to Expressions) • Parsing • Compilation • Compilation (Translated Expressions to Opcode) • Execution Execution (Opcode stacks are processed) Output
  • 10. Normal PHP vs APC Req • Scanning • Lexing • Parsing • Compilation Execution Output
  • 11. Normal PHP vs APC Req APC hook • Scanning • Lexing • Parsing Miss • Compilation APC hook Store Opcode cache Execution Hit Output
  • 12. Why ?
  • 13. Why ? http://ralphschindler.com/
  • 14. Why ? http://ralphschindler.com/
  • 16. Installation • Windows (http://downloads.php.net/pierre/) – extension=php_apc.dll • Basic PECL (http://pecl.php.net) – pecl install apc
  • 17. Installation • Windows (http://downloads.php.net/pierre/) – extension=php_apc.dll Conf • Basic PECL (http://pecl.php.net) – pecl install apc
  • 18.
  • 19. Benchmark PHP Native PHP w/APC Concurrency Level 10 Time taken for tests 60 seconds Complete requests 298 914 Total transferred 643,149 bytes 1,962,675 bytes HTML transferred 516,971 bytes 1,582,035 bytes Requests per second 4.91 [#/sec] (mean) 15.21 [#/sec] (mean) Time per request 2035.405 [ms] (mean) 657.623 [ms] (mean) Time per request 203.541 [ms] 65.762 [ms] (mean, across all concurrent requests) Transfer rate 10.35 [KB/s] received 31.88 [KB/s] received
  • 21. History “Developed by Danga Interactive for LiveJournal.com”
  • 22. Memcached ? • a distributed memory object caching system with hash table
  • 23. Memcached ? • a distributed memory object caching system with hash table
  • 24. Memcached ? • a distributed memory object caching system with hash table • a generic two stage hashing system (clients and servers). Clients are written for specific application languages. Server is written in C
  • 25. Memcached ? • a distributed memory object caching system with hash table • a generic two stage hashing system (clients and servers). Clients are written for specific application languages. Server is written in C
  • 26. Memcached ? • a distributed memory object caching system with hash table • a generic two stage hashing system (clients and servers). Clients are written for specific application languages. Server is written in C • 85% of top 20 sites use memcached; 50%+ of top 5k sites uses Memcached
  • 27. Memcached ? • a distributed memory object caching system with hash table • a generic two stage hashing system (clients and servers). Clients are written for specific application languages. Server is written in C • 85% of top 20 sites use memcached; 50%+ of top 5k sites uses Memcached
  • 28. Limits (c/Hash Table) • Key : max 250 chars. • Values: max 1MB
  • 29. Why Memcached ? • Scale-out – Machine – Process (Use different ports) • Memory faster than Disk • Allows for efficient use of your database • Can utilize existing network – Uses non-blocking network I/O (TCP/IP) • Very flexible • Client libraries in all major languages
  • 30.
  • 31. “We use more than 800 servers supplying over 28 terabytes of memory to our users.” “total throughput achieved is 300,000 UDP req/s” by Paul Saab Saturday, December 13, 2008 at 2:43am • 8-core machines • 20-30% CPU usage. • scale memcached to 8 threads on an 8-core system • moved to UDP for get operations to reduce network traffic http://www.facebook.com/note.php?note_id=39391378919
  • 33. Cache Memcached APC Memcached Instance Reverse Memcached Instance Memcached Instance Proxy Instance I n t e PHP Web App Web Server r n e Session Files t Memcached Memcached Memcached Instance Memcached Instance Master Slave Memcached Instance Memcached Instance Memcached Instance Instance CDN/DFS Instance DB
  • 34. Installation & Used memcached binary packages • http://labs.northscale.com/memcached-packages/ 1. Unzip into a directory of choice 2. Open the shell of your choice (i.e. cmd.exe); cd into the directory 3. Run memcached.exe passing standard arguments. Sample C:memcachedmemcached.exe -m 128 -p 11211 -l 127.0.0.1 -d
  • 35. PHP Session w/Memcached session.save_handler = files session.save_path = “C:/Windows/temp” TO session.save_handler = memcache session.save_path = “tcp://server:port “ OR ini_set('session.save_handler', 'memcache'); ini_set('session.save_path', 'tcp://server:port,tcp://server:port');
  • 36. Coding ? (in PHP) /* OO API */ $memcacheObj = new Memcache; $memcacheObj->connect('memcache_host', 11211); /* set */ $memcacheObj->set('key', 'data', MEMCACHE_COMPRESSED, 50); / * get w/single key */ $var = $memcacheObj->get('key'); / * get w/multiple key */ $var = $memcacheObj->get(array('key1', 'key2')); $memcacheObj->close();
  • 37. CMS ? • Drupal has Memcache API and Integration http://drupal.org/project/memcache • Wordpress has object cache http://mohanjith.net/blog/2008/10/using-memcached-with- wordpress-object-cache.html
  • 38. Tips
  • 39. Two Level Caching with Zend_Cache • Tagging System in Files Cache • Memcached Key used Tagging System
  • 40. Two Level Caching - Workflow Req Compute Files Cache Memcached Output 1. Check 3. Store 2. Miss 4. Hit
  • 42. Used Two Level with Zend_Cache
  • 43. Ref. • Improving PHP Application Performance with APC http://www.slideshare.net/vortexau/improving-php-application- performance-with-apc-presentation • PHP Accelerators : APC vs Zend vs XCache with Zend Framework http://blog.digitalstruct.com/2007/12/23/php-accelerators-apc-vs-zend-vs- xcache-with-zend-framework/ • Scaling with memcached http://www.slideshare.net/acme/scaling-with-memcached • Gear6 and Scaling Website Performance: Caching Session and Profile Data with Memcached http://www.slideshare.net/gear6memcached/gear6-and-scaling-website- performance-caching-session-and-profile-data-with-memcached
  • 44. Ref. (2) • PHP: Memcache - Manual http://th.php.net/manual/en/book.memcache.php • http://danga.com/memcached/ • http://pecl.php.net/package/memcache • http://www.socialtext.net/memcached/
  • 45. Discussion Q&A
  • 46. Thank you @FordAntiTrust http://www.slideshare.net/FordAntiTrust