Your SlideShare is downloading. ×
0
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Redis begins
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Redis begins

1,953

Published on

Published in: Technology
0 Comments
5 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,953
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
63
Comments
0
Likes
5
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Redis Begins charsyam@naver.com
  • 2. Redis?
  • 3. Redis? Redis is an open source. http://redis.io
  • 4. Redis? Redis is an open source. BSD licensed. http://redis.io
  • 5. Redis? Redis is an open source. BSD licensed. advanced key-value store. http://redis.io
  • 6. Redis? Redis.io http://redis.io
  • 7. Why Redis?
  • 8. Why Redis? Simple. Performance.
  • 9. Build $ make
  • 10. But You can meet some errors in Linux Solution: $> make distclean; make;
  • 11. Why? Redis saves settings to .make-* files And they disturb normal building.
  • 12. Argenda Single Thread. Collections. Persistent. Replication.
  • 13. The one thing you should know.
  • 14. Redis is Single Threaded!
  • 15. Single Thread Means!
  • 16. Don’t execute long task.
  • 17. Example: Keys command Flushall/flushdb command
  • 18. O(n)
  • 19. Keys * di = dictGetSafeIterator(c->db->dict); allkeys = (pattern[0] == '*' && pattern[1] == '0'); while((de = dictNext(di)) != NULL) { …… stringmatchlen(pattern,plen,key,sdslen(key),0) }
  • 20. FlushAll Cache Item Count Time Memcache 1,000,000 1~2ms Redis 1,000,000 1000ms(1 second)
  • 21. Memcache’s flush is faster than Redis’s flush.
  • 22. Memcache’s flush is faster than Redis’s flush?
  • 23. FlushAll-Redis for (i = 0; i < ht->size && ht->used > 0; i++) { dictEntry *he, *nextHe; if ((he = ht->table[i]) == NULL) continue; while(he) { nextHe = he->next; dictFreeKey(d, he); dictFreeVal(d, he); zfree(he); ht->used--; he = nextHe; } }
  • 24. FlushAll-Memcache if (exptime > 0) settings.oldest_live = realtime(exptime) - 1; else /* exptime == 0 */ settings.oldest_live = current_time - 1;
  • 25. FlushAll-Memcache if (settings.oldest_live != 0 && settings.oldest_live <= current_time && it->time <= settings.oldest_live) { do_item_unlink(it, hv); do_item_remove(it); it = NULL; }
  • 26. Argenda Single Thread. Collections. Persistent. Replication.
  • 27. Collections Memcached supports just K-V List Set Sorted Set Hash
  • 28. Key:Value $> set key value $> get key
  • 29. Key:Value sql> insert into userinfo (name, email) values(‘charsyam’, ‘test@abc.com’);
  • 30. Key:Value $> set id:name “charsyam” $> set id:email test@abc.com $> mget id:name id:email 1) “charsyam” 2) test@abc.com”
  • 31. List $> rpush listname a --- (a) $> rpush listname b --- (a, b) $> lpush listname c --- (c, a, b) $> rpop listname(or lpop listname)
  • 32. List - when When you need job queue or stack.
  • 33. Set $> sadd setname id1 $> sadd setname id2 $> smember setname 1) “id2” 2) “id1”
  • 34. set - when When you need follwers ids or group members id
  • 35. Sorted Set $> zadd zsetname 1 “one” $> zadd zsetname 2 “two” $> zadd zsetname 3 “three”
  • 36. Sorted Set $> zrange zsetname 0 -1 1) “one” 2) “two” 3) “three”
  • 37. zset - when When you need ranking
  • 38. Sorted Set $> zrange zsetname 1 3 1) “two” 2) “three”
  • 39. Hash sql> insert into userinfo (name, email) values(‘charsyam’, ‘test@abc.com’);
  • 40. Hash$> hmset id name “charsyam” email test@abc.com
  • 41. Hash$> hgetall 1) “name” 2) “charsyam” 3) “email” 4) “test@abc.com”
  • 42. Hash$> hset id email abc@abc.com $> hgetall 1) “name” 2) “charsyam” 3) “email” 4) “abc@abc.com”
  • 43. Remember!!!!!
  • 44. The one thing you should know.
  • 45. Redis is Single Threaded!
  • 46. Don’t insert too many items into collections.
  • 47. Delete collections Item Count Time list 1,000,000 1000ms(1 second) set Sorted set hash
  • 48. Argenda Single Thread. Collections. Persistent. Replication.
  • 49. Redis can store its memory snapshot.
  • 50. RDB
  • 51. RDB is not Relation DBMS.
  • 52. RDB is redis snapshot name.
  • 53. Fork()
  • 54. RDB - BAD • Bad Performance in Large memory. • Twice memory problem. • Denying write problem when storing RDB fails. • If you just want Cache. Turn off RDB
  • 55. RDB – Large Memory • Performance is relevant to Memory Size. 17.1 GB 34.2 GB 68.4 GB 117 GB
  • 56. RDB – Twice Memory • fork() and COW(copy on write) Issue –In Write Heavy System:
  • 57. RDB – Twice Memory
  • 58. RDB – Twice Memory
  • 59. RDB – Twice Memory
  • 60. Real Case Study • Background –Can’t write to Redis Server –Sentinel doesn’t find Server’s failure.
  • 61. Real Case Study • Reason –If redis fails to save RDB, Redis basically denies write operations from client. –“MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk. Commands that may modify the data set are disabled. Please check Redis logs for details about the error.”
  • 62. Real Case Study • Reason if (server.stop_writes_on_bgsave_err && server.saveparamslen > 0 && server.lastbgsave_status == REDIS_ERR && c->cmd->flags & REDIS_CMD_WRITE) { flagTransaction(c); addReply(c, shared.bgsaveerr); return REDIS_OK; }
  • 63. Real Case Study • Solution #1 • Solution #2 config set stop-writes-on-bgsave-error no Turn off RDB Setting 2.6.12 부터 conf 에서 stop-writes-on-bgsave-error 설정이 가능해짐.
  • 64. AOF
  • 65. AOF is append only file.
  • 66. AOF memorizes all requests.
  • 67. AOF*3rn$3rnsetrn$1rnA rn$3rn123rn*3rn$3rn setrn$1rnBrn$3rn123 rn*3rn$3rnsetrn$1r nCrn$3rn123rn
  • 68. AOF*3 $3 Set $1 A ……
  • 69. AOF Rewrite When size of AOF grows than redis rewrite memory state to AOF.
  • 70. Argenda Single Thread. Collections. Persistent. Replication.
  • 71. Redis support master/slave replication
  • 72. Replication •Support Chained Replication Master 1st Slave 2nd Slave 1st slave is master of 2nd slave
  • 73. Replication Master Slave replicationCron Health check
  • 74. Replication Master Slave replicationCron Health check
  • 75. Replication Master Slave replicationCron When master reruns, Resync with Master
  • 76. Mistake: Replication Master Slave replicationCron Slave will has no data after resyncing If master has no data.
  • 77. Initial Replication Step
  • 78. Replication Don’t forget “slave of no one”
  • 79. Sentinel
  • 80. Sentinel • Sentinel is Failover Solution for Redis. Master Slave Sentinel Sentinel periodically checks Redis Master
  • 81. Sentinel Master Slave Sentinel Send “slaveof no one” to slave node
  • 82. Sentinel Master Slave Sentinel Notify to client about changing master Client
  • 83. Sentinel redis 127.0.0.1:2003> psubscribe * Reading messages... (press Ctrl-C to quit) 1) "pmessage" 2) "*" 3) "+switch-master" 4) "resque 127.0.0.1 1999 127.0.0.1 2002"
  • 84. Sentinel • Sentinel will connect correct master even if you set slave’s ip in conf Master Slave Sentinel Slave’s ip in sentinel.conf
  • 85. Sentinel • INFO # Replication role:slave master_host:127.0.0.1 master_port:6379 ……
  • 86. Sentinel • Reconnect to correct master using master_host and master_port. Master Slave Sentinel Reconnect to master of slave.
  • 87. Sentinel.conf port 26379 sentinel monitor mymaster 127.0.0.1 6379 1 sentinel down-after-milliseconds mymaster 30000 sentinel can-failover mymaster yes sentinel parallel-syncs mymaster 1 sentinel failover-timeout mymaster 900000
  • 88. Wrap Up
  • 89. Redis is Single Threaded!
  • 90. Q & A
  • 91. Thank you!

×