Upload
ford-antitrust
View
3.165
Download
3
Tags:
Embed Size (px)
DESCRIPTION
/* pOrt80BKK */ - PHP Day - PHP Performance with APC + Memcached for Windows
Citation preview
<?PHP Performance ?> w/APC + Memcached
for Windows
@FordAntiTrust
thaicyberpoint.com
thaithinkpad.com
thaihi5.com
Cache Theory ?
Cache Theory ?
Req
Output
Cache
Compute Miss
Hit Store
Check 1
2
3 4
Miss - [Store] - Hit
Type ?
http://ralphlosey.files.wordpress.com/2007/06/ram.jpg
http://www.pctechguide.com/images/31HardDrive.jpg
Fast Slow
APC ?
Alternative PHP Cache
Code not changes request and Simply Installation
Opcode Cache and Variables Cache
Automatic update w/code changes
Free & Open Source
PHP Flow
• Scanning and Lexing (Plain Text to Tokens)
• Parsing (Tokens to Expressions)
• Compilation (Translated Expressions to Opcode)
• Execution (Opcode stacks are processed)
Req
Output
• Scanning • Lexing • Parsing • Compilation
Execution
Normal PHP vs APC
Normal PHP vs APC
Req
Output
• Scanning • Lexing • Parsing • Compilation
Execution
Normal PHP vs APC
Req
Output
Opcode cache
• Scanning • Lexing • Parsing • Compilation
APC hook
APC hook
Execution
Miss
Hit
Store
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
• Basic PECL
(http://pecl.php.net)
– pecl install apc
Conf
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 (mean, across all concurrent requests)
203.541 [ms] 65.762 [ms]
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
APC Memcached
Instance Memcached Instance Memcached
Instance Memcached Instance
Web Server
Master Slave
Cache Reverse
Proxy
I
n
t
e
r
n
e
t
DB
Session
Memcached Instance Memcached
Instance Memcached Instance Memcached
Instance
Files
Memcached Instance Memcached
Instance Memcached Instance CDN/DFS
PHP Web App
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:\memcached\memcached.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
Output
Memcached
Files Cache Compute
1. Check 2. Miss
3. Store 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