パフォーマンスの考え, 楽天09

パフォーマンスの考え, 楽天09 »
Brian Shire

Browser Cache
パフォーマンスの考え
Revision Control
Language Specific, Globals Cache Layer
APC
Memcache
CDN
Cache Busting
UserAgent Strings
Site Variables
Key Versioning
Cache Dispatching
Function Abstraction
String based serialization is slow, and consumes space
Caching Layers
Release Fast, Release Often
楽天 Rakuten
Brian Shire
shire@tekrat.com
http://tekrat.com
There's more than one cache layer
HTTP Server
Caching Server
Shared Memory Cache (like APC)
Language Specific Global Cache
Browser Cache
CDN
But multiple caching layers increases complexity...
Start with a good function abstraction for caching layers.
Refactor as necessary to meet performance and changing architecture.
Open Source Contributions
Management can be time consuming
But it's shared time with other contributors.
Support mechanism outside company
Attracts talent
Many eyes are better than a few
Other ideas...
Thanks!
Contact Information:
Brian Shire
shire@tekrat.com
http://tekrat.com
Questions/Discussion?
Push new code fixes often, multiple times per day if needed.
Global scope of language can be used as an additional cache layer.
Decreases fetch time for multiple requests for the same key.
function cache_get($id, $key, $apc=false) {
  if (isset($GLOBALS['CACHE']["$key:$id"])) {
    $cache = $GLOBALS['CACHE']["$key:$id"]));
    $hit = 1;
  } elseif ($apc && (($cache = apc_fetch("$key:$id")) !== false) {
    $hit = 1;
  } else {
    ... // fetch from memcached or other cache
    if ($apc) apc_store("$key:$id", $cache);
  }
  if ($hit) $GLOBALS['CACHE']["$key:$id"] = $cache;
    return $hit ? $cache : NULL;
  }
}
Example:
Useragent string parsing is inefficient in PHP
Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2
Cache parsed useragents in APC for the first 10 minutes
Hit rate of over 50%
Pear implementation available: PEAR::Net_Useragent_Detect_APC
Enable and Disable site features across all servers.
Configure product features.
Configure memcached cluster IPs.
Version memcached keys for invalidation.
shire@shirebook:~$ php<? echo serialize(array('this','is','an','array'));
a:4:{i:0;s:4:"this";i:1;s:2:"is";i:2;s:2:"an";i:3;s:5:"array";}
shire@shirebook:~$ php
<? binary_echo binary_serialize(array('this','is','an','array'));
\0x04\0x04this\0x00is\0x00an\x00array\0x00
63 bytes!
19 bytes!
Keys can be invalidated from the cache by including a version value in keys:
$key = "$prefix:v$version:$id";
"userdata:v101:10039877"
cache_get_multi($ids, <key>, <miss>,
  $apc,$pending=false, &$pending_arr);
cache_dispatch();
Combine requests for data from the same memcached server.
Up to 10% performance improvement.
Executed code while the kernel buffers the memcache response.
Content Delivery Network
Used heavily for ensuring fast static content delivery 
  of images/JS/CSS etc.
お絞りです。
熊です。
function get_static_suffix($file) {
  global $ROOT;
  if ($version = cache_get($file, ‘sv’, 1) === null) {
    $version = trim(shell_exec(“svn info $ROOT/$file 
                  | grep‘Changed Rev’ | cut -c 19-”));
    apc_store(“sv:$file”, $version);
  }
  return '?'.$version;
}
Combining SVN revision as part of static
suffix will force browser cache refresh
on updates.
Example:
締る ドアに ご注意下さい!
Use revision control for releases (both binary and source).
GIT allows more advanced control and management for patches
But at a cost of complexity, especially for new users.
GIT has excellent integration with SVN, a central SVN repository can still
be utilized by a local GIT installation.
Push larger new features on a weekly basis.
Distrubetd SSH (DSH) is great for executing commands on many servers.
(You'll need to develop something more robust for 5,000-10,000+ servers)
per Eric Steven Raymond
試
着
す
る
東京、日本、平成21
Create Wrapper Functions:
Cache key callback functions:
cache_get($id, <key>, <miss>, $apc, $timeout);
cache_get_multi($ids, <key>, <miss>, $apc);
function profile_key($id) {
  global $VERSION_SP; // primed site variable
  return “sp:$VERSION_SP:$id;
}
お好み焼きです。
ナルトです。

鋼の錬金術師です。
Usability
Performance
Efficiency
Plugin new models for
Performance Ideas
Tokyo
Japan
2009

Loading comments...

Please log in to add your comment.

Report abuse

More presentations by Brian Shire