27
Einführung & Use Cases Sebastian Cohnen @tisba / tisba.de Donnerstag, 3. Mai 12

NoSQL CGN: Redis (05/2012)

Embed Size (px)

DESCRIPTION

Eine kurze Einführung, Rundumblick und Use Cases zu Redis.

Citation preview

  • 1. Einfhrung & Use Cases Sebastian Cohnen @tisba / tisba.deDonnerstag, 3. Mai 12
  • 2. About Me Freier Entwickler Ruby/Rails & node.js Performance & Scalability Engineering Distributed Load Testing CouchDB, Redis & Riak und ebenfalls interessiert an Erlang, AMQP, ...Donnerstag, 3. Mai 12
  • 3. Redis von Salvatore antirez Sanlippo erste Version ~04/2009 aktuell 2.4.13 (stable) / 2.6.0-rc2Donnerstag, 3. Mai 12
  • 4. Was ist Redis? memcached Ersatz? memcached on steriods? Caching Server? KV-Storage? ...?Donnerstag, 3. Mai 12
  • 5. ...! in-memory Datenbank (KV Store) Datentypen: String, Hash, List, Set & sorted Set Master-Slave Replikation Transaktionen ASCII-basiertes ProtokollDonnerstag, 3. Mai 12
  • 6. Getting Started http://redis.io/download zum Spielen 2.6.x fr Live-Systeme 2.4.x brew install redis (apt-get install redis) $ redis-cli > SET myval "bar" OK > GET myval "bar"Donnerstag, 3. Mai 12
  • 7. DatentypenDonnerstag, 3. Mai 12
  • 8. Strings binary safe Byte-Array bitweiser Zugriff mglich numerische Werte werden optimiert gespeichert GET[BIT|RANGE], SET[BIT|RANGE], APPEND, STRLEN, ... INCR[BY], DECRDonnerstag, 3. Mai 12
  • 9. Listen Sortierte Liste aus Strings [L|R]POP, [L|R]PUSH LINSERT mylist BEFORE|AFTER foo LTRIM, LRANGE, RPOPLPUSHDonnerstag, 3. Mai 12
  • 10. Hashes Hash Map mit Key und Value, jeweils Strings z.B. zum Abbilden von Objekten direkter Zugriff auf einzelne, mehrere oder alle Attribute HGET, HMGET, HGETALL HSET, HMSET HKEYS, HVALS, HLENDonnerstag, 3. Mai 12
  • 11. Mengen unsortiert (S) & sortierte (Z) [S|Z]ADD, [S|Z]REM, [S|Z]CARD [S|Z]DIFF, [S|Z]INTER, [S|Z]UNION ZSCORE, ZRANK, ZRANGE, ZREMRANGEBYRANKDonnerstag, 3. Mai 12
  • 12. VerschiedenesDonnerstag, 3. Mai 12
  • 13. Transaktionen > MULTI OK > INCR foo QUEUED > INCR bar QUEUED > EXEC 1) (integer) 1 2) (integer) 1Donnerstag, 3. Mai 12
  • 14. Debugging INFO MONITOR SLOWLOG CONFIG [GET|SET]Donnerstag, 3. Mai 12
  • 15. Performance?Donnerstag, 3. Mai 12
  • 16. Redis ist schnell genug!Donnerstag, 3. Mai 12
  • 17. Benchmarks sind doof ;) redis-benchmark -P 64 -n 1000000 -t incr,get,set => 370k SET/s | 450k GET/s | 347k INCR/s in bisherigen Tests sind dauerhafte 30k OPS/s auf EC2 kein Problem (YMMV) http://redis.io/topics/benchmarksDonnerstag, 3. Mai 12
  • 18. Performance generell gute, stabile Latenzen & guter Durchsatz algorithmische Komplexitt ist gut dokumentiert Optimierung ist oft einfach Wichtig Pipelining nutzen Domain Socket vs. TCP SocketDonnerstag, 3. Mai 12
  • 19. Use CasesDonnerstag, 3. Mai 12
  • 20. Caching plain Strings (serialisierte Objekte, JSON, HTML, Bilder...) Objekte (als Hash)Donnerstag, 3. Mai 12
  • 21. BG Jobs, Queues resque (Ruby), node-resque (node.js) Listen mit BLPOP Priorisierte Queues mit sortierten MengenDonnerstag, 3. Mai 12
  • 22. Statistiken Atomare Counter (INCR, INCRBY, HINCRBY, ZINCRBY) Sets fr eindeutige Events ...Donnerstag, 3. Mai 12
  • 23. IPC Pub/Sub Pattern SUBSCRIBE user.new PUBLISH user.new 4232 PSUBSCRIBE user.* Kommunikation zwischen Prozessen (Master, Worker, ...)Donnerstag, 3. Mai 12
  • 24. Weitere Use Cases Visitor/Event Tracking LRU Cache Scoreboard/LeaderboardDonnerstag, 3. Mai 12
  • 25. 1st class DB Integraler Bestandteil / Erweiterung der Anwendungslogik Sets, Lists und Hashes um spezielle Aufgaben zu lsen alle Requests aus Redis (live cache) Datenbank als FallbackDonnerstag, 3. Mai 12
  • 26. Resources Infos zu Redis & Dokumentation: http://redis.io/ Blog von Salvatore: http://antirez.com https://groups.google.com/forum/#!topic/redis-db/ d4QcWV0p-YM http://highscalability.com/blog/2012/4/2/youporn- targeting-200-million-views-a-day-and-beyond.htmlDonnerstag, 3. Mai 12
  • 27. Thanks! Q & A? ? Sebastian Cohnen @tisbaDonnerstag, 3. Mai 12