Memcached(pronunciation: mem-cache-dee.)是一套分散式的記憶體快取系統~ 這年頭實在是什麼都要分散式的~XD
尤其從Google的身上更是如此~Google File System、MapReduce、Bigtable... 全部都是分散式的..= ="(因為後兩者均架構在GFS之上)
根據memcached(wiki)上的解說~ 它原本是由「Danga Interactive」公司所為了開發「LiveJournal」而誕生的~ 它可以用在大部份database-driven的網站下~ (本部落格應該也要改用Memcached吧~ XD 有時間再說~),也就是說~ 我們可以快取一些經常要從資料庫抓出來的資料~ 然而它並沒有提供任何安全性或是認證的功能~ 換句話說~ Memcached需要被安置在防火牆的保護之下~ 而且許多大咖級的公司都有在用~ 像是YouTube、Digg、Wikipedia、Slashdot... Facebook更是用了超過800臺伺服器,並提供「28TB」級的記憶體來作為快取使用~ (心想Google應該更多..),重點~ 在UMD的一位Jimmy Lin助理教授~ 很快的就將它整合到Hadoop之中~ 還寫了份技術報告「Low-Latency, High-Throughput Access to Static Global Resources within the Hadoop Framework.」.. 真是先驅..Orz
關於安裝Memcached網路上已經有許多資源了~ 有興趣的人Google一下就行了~ 或參考下述相關資源。
筆者主要用「spymemcached」這一個Java API,如果您需要其它語言的API請參考:Memcached Clients。
下述是印出相關Memcached Server的狀態程式:
import java.net.SocketAddress; import java.util.Map; import net.spy.memcached.AddrUtil; import net.spy.memcached.MemcachedClient; public class MemcachedTest { public static void main(String arg[]) throws Exception { long total_items = 0; MemcachedClient mc = new MemcachedClient(AddrUtil.getAddresses("xxx.xxx.xxx.xxx:11211")); Map<SocketAddress, Map<String, String>> stats = mc.getStats(); for (Map.Entry<SocketAddress, Map<String, String>> e : stats.entrySet()) { System.out.println("memcached server: " + e.getKey().toString()); for (Map.Entry<String, String> s : e.getValue().entrySet()) { System.out.println(" - " + s.getKey() + ": " + s.getValue()); if (s.getKey().equals("curr_items")) total_items += Long.parseLong(s.getValue()); } } System.out.println("Total number items in memcache: " + total_items); mc.shutdown(); } }
相關消息與資源