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
/* pOrt80BKK */ - PHP Day - PHP Performance with APC + Memcached for Windows
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
/* pOrt80BKK */ - PHP Day - PHP Performance with APC + Memcached for Windows
“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

ODP
Apc presentation
ODP
Improving PHP Application Performance with APC
PPTX
PHP Performance with APC + Memcached
PDF
Caching with Memcached and APC
PPT
Velocity 2010 - ATS
PPT
Oscon 2010 - ATS
PPT
Apache Traffic Server
PPTX
Usenix lisa 2011
Apc presentation
Improving PHP Application Performance with APC
PHP Performance with APC + Memcached
Caching with Memcached and APC
Velocity 2010 - ATS
Oscon 2010 - ATS
Apache Traffic Server
Usenix lisa 2011

What's hot (20)

PPT
WE18_Performance_Up.ppt
PPT
are available here
PDF
[MathWorks] Versioning Infrastructure
PPT
Performance_Up.ppt
PDF
WordPress Performance & Scalability
PPTX
Apache Performance Tuning: Scaling Up
PDF
Nginx Internals
PPT
Web Server Load Balancer
PPTX
Supercharging your PHP pages with mod_lsapi in CloudLinux OS
PDF
ReplacingSquidWithATS
PDF
Apache Traffic Server & Lua
PDF
NginX - good practices, tips and advanced techniques
PPTX
Memcached B box presentation
PPTX
Fastest Servlets in the West
PDF
Os Harkins
ODP
Apache httpd 2.4: The Cloud Killer App
PPTX
Php psr standard 2014 01-22
PDF
J Ruby Whirlwind Tour
PPTX
Zendcon scaling magento
ODP
MNPHP Scalable Architecture 101 - Feb 3 2011
WE18_Performance_Up.ppt
are available here
[MathWorks] Versioning Infrastructure
Performance_Up.ppt
WordPress Performance & Scalability
Apache Performance Tuning: Scaling Up
Nginx Internals
Web Server Load Balancer
Supercharging your PHP pages with mod_lsapi in CloudLinux OS
ReplacingSquidWithATS
Apache Traffic Server & Lua
NginX - good practices, tips and advanced techniques
Memcached B box presentation
Fastest Servlets in the West
Os Harkins
Apache httpd 2.4: The Cloud Killer App
Php psr standard 2014 01-22
J Ruby Whirlwind Tour
Zendcon scaling magento
MNPHP Scalable Architecture 101 - Feb 3 2011
Ad

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

ZIP
Memcached, presented to LCA2010
KEY
Introduction to memcached
PDF
Facebook的缓存系统
PDF
4069180 Caching Performance Lessons From Facebook
PDF
The Native NDB Engine for Memcached
PDF
Dutch php conference_apc_mem2010
PDF
Apc Memcached Confoo 2011
PDF
Caching for Cash: Caching
PDF
Gear6 and Scaling Website Performance: Caching Session and Profile Data with...
KEY
Profiling php applications
ODP
Caching and tuning fun for high scalability
ZIP
All The Little Pieces
PDF
Gear6 Webinar - MySQL Scaling with Memcached
PDF
Give Your Site a Boost with Memcache
PDF
PDF
Solving the C20K Problem: PHP Performance and Scalability
PDF
Solving the C20K Problem: PHP Performance and Scalability
PDF
Bottom to Top Stack Optimization with LAMP
PDF
Bottom to Top Stack Optimization - CICON2011
PDF
Caching objects-in-memory
Memcached, presented to LCA2010
Introduction to memcached
Facebook的缓存系统
4069180 Caching Performance Lessons From Facebook
The Native NDB Engine for Memcached
Dutch php conference_apc_mem2010
Apc Memcached Confoo 2011
Caching for Cash: Caching
Gear6 and Scaling Website Performance: Caching Session and Profile Data with...
Profiling php applications
Caching and tuning fun for high scalability
All The Little Pieces
Gear6 Webinar - MySQL Scaling with Memcached
Give Your Site a Boost with Memcache
Solving the C20K Problem: PHP Performance and Scalability
Solving the C20K Problem: PHP Performance and Scalability
Bottom to Top Stack Optimization with LAMP
Bottom to Top Stack Optimization - CICON2011
Caching objects-in-memory
Ad

More from Ford AntiTrust (9)

PDF
Google calendar
PPT
PDF
Drupal in the Cloud with Windows Azure
PDF
Web Design, Running A Website And Hosting
PDF
PHP Hoffman Framework (HMF) at Barcamp Bangkok 2
PDF
GoOO->PHP [5] at Barcamp Bangkok 2
PDF
MySQL Tuning
PDF
PHP on AJAX
PPT
PHP Hoffman Framework
Google calendar
Drupal in the Cloud with Windows Azure
Web Design, Running A Website And Hosting
PHP Hoffman Framework (HMF) at Barcamp Bangkok 2
GoOO->PHP [5] at Barcamp Bangkok 2
MySQL Tuning
PHP on AJAX
PHP Hoffman Framework

Recently uploaded (20)

PDF
Network Security Unit 5.pdf for BCA BBA.
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
cuic standard and advanced reporting.pdf
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Empathic Computing: Creating Shared Understanding
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Encapsulation theory and applications.pdf
PPTX
sap open course for s4hana steps from ECC to s4
PPTX
Spectroscopy.pptx food analysis technology
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Approach and Philosophy of On baking technology
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PPTX
MYSQL Presentation for SQL database connectivity
Network Security Unit 5.pdf for BCA BBA.
“AI and Expert System Decision Support & Business Intelligence Systems”
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
cuic standard and advanced reporting.pdf
Building Integrated photovoltaic BIPV_UPV.pdf
Empathic Computing: Creating Shared Understanding
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Mobile App Security Testing_ A Comprehensive Guide.pdf
Encapsulation theory and applications.pdf
sap open course for s4hana steps from ECC to s4
Spectroscopy.pptx food analysis technology
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
20250228 LYD VKU AI Blended-Learning.pptx
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Programs and apps: productivity, graphics, security and other tools
Approach and Philosophy of On baking technology
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
MYSQL Presentation for SQL database connectivity

/* 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
  • 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
  • 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