Mais conteúdo relacionado
Semelhante a About memcached (20)
About memcached
- 2. Memcached?
Memcached LiveJournal
, ,
, Web
LiveJournal Memcached MogileFS Perlbal
: http://www.danga.com/memcached
- 9. Map
key1: value1
key2:value2 / Expired
key3:value3
Cache
Do one thing well
I am not...
persistent
failover / redundant
authentication
RDBMS...
- 10. Simple
• C/S
• support telnet interface
•
✴set / get / stats
- 11. Simple
• C/S
• support telnet interface
•
✴set / get / stats
- 12. Simple
• C/S
• support telnet interface
•
✴set / get / stats
- 13. Simple
• C/S
• support telnet interface
•
✴set / get / stats
- 15. Object getFoo(String fooId) {
Object foo = memcached.get("foo" + fooId);
if (foo != null) return foo;
foo = database.fetchFoo(fooId);
memcached.set("foo"+fooId, foo);
return foo;
}
- 20. if (memcached.get(key) == null) {
if (memcached.add(key_mutex, 3*60*1000) == true) {
foo = database.fetchFoo(key);
memcached.set(key, foo);
memcached.delete(key_mutex);
} else {
sleep(50);
retry();
}
}
Mutex Patten
- 23. foo = memcached.get(key);
if (foo == null) {
if (memcached.add(key_mutex, 3 * 60 * 1000) == true) {
foo = database.get(key);
memcached.set(key, foo);
memcached.delete(key_mutex);
} else {
sleep(50);
retry();
}
} else {
...
}
Mutex Patten II
- 24. foo = memcached.get(key);
if (foo == null) {
if (memcached.add(key_mutex, 3 * 60 * 1000) == true) {
foo = database.get(key);
memcached.set(key, foo);
memcached.delete(key_mutex);
} else {
sleep(50);
retry();
}
} else {
... here
}
Mutex Patten II
- 25. if (foo.timeout >= now()) {
if (memcached.add(key_mutex, 3 * 60 * 1000) == true) {
foo.timeout += 3 * 60 * 1000;
memcached.set(key, foo, KEY_TIMEOUT * 2);
foo = database.get(key);
foo.timeout = KEY_TIMEOUT;
memcached.set(key, foo, KEY_TIMEOUT * 2);
memcached.delete(key_mutex);
} else {
sleep(50);
retry();
}
} else {
return foo;
}
Mutex Patten II
- 26. if (foo.timeout >= now()) {
if (memcached.add(key_mutex, 3 * 60 * 1000) == true) {
foo.timeout += 3 * 60 * 1000;
memcached.set(key, foo, KEY_TIMEOUT * 2);
foo = database.get(key);
foo.timeout = KEY_TIMEOUT;
memcached.set(key, foo, KEY_TIMEOUT * 2);
memcached.delete(key_mutex);
} else {
sleep(50);
retry();
}
} else {
return foo;
}
Mutex Patten II
- 31. ?
WEB EJB RDBMS
HTML Marshall
SQL
JSON Java
Results
XML Objects
- 32. ?
WEB EJB RDBMS
HTML Marshall
SQL
JSON Java
Results
XML Objects
- 33. ?
WEB EJB RDBMS
HTML Marshall
SQL
JSON Java
Results
XML Objects
- 34. • (memcached exptimes)
•
- SET or DELETE
-
• version
- version key: user_v2_100
- + LRU
- 44. Memcached Client
• Marshall
•
• Multiget support
• Compressed support
• Async/Sync Modes
• Replicated
• ...
- 45. Stats
• Memcached:
• telnet
• : stats
- 47. Limits
• Key Size (250 bytes)
• Data Size (under 1 megabyte)
• 32bit/64bit (maximum size of the process)
- 48. Protocol Commands
• set / get / gets / replace / add / delete
• append / prepend
• increment / decrement
• cas (compare and swap atomic!)
• stats(detail)
- 49. Numbers Everyone
Should Know
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns
Mutex lock/unlock 100 ns
Main memory reference * 100 ns
Compress 1K bytes with Zippy 10,000 ns
Send 2K bytes over 1 Gbps network * 20,000 ns
Read 1 MB sequentially from memory * 250,000 ns
Round trip within same datacenter 500,000 ns
Disk seek * 10,000,000 ns
Read 1 MB sequentially from network * 10,000,000 ns
Read 1 MB sequentially from disk * 30,000,000 ns
Send packet CA->Netherlands->CA 150,000,000 ns
Notas do Editor
- \n
- \n
- \n
- \n
- \n
- \n
- \n
- \n
- \n
- \n
- \n
- \n
- \n
- \n
- 1. NullObject\n2. Expire时的Cache击穿问题\n
- 应用服务器侧:\n1. 取不到数据?\n2. 超时怎么控制?\n\n引入了prefetch worker:\n1. 多了一个run component\n2. 增加了开发、测试、维护的复杂性\n3. 好的系统:自成系统\n
- \n
- \n
- \n
- 在value内部设置1个超时值(timeout1), timeout1比实际的memcache timeout(timeout2)小。当从cache读取到timeout1发现它已经过期时候,马上延长timeout1并重新设置\n
- 在value内部设置1个超时值(timeout1), timeout1比实际的memcache timeout(timeout2)小。当从cache读取到timeout1发现它已经过期时候,马上延长timeout1并重新设置\n
- \n
- \n
- \n
- \n
- \n
- \n
- \n
- \n
- 常用:\n1.指定失效时间 + 程序触发\n2.指定失效时间也适用于防止系统错误导致脏数据\n
- 单纯把MC当MEM用时需要做Failover\n
- \n
- \n
- \n
- \n
- \n
- \n
- \n
- \n
- \n
- \n
- \n
- \n
- \n
- \n