Memcachedcocowool@gmail.com
Memcached的历史及现状Memcached服务器端介绍memcache使用最佳实践memcache的分布式算法Memcached运维讨论
Memcached的历史及现状2003年,LiveJournal作者Brad Fitzpatrick当前版本1.4.5(2010-4-3)目前应用在许多大型网站中Flickr、Twitter、Craiglist, etc
Memcached的历史及现状什么是MemcachedMemory Cache Daemonmemcached is a server that caches Name Value Pairs (NVPs) in memoryMemcached能做什么任何元素:HTML片段、二进制对象、数据结果集极大地提高数据的获取效率Memcached不能做什么Memcached不是持久化的存储Memcached本身不支持分布式和高可用
一般情况下Memcached的用途
Memcached的分布式Memcached尽管是“分布式”服务器,但是服务器端并没有分布式的功能。各个Memcached不会互相通信以共享信息。Memcached的分布式,完全取决于客户端的实现。
Memcached服务器端介绍Memcached的安装支持Linux、Windows多种平台安装过程简单Memcached的启动端口、内存、Daemon新版本对于多线程的支持Memcached的几个限制:Key的长度不能超过250个字符存储的数据不能超过1MB最大同时连接数200
Memcached支持的参数
Memcached服务器端介绍可以使用telnet命令进行测试telnet servername port支持的命令存储类命令ADD、SET、REPLACE、APPEND、PREPEND、CAS读取类命令GET、GETSDELETE,Least Recently Used(LRU)算法INCR/DECR
Memcached服务器端介绍支持的命令状态类命令STATS、STATS ITEMS、STATS SLABS、STATSSIZESflush_all服务器效率的检查Cache hits ratio 缓存命中率get_hits / (get_hits + get_misses)gets 和 sets 百分比cmd_get / cmd_set这个比例应当越高越好curr_items/total_items/bytes
memcache使用最佳实践如何在应用中使用Memcached需要有客户端支持,目前有丰富的客户端Perl、PHP、Python、Ruby、Java、.NET/C#、C、Postgres、Chicken客户端的作用实现Memcache的分布式算法提供压缩功能,使Memcached存储更大容量数据
memcache使用最佳实践PHP客户端特点以模块的方式提供支持从PHP4.3.3以后的版本开始依赖于zlib提供数据的压缩功能配置参数
memcache使用最佳实践PHP客户端配置参数
memcache使用最佳实践PHP客户端支持的函数列表
memcache使用最佳实践Memcached的使用场景Key的命名规范ObjectName:ObjectType:Key使用SQL语句作为键值如何处理数据的更新Flush Cache预清除缓存(Proactively Clear Cache)读取数据时强制重设缓存
memcache使用最佳实践如何避免多个客户端的更新增加锁机制依赖Memcached返回成功信息的机制通过GET和SET实现如何设置合适的过期时间数据的请求频率数据的更新频率,更新越频繁,过期时间宜短数据是由外部程序来更新的(第三方)避免数据过期时的并发访问
memcache使用最佳实践缓存什么内容慢查询SQL减少Memcached的影响确保即便所有的服务器都Down了,服务仍正常Client的重试动作
memcache的分布式算法
memcache的分布式算法
memcache的分布式算法Cache::Memcached的分布算法根据余数进行分散(CRC32)支持Rehash,可以设置关闭在缓存服务器发生重组时代价较大
memcache的分布式算法Consistent Hashing
memcache的分布式算法Consistent Hashing
memcache的分布式算法LibketamaTake your list of servers (eg: 1.2.3.4:11211, 5.6.7.8:11211, 9.8.7.6:11211)Hash each server string to several (100-200) unsigned intsConceptually, these numbers are placed on a circle called the continuum. (imagine a clock face that goes from 0 to 2^32)Each number links to the server it was hashed from, so servers appear at several points on the continuum, by each of the numbers they hashed to.To map a key->server, hash your key to a single unsigned int, and find the next biggest number on the continuum. The server linked to that number is the correct server for that key.If you hash your key to a value near 2^32 and there are no points on the continuum greater than your hash, return the first server in the continuum.
Memcached运维讨论运维工具与方法telnet与stats命令memcached-tool查看memcached中slab的使用状况几个重要参数curr_connectionslisten_disabled_numlisten_disabled_num
Memcached的扩展memcached Storage Engine for MySQLApache memcached SessionrepcachedmemcachefsMemcachedbFlaredTokyo Tyrant
参考资料Using Memcached – How to scale your website easilyhttp://timyang.net/tag/cache/http://www.mysqlperformanceblog.com/2006/08/09/cache-performance-comparison/http://www.last.fm/user/RJ/journal/2007/04/10/rz_libketama_-_a_consistent_hashing_algo_for_memcache_clients从Memcached分布式应用看一致性哈希散列函数的选择Memcache的mutex设计模式Memcached数据被踢(evictions>0)现象分析Cache Performance Comparison

Memcached分析