PHP Performance w/APC + Memcached @FordAntiTrust thaicyberpoint.com thaithinkpad.com thaihi5.com.

Click here to load reader

  • date post

    18-Jan-2016
  • Category

    Documents

  • view

    214
  • download

    2

Embed Size (px)

Transcript of PHP Performance w/APC + Memcached @FordAntiTrust thaicyberpoint.com thaithinkpad.com thaihi5.com.

PHP Performance APC + Memcached

PHP Performance w/APC + [email protected].comCache Theory ?Cache Theory ?ReqOutputCacheComputeMissHitStoreCheck1234Miss - [Store] - HitType ?http://ralphlosey.files.wordpress.com/2007/06/ram.jpg

http://www.pctechguide.com/images/31HardDrive.jpgFastSlowAPC ?Alternative PHP CacheCode not changes requestOpcode Cache and Variables CacheAutomatic update w/code changesFree & Open SourceSimply InstallationPHP FlowScanning and Lexing (Plain Text to Tokens)Parsing (Tokens to Expressions)Compilation (Translated Expressions to Opcode)Execution (Opcode stacks are processed)ReqOutput Scanning Lexing Parsing CompilationExecutionNormal PHP vs APCNormal PHP vs APCReqOutput Scanning Lexing Parsing CompilationExecutionNormal PHP vs APCReqOutputOpcodecache Scanning Lexing Parsing CompilationAPC hookAPC hookExecutionMissHitStoreInstallationBasic PECL (http://pecl.php.net)pecl install apcUbuntuapt-get install php5-apcWindows (http://pecl4win.php.net)extension=php_apc.dllConfextension=apc.soapc.shm_segments=1apc.shm_size=256apc.optimization=0apc.num_files_hint=2048apc.ttl=3600apc.user_ttl=3600apc.enable_cli=1apc.max_file_size=1M

BenchmarkPHP NativePHP w/APCConcurrency Level10Time taken for tests60 secondsComplete requests298914Total transferred643,149 bytes1,962,675 bytesHTML transferred516,971 bytes1,582,035 bytesRequests per second4.91 [#/sec] (mean)15.21 [#/sec] (mean)Time per request2035.405 [ms] (mean)657.623 [ms] (mean)Time per request(mean, across all concurrent requests)203.541 [ms] 65.762 [ms]Transfer rate10.35 [KB/s] received31.88 [KB/s] receivedMemcachedHistoryDeveloped by Danga Interactive for LiveJournal.comMemcached ?a distributed memory object caching system with hash tableMemcached ?a distributed memory object caching system with hash tableMemcached ?a distributed memory object caching system with hash tablea generic two stage hashing system (clients and servers). Clients are written for specific application languages. Server is written in CMemcached ?a distributed memory object caching system with hash tablea generic two stage hashing system (clients and servers). Clients are written for specific application languages. Server is written in CMemcached ?a distributed memory object caching system with hash tablea generic two stage hashing system (clients and servers). Clients are written for specific application languages. Server is written in C85% of top 20 sites use memcached; 50%+ of top 5k sites uses MemcachedMemcached ?a distributed memory object caching system with hash tablea generic two stage hashing system (clients and servers). Clients are written for specific application languages. Server is written in C85% of top 20 sites use memcached; 50%+ of top 5k sites uses MemcachedWhy Memcached ? Scale-outMachineProcess (Use different ports)Memory faster than DiskAllows for efficient use of your database Can utilize existing networkUses non-blocking network I/O (TCP/IP)Very flexibleClient libraries in all major languagesLimits (c/Hash Table)Key : max 250 chars.Values: max 1MB

We use more than 800 servers supplying over 28 terabytes of memory to our users.total throughput achieved is 300,000 UDP req/sby Paul Saab Saturday, December 13, 2008 at 2:43am8-core machines20-30% CPU usage.scale memcached to 8 threads on an 8-core systemmoved to UDP for get operations to reduce network traffichttp://www.facebook.com/note.php?note_id=39391378919

Architecture practical ?

http://barry.files.wordpress.com/2007/04/new-servers-back-04-2007.jpgArchitecture practical ?http://blog.thinkdiff.net/?p=419designing & implementing scalable applications with memcached and mysql

Architecture practical ?http://blog.thinkdiff.net/wp-content/uploads/2009/02/memcache_22-02-2009.png

Coding ? (in PHP)/*OOAPI*/$memcacheObj=newMemcache;$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 Integrationhttp://drupal.org/project/memcacheWordpress has object cachehttp://mohanjith.net/blog/2008/10/using-memcached-with-wordpress-object-cache.htmlcode optimization is bestDiscussionQ&ARef.Improving PHP Application Performance with APChttp://www.slideshare.net/vortexau/improving-php-application-performance-with-apc-presentationPHP Accelerators : APC vs Zend vs XCache with Zend Frameworkhttp://blog.digitalstruct.com/2007/12/23/php-accelerators-apc-vs-zend-vs-xcache-with-zend-framework/Scaling with memcachedhttp://www.slideshare.net/acme/scaling-with-memcachedGear6 and Scaling Website Performance: Caching Session and Profile Data with Memcachedhttp://www.slideshare.net/gear6memcached/gear6-and-scaling-website-performance-caching-session-and-profile-data-with-memcachedRef. (2)PHP: Memcache - Manualhttp://th.php.net/manual/en/book.memcache.phphttp://danga.com/memcached/http://pecl.php.net/package/memcachehttp://www.socialtext.net/memcached/Thank [email protected]://www.slideshare.net/FordAntiTrust