Download presentation
Presentation is loading. Please wait.
Published byJunior Carroll Modified over 9 years ago
1
PHP Performance w/APC + Memcached @FordAntiTrust thaicyberpoint.com thaithinkpad.com thaihi5.com
2
Cache Theory ?
3
Req Output Cache Compute Miss Hit Store Check 1 1 2 2 3 3 4 4 Miss - [Store] - Hit
4
Type ? http://ralphlosey.files.wordpress.com/2007/06/ram.jpg http://www.pctechguide.com/images/31HardDrive.jpg FastSlow
5
APC ? Alternative PHP Cache
6
Code not changes request Opcode Cache and Variables Cache Automatic update w/code changes
7
Free & Open Source
8
Simply Installation
9
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 Scanning Lexing Parsing Compilation Execution
10
Normal PHP vs APC
11
Req Output Scanning Lexing Parsing Compilation Scanning Lexing Parsing Compilation Execution
12
Normal PHP vs APC Req Output Opcode cache Opcode cache Scanning Lexing Parsing Compilation Scanning Lexing Parsing Compilation APC hook Execution Miss Hit Store
13
Installation Basic PECL (http://pecl.php.net) –pecl install apc Ubuntu –apt-get install php5-apc Windows (http://pecl4win.php.net) –extension=php_apc.dll Conf extension=apc.so apc.shm_segments=1 apc.shm_size=256 apc.optimization=0 apc.num_files_hint=2048 apc.ttl=3600 apc.user_ttl=3600 apc.enable_cli=1 apc.max_file_size=1M extension=apc.so apc.shm_segments=1 apc.shm_size=256 apc.optimization=0 apc.num_files_hint=2048 apc.ttl=3600 apc.user_ttl=3600 apc.enable_cli=1 apc.max_file_size=1M
15
Benchmark PHP NativePHP w/APC Concurrency Level10 Time taken for tests60 seconds Complete requests 298914 Total transferred 643,149 bytes1,962,675 bytes HTML transferred 516,971 bytes1,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] received31.88 [KB/s] received
16
Memcached
17
History “Developed by Danga Interactive for LiveJournal.com”
18
Memcached ? a distributed memory object caching system with hash table
19
Memcached ? a distributed memory object caching system with hash table
20
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
21
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
22
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
23
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
24
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
25
Limits (c/Hash Table) Key : max 250 chars. Values: max 1MB
27
“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
28
Architecture practical ? http://barry.files.wordpress.com/2007/04/new-servers-back-04-2007.jpg
29
Architecture practical ? http://blog.thinkdiff.net/?p=419 “designing & implementing scalable applications with memcached and mysql”
31
Architecture practical ? http://blog.thinkdiff.net/wp-content/uploads/2009/02/memcache_22-02-2009.png
32
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();
33
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
34
code optimization is best
35
Discussion Q&A
36
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
37
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/
38
Thank you @FordAntiTrust http://www.slideshare.net/FordAntiTrust
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.