Redis深入浅出

1,086 views

Published on

Published in: Technology, Art & Photos
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,086
On SlideShare
0
From Embeds
0
Number of Embeds
87
Actions
Shares
0
Downloads
13
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Redis深入浅出

  1. 1. redis 深入浅出
  2. 2. Agenda Feature&Architecture Admin&capcity forecast Replication Presistence Table design
  3. 3. Feature redis memcacheddata structure string|list|hash|set|zset stringthread model third(main thread, two many auxiliary thread)demultiplexer ae.c libevent(3rd library)persistence yes noreplication yes nodesign weak no
  4. 4. String Set hello world Set hello 1234567 Set hello 1234
  5. 5. List Lpush list aaaa bbb ccc Double link list, so can lpush,rpush,lpop,rpop
  6. 6. ZipmapHset test hello worldHset test aliyun dbaZipmap defect:Zmlen one bytes, only 253 subkey
  7. 7. Architecture
  8. 8. Rehash
  9. 9. Cache forecaststring 类型的内存大小 = 键值个数 * (dictEntry 大 小 + redisObject 大小 + 包含 key 的 sds 大小 + 包含 value 的 sds 大小 ) + bucket 个数 * 4zipmap 类型的内存大小 = hashkey 个数 * (dictEntry 大小 + redisObject 大小 + 包含 key 的 sds 大小 + subkey 的总大小 ) + bucket 个数 * 4Jemalloc size class
  10. 10. Admin Redis.conf(static), config set(dynamic) – maxmemory <bytes> – Appendfsync everysec(fsync pagecache to disk) – hash-max-zipmap-entries 512 – hash-max-zipmap-value 64
  11. 11. Replication procedure  map  Master slave – slave – slave - slave defects  Without resume broken transfer  Without lag(slave position)
  12. 12. replication
  13. 13. Persistence Snapshot  Fork process, loop hash table, save file dump.rdb  Yes!!! sequential write  Write dump.rdb need O_DIRECT Aof  Like binlog, for recover after crash  Auto bgrewrteaof  Auxiliary threads  Postpone fsync
  14. 14. Auxiliary thread
  15. 15. Table desgin login user Design a login user system  Heap table  userid login_times last_login_time  1 5 2011-1-1  2 1 2011-1-2  3 2 2011-1-3  Last login man? Create index on last_login_time  Max login man? Create index on login_times  Index, explan plan, compute statistics is suck!!!
  16. 16. Login user data  Set userid:1:login_times 5  Set userid:2:login_times 1  Set userid:3:login_times 2  Set userid:1:last_login 2011-1-1  Set userid:2:last_login 2011-1-2  Set userid:3:last_login 2011-1-3 Last login  lpush user_last_login 1  lpush user_last_login 2  lpush user_last_login 3  ltrim user_last_login 0 1
  17. 17. Login user Max login man  zadd user:login_times 5 1  zadd user:login_times 1 2  zadd user:login_times 2 3  zcard user:login_times  zrangebyscore user:login_times 3 +inf withscores Column store data?
  18. 18. Suitable Scene 轻量级的高性能消息队列服务 , 生产者消费者 跨机器的共享内存 Redis 的主要缺点是数据库容量受到物理内存 的限制,不能用作海量数据的高性能读写,并 且它没有原生的可扩展机制,不具有 scale (可扩展)能力,要依赖客户端来实现 分布式读写,因此 Redis 适合的场景主要局限 在较小数据量的高性能操作和运算上。
  19. 19. QA @hoterranwww.hoterran.info

×