SlideShare a Scribd company logo
Redis Tutoring
Blackie
2015/10/12
Redis Introduction
StackExchange.Redis Introduction
RedisDemo Introduction
Tools
Who am I
Blackie Tsai
Senior IT consultant of Xuenn
Full stack developer
Major on development of real-time transaction system with low latency and high concurrent
Learning CI&CD and run with Agile&LEAN
Blog
http://www.dotblogs.com.tw/blackie1019
REDIS INTRODUCTION
Redis
Redis - A.K.A Remote Directory Server. It is an open source (BSD licensed), one of Key-Value database of
NoSQL, in-memory data structure store, used as database, cache and message broker. It also can run atomic
operations.
Most Popular NoSQL(http://techstacks.io/)
Recommend using Linux for deploying.
Features
Pure
Simple
Single Tread
In-memory but persistent on disk database
Remote dictionary server
3.0.4 is the latest stable version.
開源資料庫Redis實戰經驗大公開
https://www.g2crowd.com/press-release/best-nosql-databases-fall-2015/
https://clusterhq.com/assets/pdfs/state-of-container-usage-june-2015.pdf
Over 70% would like to run a database or other stateful service in their
container environments, with MySQL and Redis the two leading choices
Important features for data management in container solutions were:
Integration of data management capabilities into existing container work flow and
tools
seamless movement of data between dev, test and production environments.
Who using Redis
Facebook’s Instagram: Making the Switch to Cassandra from Redis, a 75% ‘Insta’ Savings
http://techstacks.io/tech/redis、http://redis.io/topics/whos-using-redis
http://redis.io/clients
Redis - Data Persistence
Master
Redis
Slaver
Redis
Persistence to Disk
Server A
Server B
Replication
IMPLEMENTING PERSISTENCE IN REDIS
• Master instance with no persistence
• Slave instance with AOF enabled
Redis - PubSub
SignalR Scaleout with Redis
Redis - Insight Of Pit
Server-side session with Redis
Redis has many eviction policies, but most of them are based on 'sampling‘.
Alternative Solution
Use Database as an another back-end
Use Redis 3.0
Maximize CPUs usage
Redis is single thread. One instance usually only use one CPU
Redis, another step on the road
Redis - DataStore
http://redis.io/commands#string
http://redis.io/commands#hash
http://redis.io/commands#set
http://redis.io/commands#sorted_set
http://redis.io/commands#list
Redis – LUA Script
Redis embedded scripting language
Good Learning : Lua: 给 Redis 用户的入门指导
5 Methods For Tracing and Debugging Redis Lua Scripts
http://redis.io/commands/eval
STACKEXCHANGE.REDIS INTRODUCTION
Stack Exchange
The world’s largest programming
community is growing
Stack Exchange is a network of 130+ Q&A communities
including Stack Overflow
Global traffic ranking 54th largest website
Architecture of Stack Exchange
http://stackexchange.com/performance
Stack Exchange - Info
Stack Overflow still uses Microsoft products.
Stack Overflow still uses a scale-up strategy with HA.
SQL Servers loaded with 384 GB of RAM and 2TB of SSD.
Stats
4 million users, 8 million questions, 40 million answers, 560 million pageviews a month.
Peak is more like 2600-3000 requests/sec on most weekdays.
25 servers, Stack Overflow has a 40:60 read-write ratio.
2 TB of SQL data all stored on SSDs, Each web server has 2x 320GB SSDs in a RAID 1.
DB servers average 10% CPU utilization, 11 web servers, using IIS.
2 load balancers, 1 active, using HAProxy
4 active database nodes, using MS SQL
2 machines for distributed cache and messaging using Redis
2 read-only SQL Servers for used mainly for the Stack Exchange API
3 machines doing search with ElasticSearch
Stack Exchange - Caching
Caching
Cache all the things.
5 levels of caches.
1st:
Caching in the browser, CDN, and proxies.
2nd:
Using HttpRuntime.Cache. An in-
memory, per server cache.
3rd:
Redis.
4th:
SQL Server
Cache.
5th:
SSD.
Stack Exchange - Lessons Learned
Why use Redis if you use MS products?
gabeech: It's not about OS evangelism. We run things on the platform they run best on. Period. C# runs best on a
windows machine, we use IIS. Redis runs best on a *nix machine we use *nix.
Overkill as a strategy
SSDs Rock
Know your read/write workload
Keeping things very efficient means new machines are not needed often
Don’t be afraid to specialize
Do only what needs to be done
Reinvention is OK
Go down to the bare metal
No bureaucracy.
Garbage collection driven programming
The cost of inefficient code can be higher than you think
StackExchange.Redis
Basic Usage - getting started and basic usage
Configuration - options available when connecting to redis
Pipelines and Multiplexers - what is a multiplexer?
Keys, Values and Channels - discusses the data-types used on the API
Transactions - how atomic transactions work in redis
Events - the events available for logging / information purposes
Pub/Sub Message Order - advice on sequential and concurrent processing
Scripting - running Lua scripts with convenient named parameter replacement
https://github.com/StackExchange/StackExchange.Redis
How to use
Configuration
Automatic and Manual Configuration
String Parse Constructor
New Constructor
Configuration Options
Renaming Commands
Twemproxy
StackExchange.Redis Configuration
REDISDEMO INTRODUCTION
RedisDemo
Features
Connection Mapping with Configuration
Configuration with Redis Instance Group and Name concept supported
Singleton pattern avoid resource waste
Dependency
StackExchange.Redis
FX.Configuration
Newtonsoft.Json
Log4Net(Optional)
Demo Version
https://github.com/blackie1019/RedisDemo
RedisDemo - Configuration
ConnectionSetting follow StackExchange.Redis
ConfigurationOptions.Parse()
RedisDemo Framework - Example
Example Lab
Example – Basic
Strings
Lists
Sets
Hashes
Sorted Sets
Example – Advance
Sort
Expire
HashSet, HashGetAll and HashDelete
Pub/Sub
Pipelines
Batch
Example – Scripting
https://github.com/blackie1019/RedisDemo
TOOLS
Redis Data Management
Cross-platform redis desktop manager - desktop management GUI for mac OS X, Windows, Debian and
Ubuntu.
http://redisdesktop.com
Opserver
Monitoring Tool of Stack Exchange
Servers
SQL clusters/instances
Redis
Elastic search
Exception logs
Haproxy
Redis Server with Docker
Enable Virtualization Technology on Bios and install Docker Toolbox
Create a Docker container for Redis
Run the service
Create your web application container
If any problem you can remove and setup again
docker-machine rm default
docker-machine --native-ssh create -d virtualbox default
Dockerizing a Redis service
Reference
Scaling Stack Overflow (QCon NYC 2015)
Redis, another step on the road
Types of NoSQL databases
StackOverflow Update: 560M Pageviews A Month, 25 Servers, And It's All About Performance
Redis 设计与实现
《Redis 设计与实现》图片集

More Related Content

PPTX
Introduction to Redis
Maarten Smeets
 
ODP
Beyond relational database - Building high performance websites using Redis a...
Dinh Pham
 
PDF
Redis 101
Geoff Hoffman
 
PPTX
Redis Introduction
Alex Su
 
PPTX
Redis/Lessons learned
Tit Petric
 
PPTX
Redis 101 Data Structure
Ismaeel Enjreny
 
PDF
Postgres & Redis Sitting in a Tree- Rimas Silkaitis, Heroku
Redis Labs
 
PDF
Redis memcached pdf
Erin O'Neill
 
Introduction to Redis
Maarten Smeets
 
Beyond relational database - Building high performance websites using Redis a...
Dinh Pham
 
Redis 101
Geoff Hoffman
 
Redis Introduction
Alex Su
 
Redis/Lessons learned
Tit Petric
 
Redis 101 Data Structure
Ismaeel Enjreny
 
Postgres & Redis Sitting in a Tree- Rimas Silkaitis, Heroku
Redis Labs
 
Redis memcached pdf
Erin O'Neill
 

What's hot (20)

PPTX
Caching solutions with Redis
George Platon
 
PDF
Boosting Machine Learning with Redis Modules and Spark
Dvir Volk
 
DOCX
Redis vs Memcached
Gaurav Agrawal
 
PPTX
Redis and it's data types
Aniruddha Chakrabarti
 
PPTX
Hadoop Meetup Jan 2019 - Router-Based Federation and Storage Tiering
Erik Krogen
 
KEY
Scaling php applications with redis
jimbojsb
 
PDF
Background Tasks in Node - Evan Tahler, TaskRabbit
Redis Labs
 
PPTX
Hadoop Meetup Jan 2019 - Hadoop Encryption
Erik Krogen
 
PPTX
Hadoop Meetup Jan 2019 - Mounting Remote Stores in HDFS
Erik Krogen
 
PPTX
This is redis - feature and usecase
Kris Jeong
 
PDF
Redis modules 101
Dvir Volk
 
PPTX
SQL on Azure
Maximiliano Accotto
 
PDF
Oracle Database on Docker
Franck Pachot
 
KEY
Drupal In The Cloud
Jochen Lillich
 
PPTX
REDIS327
Rajan Bhatt
 
PDF
Technical tips for secure Apache Hadoop cluster #ApacheConAsia #ApacheCon
Yahoo!デベロッパーネットワーク
 
PPTX
Tips to drive maria db cluster performance for nextcloud
Severalnines
 
PDF
ProxySQL - High Performance and HA Proxy for MySQL
René Cannaò
 
PPTX
Hadoop Meetup Jan 2019 - HDFS Scalability and Consistent Reads from Standby Node
Erik Krogen
 
PPTX
Ravi Namboori Hadoop & HDFS Architecture
Ravi namboori
 
Caching solutions with Redis
George Platon
 
Boosting Machine Learning with Redis Modules and Spark
Dvir Volk
 
Redis vs Memcached
Gaurav Agrawal
 
Redis and it's data types
Aniruddha Chakrabarti
 
Hadoop Meetup Jan 2019 - Router-Based Federation and Storage Tiering
Erik Krogen
 
Scaling php applications with redis
jimbojsb
 
Background Tasks in Node - Evan Tahler, TaskRabbit
Redis Labs
 
Hadoop Meetup Jan 2019 - Hadoop Encryption
Erik Krogen
 
Hadoop Meetup Jan 2019 - Mounting Remote Stores in HDFS
Erik Krogen
 
This is redis - feature and usecase
Kris Jeong
 
Redis modules 101
Dvir Volk
 
SQL on Azure
Maximiliano Accotto
 
Oracle Database on Docker
Franck Pachot
 
Drupal In The Cloud
Jochen Lillich
 
REDIS327
Rajan Bhatt
 
Technical tips for secure Apache Hadoop cluster #ApacheConAsia #ApacheCon
Yahoo!デベロッパーネットワーク
 
Tips to drive maria db cluster performance for nextcloud
Severalnines
 
ProxySQL - High Performance and HA Proxy for MySQL
René Cannaò
 
Hadoop Meetup Jan 2019 - HDFS Scalability and Consistent Reads from Standby Node
Erik Krogen
 
Ravi Namboori Hadoop & HDFS Architecture
Ravi namboori
 
Ad

Similar to Redis tutoring (20)

PPTX
Redis Labcamp
Angelo Simone Scotto
 
PPT
New York REDIS Meetup Welcome Session
Aleksandr Yampolskiy
 
PPTX
05 integrate redis
Erhwen Kuo
 
PPTX
Redis meetup
Nikhil Dole
 
PPTX
Redis_Presentation.pptx ppt on redis and
tanishksaini51
 
PPTX
Introduction to Redis
Ofer Zelig
 
PPTX
Get more than a cache back! - ConFoo Montreal
Maarten Balliauw
 
PDF
Redis 101
Abhishek Parwal
 
PDF
Mini-Training: Redis
Betclic Everest Group Tech Team
 
PDF
Fun with Ruby and Redis
javier ramirez
 
PDF
Everything you always wanted to know about Redis but were afraid to ask
Carlos Abalde
 
PPTX
Enhance your multi-cloud application performance using Redis Enterprise P2
Ashnikbiz
 
PPTX
Redis introduction
Federico Daniel Colombo Gennarelli
 
PDF
redis_tutoria0l for new learners step from scratch.pdf
BharathiRaja981061
 
PDF
A Brief Introduction to Redis
Charles Anderson
 
PDF
#SydPHP - The Magic of Redis
Aaron Weatherall
 
PDF
Redispresentation apac2012
Ankur Gupta
 
PDF
Redis overview
Ashokkumar T A
 
PDF
dba_lounge_Iasi: Everybody likes redis
Liviu Costea
 
PDF
Getting Started with Redis
Faisal Akber
 
Redis Labcamp
Angelo Simone Scotto
 
New York REDIS Meetup Welcome Session
Aleksandr Yampolskiy
 
05 integrate redis
Erhwen Kuo
 
Redis meetup
Nikhil Dole
 
Redis_Presentation.pptx ppt on redis and
tanishksaini51
 
Introduction to Redis
Ofer Zelig
 
Get more than a cache back! - ConFoo Montreal
Maarten Balliauw
 
Redis 101
Abhishek Parwal
 
Mini-Training: Redis
Betclic Everest Group Tech Team
 
Fun with Ruby and Redis
javier ramirez
 
Everything you always wanted to know about Redis but were afraid to ask
Carlos Abalde
 
Enhance your multi-cloud application performance using Redis Enterprise P2
Ashnikbiz
 
redis_tutoria0l for new learners step from scratch.pdf
BharathiRaja981061
 
A Brief Introduction to Redis
Charles Anderson
 
#SydPHP - The Magic of Redis
Aaron Weatherall
 
Redispresentation apac2012
Ankur Gupta
 
Redis overview
Ashokkumar T A
 
dba_lounge_Iasi: Everybody likes redis
Liviu Costea
 
Getting Started with Redis
Faisal Akber
 
Ad

More from Chen-Tien Tsai (20)

PDF
關於軟體工程師職涯的那些事
Chen-Tien Tsai
 
PPTX
Artifacts management with CI and CD
Chen-Tien Tsai
 
PPTX
.NET Security Application/Web Development - Part IV
Chen-Tien Tsai
 
PPTX
.NET Security Application/Web Development - Part III
Chen-Tien Tsai
 
PPTX
.NET Security Application/Web Development - Part II
Chen-Tien Tsai
 
PPTX
.NET Security Application/Web Development - Part I
Chen-Tien Tsai
 
PPTX
.NET Security Application/Web Development - Overview
Chen-Tien Tsai
 
PPTX
Designing distributedsystems cht6
Chen-Tien Tsai
 
PPTX
Reactive application with akka.NET & .NET Core
Chen-Tien Tsai
 
PPTX
The Cloud - What's different
Chen-Tien Tsai
 
PDF
How to be a professional speaker
Chen-Tien Tsai
 
PPTX
Agile tutorial
Chen-Tien Tsai
 
PPTX
響應式程式開發之 .NET Core 應用 
Chen-Tien Tsai
 
PPTX
Artifacts management with DevOps
Chen-Tien Tsai
 
PPTX
Web optimization with service woker
Chen-Tien Tsai
 
PDF
GCPUG.TW Meetup #25 - ASP.NET Core with GCP
Chen-Tien Tsai
 
PDF
.NET Study Group - ASP.NET Core with GCP
Chen-Tien Tsai
 
PPTX
Webpack and Web Performance Optimization
Chen-Tien Tsai
 
PPTX
DotNet MVC and webpack + Babel + react
Chen-Tien Tsai
 
PPTX
Website Auto scraping with Autoit and .Net HttpRequest
Chen-Tien Tsai
 
關於軟體工程師職涯的那些事
Chen-Tien Tsai
 
Artifacts management with CI and CD
Chen-Tien Tsai
 
.NET Security Application/Web Development - Part IV
Chen-Tien Tsai
 
.NET Security Application/Web Development - Part III
Chen-Tien Tsai
 
.NET Security Application/Web Development - Part II
Chen-Tien Tsai
 
.NET Security Application/Web Development - Part I
Chen-Tien Tsai
 
.NET Security Application/Web Development - Overview
Chen-Tien Tsai
 
Designing distributedsystems cht6
Chen-Tien Tsai
 
Reactive application with akka.NET & .NET Core
Chen-Tien Tsai
 
The Cloud - What's different
Chen-Tien Tsai
 
How to be a professional speaker
Chen-Tien Tsai
 
Agile tutorial
Chen-Tien Tsai
 
響應式程式開發之 .NET Core 應用 
Chen-Tien Tsai
 
Artifacts management with DevOps
Chen-Tien Tsai
 
Web optimization with service woker
Chen-Tien Tsai
 
GCPUG.TW Meetup #25 - ASP.NET Core with GCP
Chen-Tien Tsai
 
.NET Study Group - ASP.NET Core with GCP
Chen-Tien Tsai
 
Webpack and Web Performance Optimization
Chen-Tien Tsai
 
DotNet MVC and webpack + Babel + react
Chen-Tien Tsai
 
Website Auto scraping with Autoit and .Net HttpRequest
Chen-Tien Tsai
 

Recently uploaded (20)

PDF
settlement FOR FOUNDATION ENGINEERS.pdf
Endalkazene
 
PPTX
22PCOAM21 Session 2 Understanding Data Source.pptx
Guru Nanak Technical Institutions
 
PDF
EVS+PRESENTATIONS EVS+PRESENTATIONS like
saiyedaqib429
 
PPT
Understanding the Key Components and Parts of a Drone System.ppt
Siva Reddy
 
PDF
Chad Ayach - A Versatile Aerospace Professional
Chad Ayach
 
PPTX
business incubation centre aaaaaaaaaaaaaa
hodeeesite4
 
PPTX
Victory Precisions_Supplier Profile.pptx
victoryprecisions199
 
PDF
2010_Book_EnvironmentalBioengineering (1).pdf
EmilianoRodriguezTll
 
PPTX
sunil mishra pptmmmmmmmmmmmmmmmmmmmmmmmmm
singhamit111
 
PPTX
Tunnel Ventilation System in Kanpur Metro
220105053
 
PPTX
Chapter_Seven_Construction_Reliability_Elective_III_Msc CM
SubashKumarBhattarai
 
PPTX
database slide on modern techniques for optimizing database queries.pptx
aky52024
 
PPTX
IoT_Smart_Agriculture_Presentations.pptx
poojakumari696707
 
PPTX
Online Cab Booking and Management System.pptx
diptipaneri80
 
PPTX
Civil Engineering Practices_BY Sh.JP Mishra 23.09.pptx
bineetmishra1990
 
PDF
FLEX-LNG-Company-Presentation-Nov-2017.pdf
jbloggzs
 
PDF
Introduction to Ship Engine Room Systems.pdf
Mahmoud Moghtaderi
 
PDF
Packaging Tips for Stainless Steel Tubes and Pipes
heavymetalsandtubes
 
PDF
LEAP-1B presedntation xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
hatem173148
 
PDF
AI-Driven IoT-Enabled UAV Inspection Framework for Predictive Maintenance and...
ijcncjournal019
 
settlement FOR FOUNDATION ENGINEERS.pdf
Endalkazene
 
22PCOAM21 Session 2 Understanding Data Source.pptx
Guru Nanak Technical Institutions
 
EVS+PRESENTATIONS EVS+PRESENTATIONS like
saiyedaqib429
 
Understanding the Key Components and Parts of a Drone System.ppt
Siva Reddy
 
Chad Ayach - A Versatile Aerospace Professional
Chad Ayach
 
business incubation centre aaaaaaaaaaaaaa
hodeeesite4
 
Victory Precisions_Supplier Profile.pptx
victoryprecisions199
 
2010_Book_EnvironmentalBioengineering (1).pdf
EmilianoRodriguezTll
 
sunil mishra pptmmmmmmmmmmmmmmmmmmmmmmmmm
singhamit111
 
Tunnel Ventilation System in Kanpur Metro
220105053
 
Chapter_Seven_Construction_Reliability_Elective_III_Msc CM
SubashKumarBhattarai
 
database slide on modern techniques for optimizing database queries.pptx
aky52024
 
IoT_Smart_Agriculture_Presentations.pptx
poojakumari696707
 
Online Cab Booking and Management System.pptx
diptipaneri80
 
Civil Engineering Practices_BY Sh.JP Mishra 23.09.pptx
bineetmishra1990
 
FLEX-LNG-Company-Presentation-Nov-2017.pdf
jbloggzs
 
Introduction to Ship Engine Room Systems.pdf
Mahmoud Moghtaderi
 
Packaging Tips for Stainless Steel Tubes and Pipes
heavymetalsandtubes
 
LEAP-1B presedntation xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
hatem173148
 
AI-Driven IoT-Enabled UAV Inspection Framework for Predictive Maintenance and...
ijcncjournal019
 

Redis tutoring

  • 3. Who am I Blackie Tsai Senior IT consultant of Xuenn Full stack developer Major on development of real-time transaction system with low latency and high concurrent Learning CI&CD and run with Agile&LEAN Blog http://www.dotblogs.com.tw/blackie1019
  • 5. Redis Redis - A.K.A Remote Directory Server. It is an open source (BSD licensed), one of Key-Value database of NoSQL, in-memory data structure store, used as database, cache and message broker. It also can run atomic operations. Most Popular NoSQL(http://techstacks.io/) Recommend using Linux for deploying. Features Pure Simple Single Tread In-memory but persistent on disk database Remote dictionary server 3.0.4 is the latest stable version. 開源資料庫Redis實戰經驗大公開
  • 7. https://clusterhq.com/assets/pdfs/state-of-container-usage-june-2015.pdf Over 70% would like to run a database or other stateful service in their container environments, with MySQL and Redis the two leading choices Important features for data management in container solutions were: Integration of data management capabilities into existing container work flow and tools seamless movement of data between dev, test and production environments.
  • 8. Who using Redis Facebook’s Instagram: Making the Switch to Cassandra from Redis, a 75% ‘Insta’ Savings http://techstacks.io/tech/redis、http://redis.io/topics/whos-using-redis
  • 10. Redis - Data Persistence Master Redis Slaver Redis Persistence to Disk Server A Server B Replication IMPLEMENTING PERSISTENCE IN REDIS • Master instance with no persistence • Slave instance with AOF enabled
  • 11. Redis - PubSub SignalR Scaleout with Redis
  • 12. Redis - Insight Of Pit Server-side session with Redis Redis has many eviction policies, but most of them are based on 'sampling‘. Alternative Solution Use Database as an another back-end Use Redis 3.0 Maximize CPUs usage Redis is single thread. One instance usually only use one CPU Redis, another step on the road
  • 14. Redis – LUA Script Redis embedded scripting language Good Learning : Lua: 给 Redis 用户的入门指导 5 Methods For Tracing and Debugging Redis Lua Scripts http://redis.io/commands/eval
  • 16. Stack Exchange The world’s largest programming community is growing Stack Exchange is a network of 130+ Q&A communities including Stack Overflow Global traffic ranking 54th largest website
  • 17. Architecture of Stack Exchange http://stackexchange.com/performance
  • 18. Stack Exchange - Info Stack Overflow still uses Microsoft products. Stack Overflow still uses a scale-up strategy with HA. SQL Servers loaded with 384 GB of RAM and 2TB of SSD. Stats 4 million users, 8 million questions, 40 million answers, 560 million pageviews a month. Peak is more like 2600-3000 requests/sec on most weekdays. 25 servers, Stack Overflow has a 40:60 read-write ratio. 2 TB of SQL data all stored on SSDs, Each web server has 2x 320GB SSDs in a RAID 1. DB servers average 10% CPU utilization, 11 web servers, using IIS. 2 load balancers, 1 active, using HAProxy 4 active database nodes, using MS SQL 2 machines for distributed cache and messaging using Redis 2 read-only SQL Servers for used mainly for the Stack Exchange API 3 machines doing search with ElasticSearch
  • 19. Stack Exchange - Caching Caching Cache all the things. 5 levels of caches. 1st: Caching in the browser, CDN, and proxies. 2nd: Using HttpRuntime.Cache. An in- memory, per server cache. 3rd: Redis. 4th: SQL Server Cache. 5th: SSD.
  • 20. Stack Exchange - Lessons Learned Why use Redis if you use MS products? gabeech: It's not about OS evangelism. We run things on the platform they run best on. Period. C# runs best on a windows machine, we use IIS. Redis runs best on a *nix machine we use *nix. Overkill as a strategy SSDs Rock Know your read/write workload Keeping things very efficient means new machines are not needed often Don’t be afraid to specialize Do only what needs to be done Reinvention is OK Go down to the bare metal No bureaucracy. Garbage collection driven programming The cost of inefficient code can be higher than you think
  • 21. StackExchange.Redis Basic Usage - getting started and basic usage Configuration - options available when connecting to redis Pipelines and Multiplexers - what is a multiplexer? Keys, Values and Channels - discusses the data-types used on the API Transactions - how atomic transactions work in redis Events - the events available for logging / information purposes Pub/Sub Message Order - advice on sequential and concurrent processing Scripting - running Lua scripts with convenient named parameter replacement https://github.com/StackExchange/StackExchange.Redis
  • 23. Configuration Automatic and Manual Configuration String Parse Constructor New Constructor Configuration Options Renaming Commands Twemproxy StackExchange.Redis Configuration
  • 25. RedisDemo Features Connection Mapping with Configuration Configuration with Redis Instance Group and Name concept supported Singleton pattern avoid resource waste Dependency StackExchange.Redis FX.Configuration Newtonsoft.Json Log4Net(Optional) Demo Version https://github.com/blackie1019/RedisDemo
  • 26. RedisDemo - Configuration ConnectionSetting follow StackExchange.Redis ConfigurationOptions.Parse()
  • 28. Example Lab Example – Basic Strings Lists Sets Hashes Sorted Sets Example – Advance Sort Expire HashSet, HashGetAll and HashDelete Pub/Sub Pipelines Batch Example – Scripting https://github.com/blackie1019/RedisDemo
  • 29. TOOLS
  • 30. Redis Data Management Cross-platform redis desktop manager - desktop management GUI for mac OS X, Windows, Debian and Ubuntu. http://redisdesktop.com
  • 31. Opserver Monitoring Tool of Stack Exchange Servers SQL clusters/instances Redis Elastic search Exception logs Haproxy
  • 32. Redis Server with Docker Enable Virtualization Technology on Bios and install Docker Toolbox Create a Docker container for Redis Run the service Create your web application container If any problem you can remove and setup again docker-machine rm default docker-machine --native-ssh create -d virtualbox default Dockerizing a Redis service
  • 33. Reference Scaling Stack Overflow (QCon NYC 2015) Redis, another step on the road Types of NoSQL databases StackOverflow Update: 560M Pageviews A Month, 25 Servers, And It's All About Performance Redis 设计与实现 《Redis 设计与实现》图片集

Editor's Notes

  • #6: The Kiss Principle (儉樸原則) 說 ‘Less is more’ (少即是多) 的哲學。 KISS is an acronym for the design principle “Keep it simple, Stupid!“ “keep it short and simple” “keep it simple and straightforward“. 簡純 ANSI C 撰寫。 幾乎不依賴第三方函式庫。 memcached 使用 libevent ,程式碼龐大。 Redis 參考 libevent 實現了自己的 epoll event loop 。 KISS 原則 每個數據結構只負責自己應當做的。  簡單 No map-reduce. No indexes. No vector clocks. 單執行緒 No thread context switch. No thread race condition. No other complicated condition  記憶體資料庫,但可永久儲存於硬碟中 記憶體操作資料。 資料可永久儲存於硬碟。 不只是快取伺服器 Queue
  • #8: DevOps.com & ClusterHQ.com所統計 This report is based on the current and planned container usage patterns of 285 respondents. The survey was conducted over the latter half of May 2015.
  • #11: Consider a setup as shown in the preceding image; that is: Master instance with no persistence Slave instance with AOF enabled In this case, the master does not need to perform any background disk operations and is fully dedicated to serve client requests, except for a trivial slave connection. The slave server configured with AOF performs the disk operations. As mentioned before, this file can be used to restore the master in case of a disaster. Persistence in Redis is a matter of configuration, balancing the trade-off between performance, disk I/O, and data durability. If you are looking for more information on persistence in Redis, you will find the article by Salvatore Sanfilippo at http://oldblog.antirez.com/post/redis-persistence-demystified.html interesting.
  • #13: Redis 有很多種移除舊數據的策略,但大多基於「抽樣」。 ✔ 這意謂移除舊數據不是全局最優而是局部最優。 ✔ 當達到 'maxmemory' 上限時,可能造成移除的數據「不 ✔ 夠舊」。 ✔ 使得使用者提前被登出。最糟的是,你可能都不會知道, ✔ 直到使用者開始抱怨 替代方案。 ✔ 使用資料庫為另一儲存後台。 ✔1. 寫入 Session 時,同時寫進 Redis 及資料庫。 ✔2. 讀出 Session 時, Redis 優先,資料庫其次。 ✔ 使用 Redis 3.0 。 ✔ 選擇較大的 'sampling' ( 抽樣數 ) 
  • #14: http://redis.io/commands#string http://redis.io/commands#set http://redis.io/commands#sorted_set http://redis.io/commands#hash http://redis.io/commands#list
  • #17: Teams: SRE (System Reliability Engineering): - 5 people Core Dev (Q&A site) : ~6-7 people Core Dev Mobile: 6 people Careers team that does development solely for the SO Careers product: 7 people
  • #20: 1st: Caching in the browser, CDN, and proxies. 2nd: Using HttpRuntime.Cache. An in-memory, per server cache. 3rd: Redis. 4th: SQL Server Cache. 5th: SSD. For example, every help page is cached. Code to access a page is very terse: Static methods and static classes re used. Really bad from an OOP perspective, but really fast and really friendly towards terse code. All code is directly addressed. Caching is handled by a library layer of Redis and Dapper, a micro ORM. To get around garbage collection problems, only one copy of a class used in templates are created and kept in a cache. Everything is measured, including GC operation, from statistics it is known that layers of indirection increase GC pressure to the point of noticeable slowness. CDN hits vary, since the query string hash is based on file content, it’s only re-fetched on a build. It's typically 30-50 million hits a day for 300 to 600 GB of bandwidth. A CDN is not used for CPU or I/O load, but to help users find answers faster.
  • #21: Why use Redis if you use MS products? gabeech: It's not about OS evangelism. We run things on the platform they run best on. Period. C# runs best on a windows machine, we use IIS. Redis runs best on a *nix machine we use *nix. Overkill as a strategy. Nick Craver on why their network is over provisioned: Is 20 Gb massive overkill? You bet your ass it is, the active SQL servers average around 100-200 Mb out of that 20 Gb pipe. However, things like backups, rebuilds, etc. can completely saturate it due to how much memory and SSD storage is present, so it does serve a purpose. SSDs Rock. The database nodes all use SSD and the average write time is 0 milliseconds. Know your read/write workload. Keeping things very efficient means new machines are not needed often. Only when a new project comes along that needs different hardware for some reason is new hardware added. Typically memory is added, but other than that efficient code and low utilization means it doesn't need replacing. So typically talking about adding a) SSDs for more space, or b) new hardware for new projects. Don’t be afraid to specialize. SO uses complicated queries based on tags, which is why a specialized Tag Engine was developed. Do only what needs to be done. Tests weren’t necessary because an active community did the acceptance testing for them. Add projects only when required. Add a line of code only when necessary. You Aint Gone Need It really works. Reinvention is OK. Typical advice is don’t reinvent the wheel, you’ll just make it worse, by making it square, for example. At SO they don't worry about making a "Square Wheel". If developers can write something more lightweight than an already developed alternative, then go for it. Go down to the bare metal. Go into the IL (assembly language of .Net). Some coding is in IL, not C#. Look at SQL query plans. Take memory dumps of the web servers to see what is actually going on. Discovered, for example, a split call generated 2GB of garbage. No bureaucracy. There’s always some tools your team needs. For example, an editor, the most recent version of Visual Studio, etc. Just make it happen without a lot of process getting in the way. Garbage collection driven programming. SO goes to great lengths to reduce garbage collection costs, skipping practices like TDD, avoiding layers of abstraction, and using static methods. While extreme, the result is highly performing code. When you're doing hundreds of millions of objects in a short window, you can actually measure pauses in the app domain while GC runs. These have a pretty decent impact on request performance. The cost of inefficient code can be higher than you think. Efficient code stretches hardware further, reduces power usage, makes code easier for programmers to understand.
  • #24: Renaming Commands A slightly unusual feature of redis is that you can disable and/or rename individual commands. As per the previous example, this is done via the CommandMap Twemproxy  is a tool that allows multiple redis instances to be used as though it were a single server, with inbuilt sharding and fault tolerance (much like redis cluster, but implemented separately).
  • #32: opserver做了更清晰的展示。 Ops(/sec)  每秒处理量 memory(used)即used_memory_rss(used_memory) used_memory_rss : 从操作系统的角度,返回 Redis 已分配的内存总量(俗称常驻集大小)。这个值和 top 、 ps等命令的输出一致。 used_memory_peak : Redis 的内存消耗峰值(以字节为单位) used_memory : 由 Redis 分配器分配的内存总量,以字节(byte)为单位   Summary是总体概览部分。 Memory是内存使用情况,重要。 persistence 是RDB和AOF的状态。 keyspace key存储的情况,analyze进去可以查看详细分布。 stats  客户端命令的key命中率和处理量 clients 查看有哪个ip(或机器名)过来的连接数多,很方便的定位到那台应用端机器长时间没有释放连接,重要。 slow command log 服务端接受的命令日志。